summaryrefslogtreecommitdiffstats
path: root/Include/pyport.h
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-63760: Don't declare gethostname() on Solaris (#108817) (#108824)Victor Stinner2023-09-021-5/+0
| | | | | | | | | | | | | | | | gh-63760: Don't declare gethostname() on Solaris (#108817) Since 2005, Solaris defines gethostname(). socketmodule.c no longer has to define gethostname() for Solaris. Oracle Solaris and OpenSolaris have patches to remove the gethostname() definition in Python: * https://github.com/oracle/solaris-userland/blob/master/components/python/python37/patches/15-gethostname.patch * https://github.com/OpenIndiana/oi-userland/blob/oi/hipster/components/python/python37/patches/15-gethostname.patch * https://github.com/omniosorg/omnios-build/blob/master/build/python27/patches/24-gethostname.patch Co-authored-by: Jakub Kulík <Kulikjak@gmail.com> (cherry picked from commit 0e6d582b3b73a88e71cae04327b31a1ee203722c)
* gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511)Petr Viktorin2023-05-041-0/+11
| | | | Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-103323: Get the "Current" Thread State from a Thread-Local Variable ↵Eric Snow2023-04-241-0/+21
| | | | | | | | | | | (gh-103324) We replace _PyRuntime.tstate_current with a thread-local variable. As part of this change, we add a _Py_thread_local macro in pyport.h (only for the core runtime) to smooth out the compiler differences. The main motivation here is in support of a per-interpreter GIL, but this change also provides some performance improvement opportunities. Note that we do not provide a fallback to the thread-local, either falling back to the old tstate_current or to thread-specific storage (PyThread_tss_*()). If that proves problematic then we can circle back. I consider it unlikely, but will run the buildbots to double-check. Also note that this does not change any of the code related to the GILState API, where it uses a thread state stored in thread-specific storage. I suspect we can combine that with _Py_tss_tstate (from here). However, that can be addressed separately and is not urgent (nor critical). (While this change was mostly done independently, I did take some inspiration from earlier (~2020) work by @markshannon (main...markshannon:threadstate_in_tls) and @vstinner (#23976).)
* gh-84436: Implement Immortal Objects (gh-19474)Eddie Elizondo2023-04-221-1/+0
| | | | | | | | | This is the implementation of PEP683 Motivation: The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime. Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
* gh-101101: Unstable C API tier (PEP 689) (GH-101102)Petr Viktorin2023-02-281-0/+9
|
* gh-101196: Make isdir/isfile/exists faster on Windows (GH-101324)Michael Droettboom2023-02-081-0/+4
| | | Co-authored-by: Eryk Sun <eryksun@gmail.com>
* gh-98705: Fix AIX build by undefining `__bool__` in C (#98768)Ayappan Perumal2023-02-021-0/+6
|
* gh-98724: Fix Py_CLEAR() macro side effects (#99100) (#100070)Victor Stinner2022-12-071-0/+9
| | | | | | | | | | | | | | The Py_CLEAR(), Py_SETREF() and Py_XSETREF() macros now only evaluate their arguments once. If an argument has side effects, these side effects are no longer duplicated. Use temporary variables to avoid duplicating side effects of macro arguments. If available, use _Py_TYPEOF() to avoid type punning. Otherwise, use memcpy() for the assignment to prevent a miscompilation with strict aliasing caused by type punning. Add _Py_TYPEOF() macro: __typeof__() on GCC and clang. Add test_py_clear() and test_py_setref() unit tests to _testcapi.
* gh-94731: Revert to C-style casts for _Py_CAST (GH-94782)Petr Viktorin2022-07-141-51/+3
| | | Co-authored-by: da-woods <dw-git@d-woods.co.uk>
* gh-91321: Fix compatibility with C++ older than C++11 (#93784)Victor Stinner2022-06-141-2/+5
| | | | | Fix the compatibility of the Python C API with C++ older than C++11. _Py_NULL is only defined as nullptr on C++11 and newer.
* gh-93442: Make C++ version of _Py_CAST work with 0/NULL. (#93500)Neil Schemenauer2022-06-051-0/+14
| | | | | | | | | | | | Add C++ overloads for _Py_CAST_impl() to handle 0/NULL. This will allow C++ extensions that pass 0 or NULL to macros using _Py_CAST() to continue to compile. Without this, you get an error like: invalid ‘static_cast’ from type ‘int’ to type ‘_object*’ The modern way to use a NULL value in C++ is to use nullptr. However, we want to not break extensions that do things the old way. Co-authored-by: serge-sans-paille
* gh-92898: Enhance _testcppext test on cast to PyObject* (#93111)Victor Stinner2022-05-261-25/+23
| | | | * Add StrongRef class. * Rename and reformat functions of the _Py_CAST() implementation.
* gh-93202: Always use %zd printf formatter (#93201)Victor Stinner2022-05-251-25/+3
| | | | | | | | | | | | | | | | Python now always use the ``%zu`` and ``%zd`` printf formats to format a size_t or Py_ssize_t number. Building Python 3.12 requires a C11 compiler, so these printf formats are now always supported. * PyObject_Print() and _PyObject_Dump() now use the printf %zd format to display an object reference count. * Update PY_FORMAT_SIZE_T comment. * Remove outdated notes about the %zd format in PyBytes_FromFormat() and PyUnicode_FromFormat() documentations. * configure no longer checks for the %zd format and no longer defines PY_FORMAT_SIZE_T macro in pyconfig.h. * pymacconfig.h no longer undefines PY_FORMAT_SIZE_T: macOS 10.4 is no longer supported. Python 3.12 now requires macOS 10.6 (Snow Leopard) or newer.
* GH-92898: Make _Py_Cast C++ version compatible with cast operator (gh-92951)serge-sans-paille2022-05-211-2/+26
|
* gh-91321: Add _Py_NULL macro (#92253)Victor Stinner2022-05-031-0/+8
| | | | | | | | Fix C++ compiler warnings: "zero as null pointer constant" (clang -Wzero-as-null-pointer-constant). * Add the _Py_NULL macro used by static inline functions to use nullptr in C++. * Replace NULL with nullptr in _testcppext.cpp.
* gh-92135: Rename _Py_reinterpret_cast() to _Py_CAST() (#92230)Victor Stinner2022-05-031-10/+10
| | | Rename also _Py_static_cast() to _Py_STATIC_CAST().
* gh-92135: Fix _Py_reinterpret_cast() for const (#92138)Victor Stinner2022-05-021-5/+15
| | | | | | | | | | Fix C++ compiler warnings on cast macros, like _PyObject_CAST(), when casting a constant expression to a non constant type: use const_cast<> in C++. * In C++, Py_SAFE_DOWNCAST() now uses static_cast<> rather than reinterpret_cast<>. * Add tests to the _testcppext C++ extension. * test_cppext no longer captures stdout in verbose mode.
* gh-90822: Make `PY_SSIZE_T_MAX` and `PY_SSIZE_T_MIN` constant expression ↵Ganesh Kathiresan2022-05-021-5/+6
| | | | (GH-92071)
* gh-91320: Add _Py_reinterpret_cast() macro (#91959)Victor Stinner2022-04-271-3/+14
| | | | | | | | | | | | | | Fix C++ compiler warnings about "old-style cast" (g++ -Wold-style-cast) in the Python C API. Use C++ reinterpret_cast<> and static_cast<> casts when the Python C API is used in C++. Example of fixed warning: Include/object.h:107:43: error: use of old-style cast to ‘PyObject*’ {aka ‘struct _object*’} [-Werror=old-style-cast] #define _PyObject_CAST(op) ((PyObject*)(op)) Add _Py_reinterpret_cast() and _Py_static_cast() macros.
* bpo-43166: Disable ceval.c optimizations for Windows debug builds (GH-32023)neonene2022-03-231-11/+0
| | | Also increases the stack allocation when run with `python_d.exe` to account for the extra stack checks that are added.
* bpo-45412: Add _PY_SHORT_FLOAT_REPR macro (GH-31171)Victor Stinner2022-02-231-55/+0
| | | | | | | | | | Remove the HAVE_PY_SET_53BIT_PRECISION macro (moved to the internal C API). * Move HAVE_PY_SET_53BIT_PRECISION macro to pycore_pymath.h. * Replace PY_NO_SHORT_FLOAT_REPR macro with _PY_SHORT_FLOAT_REPR macro which is always defined. gcc -Wundef emits a warning when using _PY_SHORT_FLOAT_REPR but the macro is not defined, if pycore_pymath.h include was forgotten.
* bpo-45569: Change PYLONG_BITS_IN_DIGIT default to 30 (GH-30497)Mark Dickinson2022-01-141-12/+4
|
* bpo-40280: Optimize ints and and startup on wasm (GH-29887)Christian Heimes2021-12-021-4/+8
|
* bpo-45723: Prepare support for autoconf 2.71 (GH-29441)Christian Heimes2021-11-081-8/+1
|
* bpo-45434: Only exclude <stdlib.h> in Python 3.11 limited C API (GH-29027)Victor Stinner2021-10-191-3/+4
| | | | | | | The Python 3.11 limited C API no longer includes stdlib.h, stdio.h, string.h and errno.h. * Exclude Py_MEMCPY() from Python 3.11 limited C API. * xxlimited C extension is now built with Python 3.11 limited C API.
* bpo-45434: pyport.h no longer includes <stdlib.h> (GH-28914)Victor Stinner2021-10-131-2/+0
| | | | | Include <stdlib.h> explicitly in C files. Python.h includes <wchar.h>.
* bpo-45434: Move _Py_BEGIN_SUPPRESS_IPH to pycore_fileutils.h (GH-28922)Victor Stinner2021-10-131-20/+0
|
* bpo-45412: Move _Py_SET_53BIT_PRECISION_START to pycore_pymath.h (GH-28882)Victor Stinner2021-10-111-73/+12
| | | | | | | | | | | | | | | Move the following macros , to pycore_pymath.h (internal C API): * _Py_SET_53BIT_PRECISION_HEADER * _Py_SET_53BIT_PRECISION_START * _Py_SET_53BIT_PRECISION_END PEP 7: add braces to if and "do { ... } while (0)" in these macros. Move also _Py_get_387controlword() and _Py_set_387controlword() definitions to pycore_pymath.h. These functions are no longer exported. pystrtod.c now includes pycore_pymath.h.
* bpo-45434: Cleanup Python.h header file (GH-28883)Victor Stinner2021-10-111-0/+26
| | | | | | * Move limits.h include and UCHAR_MAX checks to pyport.h. * Move sanitizers macros to pyport.h. * Remove comment about <assert.h>: C extensions are built with NDEBUG automatically by Python.
* bpo-45412: Remove Py_SET_ERRNO_ON_MATH_ERROR() macro (GH-28820)Victor Stinner2021-10-111-63/+0
| | | | | | | | | | | | | | | | | | | | | | Remove the following math macros using the errno variable: * Py_ADJUST_ERANGE1() * Py_ADJUST_ERANGE2() * Py_OVERFLOWED() * Py_SET_ERANGE_IF_OVERFLOW() * Py_SET_ERRNO_ON_MATH_ERROR() Create pycore_pymath.h internal header file. Rename Py_ADJUST_ERANGE1() and Py_ADJUST_ERANGE2() to _Py_ADJUST_ERANGE1() and _Py_ADJUST_ERANGE2(), and convert these macros to static inline functions. Move the following macros to pycore_pymath.h: * _Py_IntegralTypeSigned() * _Py_IntegralTypeMax() * _Py_IntegralTypeMin() * _Py_InIntegralTypeRange()
* bpo-45116: Py_DEBUG ignores Py_ALWAYS_INLINE (GH-28419)Victor Stinner2021-09-171-1/+10
| | | | If the Py_DEBUG macro is defined, the Py_ALWAYS_INLINE macro does nothing.
* bpo-45116: Add the Py_ALWAYS_INLINE macro (GH-28390)Victor Stinner2021-09-171-0/+22
| | | | | Add the Py_ALWAYS_INLINE macro to ask the compiler to always inline a static inline function. The compiler can ignore it and decides to not inline the function.
* bpo-45094: Add Py_NO_INLINE macro (GH-28140)Victor Stinner2021-09-031-12/+13
| | | | | * Rename _Py_NO_INLINE macro to Py_NO_INLINE: make it public and document it. * Sort macros in the C API documentation.
* Do not use Py_ssize_clean_t (GH-25940)Inada Naoki2021-05-081-5/+1
|
* bpo-43795: PEP-652: Simplify headers for easier static analysis (GH-25483)Petr Viktorin2021-04-231-0/+2
| | | | | | | | | | | | | | | | | | | | As part of the PEP-652 implementation, I'll tighten the CI check for functions/data defined with `Py_LIMITED_API`. Discussion in https://discuss.python.org/t/pep-652-maintaining-the-stable-abi/6986 suggests that parsing C headers is OK (though personally I'd rather generate it...), but writing a full C parser is a monumental task and adding an existing one as a dependency brings too many vendoring/bootstraping issues. So, for the check I'll use a "simple" regex on preprocessor output, and adapt the few trivial places where the regex won't work. - Keep declarations in the limited API to one item per line - Make it possible to override `_Py_NO_RETURN`, so the annotation can be removed from preprocessor output. https://bugs.python.org/issue43795
* bpo-43271: Re-enable ceval.c optimizations for Windows debug builds (GH-24739)db3l2021-03-041-1/+2
| | | | | | Partially reverts commit b74396c3167cc780f01309148db02709bc37b432 The optimizations are necessary to prevent the interpreter from crashing in a number of tests involving recursion.
* bpo-11717: fix ssize_t redefinition error when targeting 32bit Windows app ↵Jozef Grajciar2021-03-011-1/+3
| | | | (GH-24479)
* bpo-43166: Disable ceval.c optimisations for Windows debug builds (GH-24485)Steve Dower2021-02-091-3/+3
| | | | This ensures that ceval.c can be debugged. Also remove some irrelevant options from the pragma.
* bpo-41617: Add _Py__has_builtin() macro (GH-23260)Victor Stinner2020-11-131-0/+12
| | | | | | | | | | | Fix building pycore_bitutils.h internal header on old clang version without __builtin_bswap16() (ex: Xcode 4.6.3 on Mac OS X 10.7). Add a new private _Py__has_builtin() macro to check for availability of a preprocessor builtin function. Co-Authored-By: Joshua Root <jmr@macports.org> Co-authored-by: Joshua Root <jmr@macports.org>
* bpo-42236: Use UTF-8 encoding if nl_langinfo(CODESET) fails (GH-23086)Victor Stinner2020-11-011-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the nl_langinfo(CODESET) function returns an empty string, Python now uses UTF-8 as the filesystem encoding. In May 2010 (commit b744ba1d14c5487576c95d0311e357b707600b47), I modified Python to log a warning and use UTF-8 as the filesystem encoding (instead of None) if nl_langinfo(CODESET) returns an empty string. In August 2020 (commit 94908bbc1503df830d1d615e7b57744ae1b41079), I modified Python startup to fail with a fatal error and a specific error message if nl_langinfo(CODESET) returns an empty string. The intent was to prevent guessing the encoding and also investigate user configuration where this case happens. In 10 years (2010 to 2020), I saw zero user report about the error message related to nl_langinfo(CODESET) returning an empty string. Today, UTF-8 became the defacto standard and it's safe to make the assumption that the user expects UTF-8. For example, nl_langinfo(CODESET) can return an empty string on macOS if the LC_CTYPE locale is not supported, and UTF-8 is the default encoding on macOS. While this change is likely to not affect anyone in practice, it should make UTF-8 lover happy ;-) Rewrite also the documentation explaining how Python selects the filesystem encoding and error handler.
* bpo-19569: Add a macro to suppress deprecation warnings (GH-9004)Zackery Spytz2020-06-161-0/+20
| | | Co-authored-by: Arfrever Frehtes Taifersar Arahesis <arfrever.fta@gmail.com>
* bpo-40943: Replace PY_FORMAT_SIZE_T with "z" (GH-20781)Victor Stinner2020-06-101-1/+3
| | | | | | | The PEP 353, written in 2005, introduced PY_FORMAT_SIZE_T. Python no longer supports macOS 10.4 and Visual Studio 2010, but requires more recent macOS and Visual Studio versions. In 2020 with Python 3.10, it is now safe to use directly "%zu" to format size_t and "%zi" to format Py_ssize_t.
* bpo-40244: Remove XLC's support from the noreturn flag (GH-20588)Batuhan Taskaya2020-06-021-2/+2
| | | Automerge-Triggered-By: @pablogsal
* bpo-40302: Add pycore_byteswap.h header file (GH-19552)Victor Stinner2020-04-171-4/+4
| | | | | | | | | | | | | | Add a new internal pycore_byteswap.h header file with the following functions: * _Py_bswap16() * _Py_bswap32() * _Py_bswap64() Use these functions in _ctypes, sha256 and sha512 modules, and also use in the UTF-32 encoder. sha256, sha512 and _ctypes modules are now built with the internal C API.
* bpo-40096: Support __attribute__((__noreturn__)) on xlc (GH-19204)Batuhan Taşkaya2020-03-291-0/+1
|
* bpo-11410: Standardize and use symbol visibility attributes across POSIX and ↵Vinay Sajip2019-10-151-11/+13
| | | | Windows. (GH-16347)
* closes bpo-38253: Fix typo of Py_SET_ERANGE_IF_OVERFLOW in pyport.h. (GH-16230)Hai Shi2019-09-241-1/+1
|
* bpo-37781: use "z" for PY_FORMAT_SIZE_T (GH-15156)Inada Naoki2019-08-301-13/+6
| | | MSVC 2015 supports %zd / %zu. "z" is portable enough nowadays.
* bpo-33407: Implement Py_DEPRECATED() on MSVC (GH-8980)Zackery Spytz2019-05-281-3/+7
|
* bpo-36475: Make PyThread_exit_thread with _Py_NO_RETURN (GH-13068)Victor Stinner2019-05-041-0/+14
|