summaryrefslogtreecommitdiffstats
path: root/Include/pyport.h
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* bpo-36775: Add _Py_FORCE_UTF8_FS_ENCODING macro (GH-13056)Victor Stinner2019-05-021-0/+10
| | | | | | | Add _Py_FORCE_UTF8_LOCALE and _Py_FORCE_UTF8_FS_ENCODING macros to avoid factorize "#if defined(__ANDROID__) || defined(__VXWORKS__)" and "#if defined(__APPLE__)". Cleanup also config_init_fs_encoding().
* bpo-36722: Don't define ALT_SOABI for Py_TRACE_REFS build (GH-12973)Victor Stinner2019-04-261-4/+10
| | | | Py_TRACE_REFS ABI is incompatible with release and debug (Py_DEBUG) ABI.
* bpo-36071 Add support for Windows ARM32 in ctypes/libffi (GH-12059)Paul Monson2019-04-181-1/+1
|
* bpo-36635: Change pyport.h for Py_BUILD_CORE_MODULE define (GH-12853)Victor Stinner2019-04-171-2/+23
| | | | | | | | | | | | | | | | | | | | Change PyAPI_FUNC(type), PyAPI_DATA(type) and PyMODINIT_FUNC macros of pyport.h when Py_BUILD_CORE_MODULE is defined. The Py_BUILD_CORE_MODULE define must be now be used to build a C extension as a dynamic library accessing Python internals: export the PyInit_xxx() function in DLL exports on Windows. Changes: * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE now imply Py_BUILD_CORE directy in pyport.h. * ceval.c compilation now fails with an error if Py_BUILD_CORE is not defined, just to ensure that Python is build with the correct defines. * setup.py now compiles _pickle.c with Py_BUILD_CORE_MODULE define. * setup.py compiles _json.c with Py_BUILD_CORE_MODULE define, rather than Py_BUILD_CORE_BUILTIN define * PCbuild/pythoncore.vcxproj: Add Py_BUILD_CORE_BUILTIN define.
* bpo-35758: Fix building on ARM + MSVC (gh-11531)Minmin Gong2019-01-211-1/+1
| | | | | | | | | | * Disable x87 control word for non-x86 targets On msvc, x87 control word is only available on x86 target. Need to disable it for other targets to prevent compiling problems. * Include immintrin.h on x86 and x64 only Immintrin.h is only available on x86 and x64. Need to disable it for other targets to prevent compiling problems.
* bpo-35059: Remove Py_STATIC_INLINE() macro (GH-10216)Victor Stinner2018-10-291-17/+0
| | | | "static inline" should be used directly. Forcing the compiler to inline is not recommended.
* bpo-35059: Add Py_STATIC_INLINE() macro (GH-10093)Victor Stinner2018-10-251-11/+28
| | | | | | | | | * Add Py_STATIC_INLINE() macro to declare a "static inline" function. If the compiler supports it, try to always inline the function even if no optimization level was specified. * Modify pydtrace.h to use Py_STATIC_INLINE() when WITH_DTRACE is not defined. * Add an unit test on Py_DECREF() to make sure that _Py_NegativeRefcount() reports the correct filename.
* bpo-33720: Refactor marshalling/unmarshalling floats. (GH-8071)Serhiy Storchaka2018-07-241-2/+4
|