summaryrefslogtreecommitdiffstats
path: root/Include/Python.h
Commit message (Collapse)AuthorAgeFilesLines
* gh-79315: Remove Include/pylock.h and Include/monitoring.h (#139731)Victor Stinner2025-10-071-2/+2
| | | Keep Include/cpython/pylock.h and Include/cpython/monitoring.h.
* gh-138143: Allow anonymous unions in public headers, using `_Py_ANONYMOUS` ↵Petr Viktorin2025-08-261-0/+13
| | | | | | | | | | | | | | (GH-137283) We already use an anonymous union for PyObject. This makes the workarounds available in all public headers: - MSVC: `__pragma(warning(disable: 4201))` (with push/pop). Warning 4201 is specifically for anonymous unions, so let's disable for all of `<Python.h>` - GCC/clang, pedantic old C standards: define `_Py_ANONYMOUS` as `__extension__` - otherwise, define `_Py_ANONYMOUS` as nothing (Note that this is only for public headers -- CPython internals use C11, which has anonymous structs/unions.) C API WG vote: https://github.com/capi-workgroup/decisions/issues/74
* gh-136823: Update documentation on excluded headers in Python.h (#136824)Sina Zel taat2025-08-051-0/+1
| | | Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
* gh-136759: rename `lock.h` to `pylock.h` (#137041)AN Long2025-07-241-1/+1
| | | Rename `lock.h` to `pylock.h` to avoid conflicts with headers of other projects.
* gh-111506: Add _Py_OPAQUE_PYOBJECT to hide PyObject layout & related API ↵Petr Viktorin2025-07-121-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-136505) Allow Py_LIMITED_API for (Py_GIL_DISABLED && _Py_OPAQUE_PYOBJECT) API that's removed when _Py_OPAQUE_PYOBJECT is defined: - PyObject_HEAD - _PyObject_EXTRA_INIT - PyObject_HEAD_INIT - PyObject_VAR_HEAD - struct _object (i.e. PyObject) (opaque) - struct PyVarObject (opaque) - Py_SIZE - Py_SET_TYPE - Py_SET_SIZE - PyModuleDef_Base (opaque) - PyModuleDef_HEAD_INIT - PyModuleDef (opaque) - _Py_IsImmortal - _Py_IsStaticImmortal Note that the `_Py_IsImmortal` removal (and a few other issues) means _Py_OPAQUE_PYOBJECT only works with limited API 3.14+ now. Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-127545: Add _Py_ALIGNED_DEF(N, T) and use it for PyObject (GH-135209)Petr Viktorin2025-06-111-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replace _Py_ALIGN_AS(V) by _Py_ALIGNED_DEF(N, T) This is now a common façade for the various `_Alignas` alternatives, which behave in interesting ways -- see the source comment. The new macro (and MSVC's `__declspec(align)`) should not be used on a variable/member declaration that includes a struct declaraton. A workaround is to separate the struct definition. Do that for `PyASCIIObject.state`. * Specify minimum PyGC_Head and PyObject alignment As documented in InternalDocs/garbage_collector.md, the garbage collector stores flags in the least significant two bits of the _gc_prev pointer in struct PyGC_Head. Consequently, this pointer is only capable of storing a location that's aligned to a 4-byte boundary. Encode this requirement using _Py_ALIGNED_DEF. This patch fixes a segfault in m68k, which was previously investigated by Adrian Glaubitz here: https://lists.debian.org/debian-68k/2024/11/msg00020.html https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087600 Original patch (using the GCC-only Py_ALIGNED) by Finn Thain. Co-authored-by: Finn Thain <fthain@linux-m68k.org> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
* gh-133779: Revert Windows generation of pyconfig.h and go back to a static ↵Steve Dower2025-05-191-0/+13
| | | | | | header. (GH-133966) Extension builders must specify Py_GIL_DISABLED if they want to link to the free-threaded builds. This was usually the case already, but this change guarantees it in all circumstances.
* gh-127271: Replace use of PyCell_GET/SET (gh-127272)Neil Schemenauer2024-12-031-1/+1
| | | | | | | | | | | | | | | | | | * Replace uses of `PyCell_GET` and `PyCell_SET`. These macros are not safe to use in the free-threaded build. Use `PyCell_GetRef()` and `PyCell_SetTakeRef()` instead. * Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some code restructuring was required, e.g. `frame_get_var()` returns a strong ref now. * Add critical sections to `PyCell_GET` and `PyCell_SET`. * Move critical_section.h earlier in the Python.h file. * Add `PyCell_GET` to the free-threading howto table of APIs that return borrowed refs. * Add additional unit tests for free-threading.
* gh-125604: Move _Py_AuditHookEntry, etc. Out of pycore_runtime.h (gh-125605)Eric Snow2024-10-181-0/+1
| | | | | | | | | | | | This is essentially a cleanup, moving a handful of API declarations to the header files where they fit best, creating new ones when needed. We do the following: * add pycore_debug_offsets.h and move _Py_DebugOffsets, etc. there * inline struct _getargs_runtime_state and struct _gilstate_runtime_state in _PyRuntimeState * move struct _reftracer_runtime_state to the existing pycore_object_state.h * add pycore_audit.h and move to it _Py_AuditHookEntry , _PySys_Audit(), and _PySys_ClearAuditHooks * add audit.h and cpython/audit.h and move the existing audit-related API there *move the perfmap/trampoline API from cpython/sysmodule.h to cpython/ceval.h, and remove the now-empty cpython/sysmodule.h
* gh-124609: Fix _Py_ThreadId for Windows builds using MinGW (#124663)Tony Roberts2024-09-271-0/+4
|
* gh-120642: Move private PyCode APIs to the internal C API (#120643)Victor Stinner2024-06-261-1/+0
| | | | | | | | | | | | | | | * Move _Py_CODEUNIT and related functions to pycore_code.h. * Move _Py_BackoffCounter to pycore_backoff.h. * Move Include/cpython/optimizer.h content to pycore_optimizer.h. * Remove Include/cpython/optimizer.h. * Remove PyUnstable_Replace_Executor(). Rename functions: * PyUnstable_GetExecutor() => _Py_GetExecutor() * PyUnstable_GetOptimizer() => _Py_GetOptimizer() * PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer() * PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter() * PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()
* gh-119344: Make critical section API public (#119353)Sam Gross2024-06-211-0/+1
| | | | | | | | | | This makes the following macros public as part of the non-limited C-API for locking a single object or two objects at once. * `Py_BEGIN_CRITICAL_SECTION(op)` / `Py_END_CRITICAL_SECTION()` * `Py_BEGIN_CRITICAL_SECTION2(a, b)` / `Py_END_CRITICAL_SECTION2()` The supporting functions and structs used by the macros are also exposed for cases where C macros are not available.
* gh-117511: Make PyMutex public in the non-limited API (#117731)Sam Gross2024-06-201-0/+1
|
* gh-120326: Include <intrin.h> on Windows with Free Threading (#120329)Kirill Podoprigora2024-06-111-0/+4
|
* gh-119853: Add Include/refcount.h file (#119854)Victor Stinner2024-05-311-0/+1
|
* gh-111997: C-API for signalling monitoring events (#116413)Irit Katriel2024-05-041-0/+1
|
* gh-111506: Error if the limited API is used in free-threaded build (#117762)Sam Gross2024-04-111-0/+5
| | | | Issue a build time error if both `Py_LIMITED_API` and `Py_GIL_DISABLED` are defined.
* gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit ↵Serhiy Storchaka2024-03-201-1/+1
| | | | platforms (GH-117064)
* gh-110850: Add PyTime_t C API (GH-115215)Petr Viktorin2024-02-121-0/+1
| | | | | | | | | | | | * gh-110850: Add PyTime_t C API Add PyTime_t API: * PyTime_t type. * PyTime_MIN and PyTime_MAX constants. * PyTime_AsSecondsDouble(), PyTime_Monotonic(), PyTime_PerfCounter() and PyTime_GetSystemClock() functions. Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-112026: Add again <unistd.h> include in Python.h (#112046)Victor Stinner2023-11-151-3/+12
| | | | Add again <ctype.h> and <unistd.h> includes in Python.h, but don't include them in the limited C API version 3.13 and newer.
* gh-108765: Python.h no longer includes <stddef.h> on Windows (#111563)Victor Stinner2023-10-311-3/+0
| | | | In practice, only Windows is impacted, because the HAVE_STDDEF_H macro was only defined on Windows.
* gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344)Sam Gross2023-09-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | PyMutex is a one byte lock with fast, inlineable lock and unlock functions for the common uncontended case. The design is based on WebKit's WTF::Lock. PyMutex is built using the _PyParkingLot APIs, which provides a cross-platform futex-like API (based on WebKit's WTF::ParkingLot). This internal API will be used for building other synchronization primitives used to implement PEP 703, such as one-time initialization and events. This also includes tests and a mini benchmark in Tools/lockbench/lockbench.py to compare with the existing PyThread_type_lock. Uncontended acquisition + release: * Linux (x86-64): PyMutex: 11 ns, PyThread_type_lock: 44 ns * macOS (arm64): PyMutex: 13 ns, PyThread_type_lock: 18 ns * Windows (x86-64): PyMutex: 13 ns, PyThread_type_lock: 38 ns PR Overview: The primary purpose of this PR is to implement PyMutex, but there are a number of support pieces (described below). * PyMutex: A 1-byte lock that doesn't require memory allocation to initialize and is generally faster than the existing PyThread_type_lock. The API is internal only for now. * _PyParking_Lot: A futex-like API based on the API of the same name in WebKit. Used to implement PyMutex. * _PyRawMutex: A word sized lock used to implement _PyParking_Lot. * PyEvent: A one time event. This was used a bunch in the "nogil" fork and is useful for testing the PyMutex implementation, so I've included it as part of the PR. * pycore_llist.h: Defines common operations on doubly-linked list. Not strictly necessary (could do the list operations manually), but they come up frequently in the "nogil" fork. ( Similar to https://man.freebsd.org/cgi/man.cgi?queue) --------- Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-108765: Python.h no longer includes <ctype.h> (#108831)Victor Stinner2023-09-031-1/+0
| | | | | | | | | | | | | | | | | | | | | | | Remove <ctype.h> in C files which don't use it; only sre.c and _decimal.c still use it. Remove _PY_PORT_CTYPE_UTF8_ISSUE code from pyport.h: * Code added by commit b5047fd01948ab108edcc1b3c2c901d915814cfd in 2004 for MacOSX and FreeBSD. * Test removed by commit 52ddaefb6bab1a74ecffe8519c02735794ebfbe1 in 2007, since Python str type now uses locale independent functions like Py_ISALPHA() and Py_TOLOWER() and the Unicode database. Modules/_sre/sre.c replaces _PY_PORT_CTYPE_UTF8_ISSUE with new functions: sre_isalnum(), sre_tolower(), sre_toupper(). Remove unused includes: * _localemodule.c: remove <stdio.h>. * getargs.c: remove <float.h>. * dynload_win.c: remove <direct.h>, it no longer calls _getcwd() since commit fb1f68ed7cc1536482d1debd70a53c5442135fe2 (in 2001).
* gh-108765: Python.h no longer includes <unistd.h> (#108783)Victor Stinner2023-09-021-6/+5
|
* gh-108765: Python.h no longer includes <ieeefp.h> (#108781)Victor Stinner2023-09-021-0/+1
| | | | Remove also the HAVE_IEEEFP_H macro: remove ieeefp.h from the AC_CHECK_HEADERS() check of configure.ac.
* gh-108765: Move standard includes to Python.h (#108769)Victor Stinner2023-09-011-16/+24
| | | | | | | | | | | | * Move <ctype.h>, <limits.h> and <stdarg.h> standard includes to Python.h. * Move "pystats.h" include from object.h to Python.h. * Remove redundant "pymem.h" include in objimpl.h and "pyport.h" include in pymem.h; Python.h already includes them earlier. * Remove redundant <wchar.h> include in unicodeobject.h; Python.h already includes it. * Move _SGI_MP_SOURCE define from Python.h to pyport.h. * pycore_condvar.h includes explicitly <unistd.h> for the _POSIX_THREADS macro.
* gh-106320: Remove private _PyTraceMalloc C API functions (#106324)Victor Stinner2023-07-021-1/+1
| | | | | | | * Remove private _PyTraceMalloc C API functions: move them to the internal C API. * Don't export most of these functions anymore, but still export _PyTraceMalloc_GetTraceback() used by tests. * Rename Include/tracemalloc.h to Include/cpython/tracemalloc.h
* gh-106316: Remove pytime.h header file (#106317)Victor Stinner2023-07-011-1/+0
| | | | | | | | | | | | | | | | | Remove the "cpython/pytime.h" header file: it only contained private functions. Move functions to the internal pycore_time.h header file. Move tests from _testcapi to _testinternalcapi. Rename also test methods to have the same name than tested C functions. No longer export these functions: * _PyTime_Add() * _PyTime_As100Nanoseconds() * _PyTime_FromMicrosecondsClamp() * _PyTime_FromTimespec() * _PyTime_FromTimeval() * _PyTime_GetPerfCounterWithInfo() * _PyTime_MulDiv()
* GH-104584: Plugin optimizer API (GH-105100)Mark Shannon2023-06-021-0/+1
|
* bpo-35134: Remove the Include/code.h header file (GH-32385)Victor Stinner2022-04-071-1/+1
| | | | | | Remove the Include/code.h header file. C extensions should only include the main <Python.h> header file. Python.h includes directly Include/cpython/code.h instead.
* bpo-45459: Add pytypedefs.h header file (GH-31527)Victor Stinner2022-02-241-0/+1
| | | | | | | | | | | | | | | | | | Move forward declarations of Python C API types to a new pytypedefs.h header file to solve interdependency issues between header files. pytypedefs.h contains forward declarations of the following types: * PyCodeObject * PyFrameObject * PyGetSetDef * PyInterpreterState * PyLongObject * PyMemberDef * PyMethodDef * PyModuleDef * PyObject * PyThreadState * PyTypeObject
* bpo-45459: Rename buffer.h to pybuffer.h (#31201)Victor Stinner2022-02-221-1/+1
| | | | | | | | | Rename Include/buffer.h header file to Include/pybuffer.h to avoid conflicts with projects having an existing "buffer.h" header file. * Incude pybuffer.h before object.h in Python.h. * Remove #include "buffer.h" from Include/cpython/object.h. * Add a forward declaration of the PyObject type in pybuffer.h to fix an inter-dependency issue.
* bpo-45459: Add Py_buffer to limited API (GH-29991)Christian Heimes2022-02-021-0/+1
| | | | | | | | | | | - [x] ``Py_buffer`` struct - [x] ``PyBuffer_*()`` API functions - [x] ``PyBUF_*`` constants - [x] ``Py_bf_getbuffer`` and ``Py_bf_releasebuffer`` type slots - [x] ``PyMemoryView_FromBuffer()`` API - [x] tests for limited API - [x] ``make regen-limited-abi`` - [x] documentation update - [ ] export ``PyPickleBuffer*()`` API ???
* bpo-39026: Fix Python.h when building with Xcode (GH-29488)Victor Stinner2021-11-231-1/+1
| | | | Fix Python.h to build C extensions with Xcode: remove a relative include from Include/cpython/pystate.h.
* bpo-45434: Only exclude <stdlib.h> in Python 3.11 limited C API (GH-29027)Victor Stinner2021-10-191-4/+6
| | | | | | | 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-45482: Rename namespaceobject.h to pycore_namespace.h (GH-28975)Victor Stinner2021-10-151-1/+0
| | | | | | | | | Rename Include/namespaceobject.h to Include/internal/pycore_namespace.h. The _testmultiphase extension is now built with the Py_BUILD_CORE_MODULE macro defined to access _PyNamespace_Type. object.c: remove unused "pycore_context.h" include.
* bpo-45434: Remove Include/eval.h header file (GH-28973)Victor Stinner2021-10-151-1/+0
| | | | Move Include/eval.h content into Include/ceval.h and Include/cpython/ceval.h, and remove Include/eval.h.
* bpo-35134: Move classobject.h to Include/cpython/ (GH-28968)Victor Stinner2021-10-151-5/+5
| | | | | | | | | Move classobject.h, context.h, genobject.h and longintrepr.h header files from Include/ to Include/cpython/. Remove redundant "#ifndef Py_LIMITED_API" in context.h. Remove explicit #include "longintrepr.h" in C files. It's not needed, Python.h already includes it.
* bpo-35134: Move Include/cellobject.h to Include/cpython/ (GH-28964)Victor Stinner2021-10-151-1/+1
|
* po-35134: Move Include/funcobject.h to Include/cpython/ (GH-28958)Victor Stinner2021-10-141-1/+1
| | | Remove redundant "#ifndef Py_LIMITED_API" in funcobject.h.
* bpo-45434: Limited Python.h no longer includes stdio.h (GH-28960)Victor Stinner2021-10-141-7/+4
| | | | The <Python.h> header file no longer includes <stdio.h> if the Py_LIMITED_API macro is defined.
* bpo-45434: pyport.h no longer includes <stdlib.h> (GH-28914)Victor Stinner2021-10-131-1/+2
| | | | | Include <stdlib.h> explicitly in C files. Python.h includes <wchar.h>.
* bpo-45434: Python.h no longer includes <stdlib.h> (GH-28888)Victor Stinner2021-10-111-1/+0
|
* bpo-45434: Cleanup Python.h header file (GH-28883)Victor Stinner2021-10-111-52/+13
| | | | | | * 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.
* closes bpo-44751: Move crypt.h include from public header to _cryptmodule ↵Geoffrey Thomas2021-07-271-13/+0
| | | | | (GH-27394) Automerge-Triggered-By: GH:benjaminp
* bpo-44363: Get test_capi passing with address sanitizer (GH-26639)Mark Shannon2021-06-101-1/+10
|
* bpo-43774: Remove unused PYMALLOC_DEBUG macro (GH-25711)Victor Stinner2021-04-291-9/+0
| | | Enhance also the documentation of debug hooks on memory allocators.
* bpo-43244: Remove the pyarena.h header (GH-25007)Victor Stinner2021-03-241-1/+0
| | | | | | | | | | | | | | | | | | Remove the pyarena.h header file with functions: * PyArena_New() * PyArena_Free() * PyArena_Malloc() * PyArena_AddPyObject() These functions were undocumented, excluded from the limited C API, and were only used internally by the compiler. Add pycore_pyarena.h header. Rename functions: * PyArena_New() => _PyArena_New() * PyArena_Free() => _PyArena_Free() * PyArena_Malloc() => _PyArena_Malloc() * PyArena_AddPyObject() => _PyArena_AddPyObject()
* bpo-43244: Remove parser_interface.h header file (GH-25001)Victor Stinner2021-03-241-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | Remove parser functions using the "struct _mod" type, because the AST C API was removed: * PyParser_ASTFromFile() * PyParser_ASTFromFileObject() * PyParser_ASTFromFilename() * PyParser_ASTFromString() * PyParser_ASTFromStringObject() These functions were undocumented and excluded from the limited C API. Add pycore_parser.h internal header file. Rename functions: * PyParser_ASTFromFileObject() => _PyParser_ASTFromFile() * PyParser_ASTFromStringObject() => _PyParser_ASTFromString() These functions are no longer exported (replace PyAPI_FUNC() with extern). Remove also _PyPegen_run_parser_from_file() function. Update test_peg_generator to use _PyPegen_run_parser_from_file_pointer() instead.
* bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561)Nicholas Sim2021-02-191-5/+5
| | | | | | Include/{odictobject.h,parser_interface.h,picklebufobject.h,pydebug.h,pyfpe.h} into Include/cpython/. Parser: peg_api: include Python.h instead of parser_interface.h.