summaryrefslogtreecommitdiffstats
path: root/Include/object.h
Commit message (Collapse)AuthorAgeFilesLines
* gh-139165: Make Py_SIZE, Py_IS_TYPE,Py_ SET_SIZE regular functions in stable ↵Petr Viktorin2025-11-251-41/+55
| | | | | | | | | | | | ABI (GH-139166) * Make Py_{SIZE,IS_TYPE,SET_SIZE} regular functions in stable ABI Group them together with Py_TYPE & Py_SET_TYPE to cut down on repetitive preprocessor macros. Format repetitive definitions in object.c more concisely. Py_SET_TYPE is still left out of the Limited API.
* gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556)Petr Viktorin2025-11-051-0/+5
| | | | Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-134786: raise error if `Py_TPFLAGS_MANAGED_WEAKREF` or ↵Sergey Miryanov2025-11-021-1/+1
| | | | `Py_TPFLAGS_MANAGED_DICT` is used without `Py_TPFLAGS_HAVE_GC` set (#135863)
* gh-140487: Fix Py_RETURN_NOTIMPLEMENTED in limited C API 3.11 (GH-140636)Victor Stinner2025-10-271-2/+7
| | | | Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE have already been fixed by commit 9258f3da9175134d03f2c8c7c7eed223802ad945 (issue gh-134989).
* gh-137956: Guard against non-free-threaded extensions in free-threaded ↵Petr Viktorin2025-09-151-0/+3
| | | | builds (GH-137957)
* gh-138143: Allow anonymous unions in public headers, using `_Py_ANONYMOUS` ↵Petr Viktorin2025-08-261-15/+1
| | | | | | | | | | | | | | (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-95245: Document Py_TPFLAGS_PREHEADER (GH-135861)Sergey Miryanov2025-08-251-0/+3
| | | Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* gh-111506: Add _Py_OPAQUE_PYOBJECT to hide PyObject layout & related API ↵Petr Viktorin2025-07-121-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-134989: Fix Py_RETURN_NONE in the limited C API (GH-135165)Victor Stinner2025-06-051-2/+7
| | | | | Fix Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE macros in the limited C API 3.11 and older: Don't treat Py_None, Py_True and Py_False as immortal.
* gh-127266: avoid data races when updating type slots (gh-133177)Neil Schemenauer2025-05-281-5/+7
| | | | | | In the free-threaded build, avoid data races caused by updating type slots or type flags after the type was initially created. For those (typically rare) cases, use the stop-the-world mechanism. Remove the use of atomics when reading or writing type flags.
* Revert gh-127266: avoid data races when updating type slots (gh-131174) ↵Neil Schemenauer2025-04-291-7/+5
| | | | | (gh-133129) This is triggering deadlocks in test_opcache. See GH-133130 for stack trace.
* gh-127266: avoid data races when updating type slots (gh-131174)Neil Schemenauer2025-04-281-5/+7
| | | | | | | | In the free-threaded build, avoid data races caused by updating type slots or type flags after the type was initially created. For those (typically rare) cases, use the stop-the-world mechanism. Remove the use of atomics when reading or writing type flags. The use of atomics is not sufficient to avoid races (since flags are sometimes read without a lock and without atomics) and are no longer required.
* GH-127705: Use `_PyStackRef`s in the default build. (GH-127875)Mark Shannon2025-03-101-4/+6
|
* gh-129666: Add C11/C++11 to docs and -pedantic-errors to GCC/clang ↵Petr Viktorin2025-03-041-1/+1
| | | | | | | | | test_c[pp]ext tests (GH-130692) Disable pedantic check for c++03 (unlimited API) Also add a check for c++03 *limited* API, which passes in pedantic mode after removing a comma in the `PySendResult` declaration, and allowing `long long`.
* GH-125174: Mark objects as statically allocated. (#127797)Mark Shannon2024-12-111-5/+15
| | | | | * Set a bit in the unused part of the refcount on 64 bit machines and the free-threaded build. * Use the top of the refcount range on 32 bit machines
* gh-121654: Add PyType_Freeze() function (#122457)Victor Stinner2024-10-251-0/+4
| | | Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-125444: Fix illegal instruction for older Arm architectures (#125574)Diego Russo2024-10-161-1/+1
| | | | | | | | On Arm v5 it is not possible to get the thread ID via c13 register hence the illegal instruction. The c13 register started to provide thread ID since Arm v6K architecture variant. Other variants of Arm v6 (T2, Z and base) don’t provide the thread ID via c13. For the sake of simplicity we group v5 and v6 together and consider that instructions for Arm v7 only.
* GH-125174: Make immortal objects more robust, following design from PEP 683 ↵Mark Shannon2024-10-101-1/+1
| | | | (GH-125251)
* gh-124609: Fix _Py_ThreadId for Windows builds using MinGW (#124663)Tony Roberts2024-09-271-0/+6
|
* gh-124153: Implement `PyType_GetBaseByToken()` and `Py_tp_token` slot ↵neonene2024-09-181-0/+4
| | | | (GH-124163)
* gh-120198: Stop the world when setting __class__ on free-threaded build ↵Ken Jin2024-07-101-8/+0
| | | | (GH-120672)
* gh-117511: Make PyMutex public in the non-limited API (#117731)Sam Gross2024-06-201-5/+1
|
* GH-119462: Enforce invariants of type versioning (GH-120731)Mark Shannon2024-06-191-1/+1
| | | | * Remove uses of Py_TPFLAGS_VALID_VERSION_TAG
* gh-120600: Make Py_TYPE() opaque in limited C API 3.14 (#120601)Victor Stinner2024-06-181-9/+19
| | | | In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
* gh-83754: Use the Py_TYPE() macro (#120599)Victor Stinner2024-06-171-4/+4
| | | | Don't access directly PyObject.ob_type, but use the Py_TYPE() macro instead.
* gh-117657: Make PyType_HasFeature (exported version) atomic (#120484)Ken Jin2024-06-151-1/+5
| | | Make PyType_HasFeature (exported version) atomic
* gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)Ken Jin2024-06-121-0/+8
| | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
* gh-119853: Add Include/refcount.h file (#119854)Victor Stinner2024-05-311-482/+0
|
* gh-117657: Fix race data race in `_Py_IsOwnedByCurrentThread()` (#118258)mpage2024-04-261-0/+4
|
* gh-117657: Fix data race in `_Py_IsImmortal` (#118261)mpage2024-04-251-1/+2
| | | | The load of `ob_ref_local races with stores. Using a relaxed load is sufficient; stores to the field are relaxed.
* GH-115776: Static object are immortal, so mark them as such. (GH-117673)Mark Shannon2024-04-161-10/+7
|
* GH-115776: Embed the values array into the object, for "normal" Python ↵Mark Shannon2024-04-021-1/+6
| | | | objects. (GH-116115)
* gh-116936: Add PyType_GetModuleByDef() to the limited C API (#116937)Victor Stinner2024-03-251-0/+4
|
* gh-115754: Add Py_GetConstant() function (#116883)Victor Stinner2024-03-211-2/+29
| | | | | | | | | | | | Add Py_GetConstant() and Py_GetConstantBorrowed() functions. In the limited C API version 3.13, getting Py_None, Py_False, Py_True, Py_Ellipsis and Py_NotImplemented singletons is now implemented as function calls at the stable ABI level to hide implementation details. Getting these constants still return borrowed references. Add _testlimitedcapi/object.c and test_capi/test_object.py to test Py_GetConstant() and Py_GetConstantBorrowed() functions.
* gh-116869: Make C API compatible with ISO C90 (#116950)Victor Stinner2024-03-181-2/+1
| | | | Make the C API compatible with -Werror=declaration-after-statement compiler flag again.
* gh-111696, PEP 737: Add PyType_GetModuleName() function (#116824)Victor Stinner2024-03-141-1/+2
| | | Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-111696, PEP 737: Add PyType_GetFullyQualifiedName() function (#116815)Victor Stinner2024-03-141-0/+3
| | | Rewrite tests on type names in Python, they were written in C.
* gh-112529: Remove PyGC_Head from object pre-header in free-threaded build ↵Sam Gross2024-02-011-2/+3
| | | | | | | | | | | | | | | | | (#114564) * gh-112529: Remove PyGC_Head from object pre-header in free-threaded build This avoids allocating space for PyGC_Head in the free-threaded build. The GC implementation for free-threaded CPython does not use the PyGC_Head structure. * The trashcan mechanism uses the `ob_tid` field instead of `_gc_prev` in the free-threaded build. * The GDB libpython.py file now determines the offset of the managed dict field based on whether the running process is a free-threaded build. Those are identified by the `ob_ref_local` field in PyObject. * Fixes `_PySys_GetSizeOf()` which incorrectly incorrectly included the size of `PyGC_Head` in the size of static `PyTypeObject`.
* gh-112087: Make PyList_{Append,Size,GetSlice} to be thread-safe (gh-114651)Donghee Na2024-01-311-0/+4
|
* gh-112529: Implement GC for free-threaded builds (#114262)Sam Gross2024-01-251-1/+3
| | | | | | | * gh-112529: Implement GC for free-threaded builds This implements a mark and sweep GC for the free-threaded builds of CPython. The implementation relies on mimalloc to find GC tracked objects (i.e., "containers").
* gh-112535: Implement fallback implementation of _Py_ThreadId() (gh-113185)Donghee Na2023-12-181-1/+5
| | | | | --------- Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-112535: Update _Py_ThreadId() to support RISC-V (gh-113084)Furkan Onder2023-12-141-0/+7
| | | Update _Py_ThreadId() to support RISC-V
* gh-112535: Update _Py_ThreadId() to support s390/s390x (gh-112751)Donghee Na2023-12-081-0/+4
|
* gh-112535: Add comment for ppc32/64 registers (gh-112746)Donghee Na2023-12-051-0/+2
|
* gh-112535: Update _Py_ThreadId() to support PowerPC (gh-112624)Donghee Na2023-12-051-0/+16
|
* gh-110481: Fix typo in Py_SET_REFCNT() (#112595)Victor Stinner2023-12-011-3/+3
|
* gh-110481: Fix Py_SET_REFCNT() integer overflow (#112174)Victor Stinner2023-12-011-10/+21
| | | | | | | | | | | | | | If Py_NOGIL is defined and Py_SET_REFCNT() is called with a reference count larger than UINT32_MAX, make the object immortal. Set _Py_IMMORTAL_REFCNT constant type to Py_ssize_t to fix the following compiler warning: Include/internal/pycore_global_objects_fini_generated.h:14:24: warning: comparison of integers of different signs: 'Py_ssize_t' (aka 'long') and 'unsigned int' [-Wsign-compare] if (Py_REFCNT(obj) < _Py_IMMORTAL_REFCNT) { ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~
* gh-111863: Rename `Py_NOGIL` to `Py_GIL_DISABLED` (#111864)Hugo van Kemenade2023-11-201-13/+13
| | | Rename Py_NOGIL to Py_GIL_DISABLED
* gh-112026: Restore removed private C API (#112115)Victor Stinner2023-11-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Restore removed private C API functions, macros and structures which have no simple replacement for now: * _PyDict_GetItem_KnownHash() * _PyDict_NewPresized() * _PyHASH_BITS * _PyHASH_IMAG * _PyHASH_INF * _PyHASH_MODULUS * _PyHASH_MULTIPLIER * _PyLong_Copy() * _PyLong_FromDigits() * _PyLong_New() * _PyLong_Sign() * _PyObject_CallMethodId() * _PyObject_CallMethodNoArgs() * _PyObject_CallMethodOneArg() * _PyObject_CallOneArg() * _PyObject_EXTRA_INIT * _PyObject_FastCallDict() * _PyObject_GetAttrId() * _PyObject_Vectorcall() * _PyObject_VectorcallMethod() * _PyStack_AsDict() * _PyThread_CurrentFrames() * _PyUnicodeWriter structure * _PyUnicodeWriter_Dealloc() * _PyUnicodeWriter_Finish() * _PyUnicodeWriter_Init() * _PyUnicodeWriter_Prepare() * _PyUnicodeWriter_PrepareKind() * _PyUnicodeWriter_WriteASCIIString() * _PyUnicodeWriter_WriteChar() * _PyUnicodeWriter_WriteLatin1String() * _PyUnicodeWriter_WriteStr() * _PyUnicodeWriter_WriteSubstring() * _PyUnicode_AsString() * _PyUnicode_FromId() * _PyVectorcall_Function() * _Py_HashDouble() * _Py_HashPointer() * _Py_IDENTIFIER() * _Py_c_abs() * _Py_c_diff() * _Py_c_neg() * _Py_c_pow() * _Py_c_prod() * _Py_c_quot() * _Py_c_sum() * _Py_static_string() * _Py_static_string_init()