summaryrefslogtreecommitdiffstats
path: root/Include/internal/pycore_object.h
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-125723: Fix crash with f_locals when generator frame outlive their ↵Mikhail Efimov2025-06-131-1/+1
| | | | | | | generator (GH-135453) Backport of 8e20e42cc63321dacc500d7670bfc225ca04e78b from GH-126956 Closes GH-125723
* [3.13] gh-132070: Use _PyObject_IsUniquelyReferenced in unicodeobject ↵Donghee Na2025-04-291-0/+17
| | | | | | | | | | | | | | | | | | | (gh-133039) (gh-133126) * gh-132070: Use _PyObject_IsUniquelyReferenced in unicodeobject (gh-133039) --------- (cherry picked from commit 75cbb8d89e7e92ccaba5c615c72459f241dca8b1) Co-authored-by: Donghee Na <donghee.na@python.org> Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> * Add _PyObject_IsUniquelyReferenced --------- Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.13] gh-127599: Fix _Py_RefcntAdd missing calls to ↵Ed Nutting2025-01-181-0/+4
| | | | | | | | | _Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC (GH-127717) (#128713) Previously, `_Py_RefcntAdd` hasn't called `_Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC` which is incorrect. Now it has been fixed. (cherry picked from commit ab05beb8cea62636bd86f6f7cf1a82d7efca7162)
* [3.13] gh-126076: Account for relocated objects in tracemalloc (GH-126077) ↵Pablo Galindo Salgado2024-12-111-5/+9
| | | | | (#127823) (cherry picked from commit 30aeb00d367d0cc9e5a7603371636cddea09f1c0)
* [3.13] gh-127582: Make object resurrection thread-safe for free threading. ↵Sam Gross2024-12-051-0/+44
| | | | | | | | | | | | | | | (GH-127612) (GH-127659) Objects may be temporarily "resurrected" in destructors when calling finalizers or watcher callbacks. We previously undid the resurrection by decrementing the reference count using `Py_SET_REFCNT`. This was not thread-safe because other threads might be accessing the object (modifying its reference count) if it was exposed by the finalizer, watcher callback, or temporarily accessed by a racy dictionary or list access. This adds internal-only thread-safe functions for temporary object resurrection during destructors. (cherry picked from commit f4f530804b9d8f089eba0f157ec2144c03b13651)
* [3.13] gh-125703: Correctly honour tracemalloc hooks on specialized DECREF ↵Miss Islington (bot)2024-12-021-0/+5
| | | | | | | | paths (GH-125704) (#125705) gh-125703: Correctly honour tracemalloc hooks on specialized DECREF paths (GH-125704) (cherry picked from commit f8ba9fb2ce6690d2dd05b356583e8e4790badad7) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* [3.13] GH-124567: Revert the Incremental GC in 3.13 (#124770)T. Wouters2024-09-301-3/+2
| | | | | Revert the incremental GC in 3.13, since it's not clear that without further turning, the benefits outweigh the costs. Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
* [3.13] gh-121528: Fix _PyObject_Init() assertion for stable ABI (GH-121725) ↵Miss Islington (bot)2024-07-171-2/+26
| | | | | | | | | | (#121936) gh-121528: Fix _PyObject_Init() assertion for stable ABI (GH-121725) Add _Py_IsImmortalLoose() function for assertions. (cherry picked from commit b826e459ca6b640f896c2a9551bb2c78d10f0e2b) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.13] gh-121700 Emscripten trampolines not quite right since GH-106219 ↵Miss Islington (bot)2024-07-141-7/+1
| | | | | | | (GH-121701) (GH-121744) (cherry picked from commit 3086b86cfda829e23a71569908edbfbcdc16327f) Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
* [3.13] gh-117657: Fix data races reported by TSAN in some set methods ↵Miss Islington (bot)2024-07-011-0/+14
| | | | | | | | | | | (GH-120914) (#121240) Refactor the fast Unicode hash check into `_PyObject_HashFast` and use relaxed atomic loads in the free-threaded build. After this change, the TSAN doesn't report data races for this method. (cherry picked from commit 294e72496439da984cb8dba9100d3613c8cc8a6d) Co-authored-by: AN Long <aisk@users.noreply.github.com>
* [3.13] gh-117657: Make PyType_HasFeature atomic (GH-120210) (#120443)Miss Islington (bot)2024-06-131-1/+1
| | | | | | | | gh-117657: Make PyType_HasFeature atomic (GH-120210) Make PyType_HasFeature atomic (cherry picked from commit eebae2c460dabdc70dc0d9b6e189368eb1abb716) Co-authored-by: Ken Jin <kenjin@python.org>
* [3.13] gh-117398: Use Per-Interpreter State for the _datetime Static Types ↵Miss Islington (bot)2024-06-031-1/+1
| | | | | | | | | | | (gh-120009) We make use of the same mechanism that we use for the static builtin types. This required a few tweaks. This change is the final piece needed to make _datetime support multiple interpreters. I've updated the module slot accordingly. (cherry picked from commit 105f22ea46ac16866e6df18ebae2a8ba422b7f45, AKA gh-119929) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.13] gh-119799: Add missing `_Py_IncRefTotal` to `_Py_NewRefWithLock` ↵Miss Islington (bot)2024-05-311-0/+3
| | | | | | | | | (GH-119800) (#119878) The free-threaded refleak builds were reporting negative refcount deltas in some tests because of a missing `_Py_NewRefWithLock`. (cherry picked from commit 879d43b705faab0c59f1a6a0042e286f39f3a4ef) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-117657: Fix data races when writing / reading `ob_gc_bits` ↵Miss Islington (bot)2024-05-081-3/+3
| | | | | | | | | | (GH-118292) (#118796) Use relaxed atomics when reading / writing to the field. There are still a few places in the GC where we do not use atomics. Those should be safe as the world is stopped. (cherry picked from commit cb6f75a32ca2649c6cc1cabb0301eb783efbd55b) Co-authored-by: mpage <mpage@meta.com>
* gh-118362: Fix thread safety around lookups from the type cache in the face ↵Dino Viehland2024-05-061-0/+1
| | | | | | | of concurrent mutators (#118454) Add _PyType_LookupRef and use incref before setting attribute on type Makes setting an attribute on a class and signaling type modified atomic Avoid adding re-entrancy exposing the type cache in an inconsistent state by decrefing after type is updated
* gh-93502: Add new C-API functions to trace object creation and destruction ↵Pablo Galindo Salgado2024-05-021-1/+1
| | | | (#115945)
* gh-117657: Fixes a few small TSAN issues in dictobject (#118200)Dino Viehland2024-04-251-1/+1
| | | | Fixup TSAN errors for dict
* gh-112075: Make instance attributes stored in inline "dict" thread safe ↵Dino Viehland2024-04-221-4/+12
| | | | | (#114742) Make instance attributes stored in inline "dict" thread safe on free-threaded builds
* GH-117760: Streamline the trashcan mechanism (GH-117763)Mark Shannon2024-04-171-1/+0
|
* gh-117376: Partial implementation of deferred reference counting (#117696)Sam Gross2024-04-121-0/+15
| | | | | This marks objects as using deferred refrence counting using the `ob_gc_bits` field in the free-threaded build and collects those objects during GC.
* gh-117439: Make refleak checking thread-safe without the GIL (#117469)Sam Gross2024-04-081-6/+6
| | | | | This keeps track of the per-thread total reference count operations in PyThreadState in the free-threaded builds. The count is merged into the interpreter's total when the thread exits.
* gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)mpage2024-04-081-3/+37
| | | | | | | | | Most mutable data is protected by a striped lock that is keyed on the referenced object's address. The weakref's hash is protected using the weakref's per-object lock. Note that this only affects free-threaded builds. Apart from some minor refactoring, the added code is all either gated by `ifdef`s or is a no-op (e.g. `Py_BEGIN_CRITICAL_SECTION`).
* GH-115776: Embed the values array into the object, for "normal" Python ↵Mark Shannon2024-04-021-35/+13
| | | | objects. (GH-116115)
* GH-117108: Set the "old space bit" to "visited" for all young objects (#117213)Mark Shannon2024-03-261-2/+2
| | | | Change old space bit of young objects from 0 to gcstate->visited_space. This ensures that any object created *and* collected during cycle GC has the bit set correctly.
* gh-115754: Add Py_GetConstant() function (#116883)Victor Stinner2024-03-211-0/+2
| | | | | | | | | | | | 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-108362: Incremental Cycle GC (GH-116206)Mark Shannon2024-03-201-14/+4
|
* GH-115802: JIT "small" code for Windows (GH-115964)Brandt Bucher2024-02-291-2/+2
|
* GH-108362: Revert "GH-108362: Incremental GC implementation (GH-108038)" ↵Mark Shannon2024-02-071-3/+14
| | | | | | | (#115132) Revert "GH-108362: Incremental GC implementation (GH-108038)" This reverts commit 36518e69d74607e5f094ce55286188e4545a947d.
* GH-108362: Incremental GC implementation (GH-108038)Mark Shannon2024-02-051-14/+3
|
* gh-112529: Remove PyGC_Head from object pre-header in free-threaded build ↵Sam Gross2024-02-011-9/+18
| | | | | | | | | | | | | | | | | (#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-113464: Add a JIT backend for tier 2 (GH-113465)Brandt Bucher2024-01-291-2/+2
| | | | | | | Add an option (--enable-experimental-jit for configure-based builds or --experimental-jit for PCbuild-based ones) to build an *experimental* just-in-time compiler, based on copy-and-patch (https://fredrikbk.com/publications/copy-and-patch.pdf). See Tools/jit/README.md for more information on how to install the required build-time tooling.
* gh-112529: Implement GC for free-threaded builds (#114262)Sam Gross2024-01-251-0/+8
| | | | | | | * 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-112075: Add try-incref functions from nogil branch for use in dict thread ↵Dino Viehland2024-01-251-0/+136
| | | | | | | | | | | | | | | | | | | | safety (#114512) * Bring in a subset of biased reference counting: https://github.com/colesbury/nogil/commit/b6b12a9a94e The NoGIL branch has functions for attempting to do an incref on an object which may or may not be in flight. This just brings those functions over so that they will be usable from in the dict implementation to get items w/o holding a lock. There's a handful of small simple modifications: Adding inline to the force inline functions to avoid a warning, and switching from _Py_ALWAYS_INLINE to Py_ALWAYS_INLINE as that's available Remove _Py_REF_LOCAL_SHIFT as it doesn't exist yet (and is currently 0 in the 3.12 nogil branch anyway) ob_ref_shared is currently Py_ssize_t and not uint32_t, so use that _PY_LIKELY doesn't exist, so drop it _Py_ThreadLocal becomes _Py_IsOwnedByCurrentThread Add '_PyInterpreterState_GET()' to _Py_IncRefTotal calls. Co-Authored-By: Sam Gross <colesbury@gmail.com>
* gh-111863: Rename `Py_NOGIL` to `Py_GIL_DISABLED` (#111864)Hugo van Kemenade2023-11-201-7/+7
| | | Rename Py_NOGIL to Py_GIL_DISABLED
* gh-110481: Implement biased reference counting (gh-110764)Sam Gross2023-10-301-5/+84
|
* gh-106213: Make Emscripten trampolines work with JSPI (GH-106219)Hood Chatham2023-09-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | There is a WIP proposal to enable webassembly stack switching which have been implemented in v8: https://github.com/WebAssembly/js-promise-integration It is not possible to switch stacks that contain JS frames so the Emscripten JS trampolines that allow calling functions with the wrong number of arguments don't work in this case. However, the js-promise-integration proposal requires the [type reflection for Wasm/JS API](https://github.com/WebAssembly/js-types) proposal, which allows us to actually count the number of arguments a function expects. For better compatibility with stack switching, this PR checks if type reflection is available, and if so we use a switch block to decide the appropriate signature. If type reflection is unavailable, we should use the current EMJS trampoline. We cache the function argument counts since when I didn't cache them performance was negatively affected. Co-authored-by: T. Wouters <thomas@python.org> Co-authored-by: Brett Cannon <brett@python.org>
* gh-108634: PyInterpreterState_New() no longer calls Py_FatalError() (#108748)Victor Stinner2023-09-011-1/+1
| | | | | | | | | | | | pycore_create_interpreter() now returns a status, rather than calling Py_FatalError(). * PyInterpreterState_New() now calls Py_ExitStatusException() instead of calling Py_FatalError() directly. * Replace Py_FatalError() with PyStatus in init_interpreter() and _PyObject_InitState(). * _PyErr_SetFromPyStatus() now raises RuntimeError, instead of ValueError. It can now call PyErr_NoMemory(), raise MemoryError, if it detects _PyStatus_NO_MEMORY() error message.
* gh-108634: Py_TRACE_REFS uses a hash table (#108663)Victor Stinner2023-08-311-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python built with "configure --with-trace-refs" (tracing references) is now ABI compatible with Python release build and debug build. Moreover, it now also supports the Limited API. Change Py_TRACE_REFS build: * Remove _PyObject_EXTRA_INIT macro. * The PyObject structure no longer has two extra members (_ob_prev and _ob_next). * Use a hash table (_Py_hashtable_t) to trace references (all objects): PyInterpreterState.object_state.refchain. * Py_TRACE_REFS build is now ABI compatible with release build and debug build. * Limited C API extensions can now be built with Py_TRACE_REFS: xxlimited, xxlimited_35, _testclinic_limited. * No longer rename PyModule_Create2() and PyModule_FromDefAndSpec2() functions to PyModule_Create2TraceRefs() and PyModule_FromDefAndSpec2TraceRefs(). * _Py_PrintReferenceAddresses() is now called before finalize_interp_delete() which deletes the refchain hash table. * test_tracemalloc find_trace() now also filters by size to ignore the memory allocated by _PyRefchain_Trace(). Test changes for Py_TRACE_REFS: * Add test.support.Py_TRACE_REFS constant. * Add test_sys.test_getobjects() to test sys.getobjects() function. * test_exceptions skips test_recursion_normalizing_with_no_memory() and test_memory_error_in_PyErr_PrintEx() if Python is built with Py_TRACE_REFS. * test_repl skips test_no_memory(). * test_capi skisp test_set_nomemory().
* gh-106320: Don't export _Py_ForgetReference() function (#108712)Victor Stinner2023-08-311-2/+8
| | | | | There is no need to export the _Py_ForgetReference() function of the Py_TRACE_REFS build. It's not used by shared extensions. Enhance also its comment.
* gh-106320: Remove private _Py_ForgetReference() (#108664)Victor Stinner2023-08-301-0/+5
| | | | Move the private _Py_ForgetReference() function to the internal C API (pycore_object.h).
* gh-106320: Remove private _PyObject_GetState() (#108606)Victor Stinner2023-08-291-0/+4
| | | | Move the private _PyObject_GetState() function to the internal C API (pycore_object.h).
* gh-107211: No longer export internal functions (6) (#108424)Victor Stinner2023-08-241-4/+2
| | | | | | | | | | | | No longer export these 5 internal C API functions: * _PyArena_AddPyObject() * _PyArena_Free() * _PyArena_Malloc() * _PyArena_New() * _Py_FatalRefcountErrorFunc() Change comment style to "// comment" and add comment explaining why other functions have to be exported.
* gh-108216: Cleanup #include in internal header files (#108228)Victor Stinner2023-08-211-1/+0
| | | | | | | | | | | * Add missing includes. * Remove unused includes. * Update old include/symbol names to newer names. * Mention at least one included symbol. * Sort includes. * Update Tools/cases_generator/generate_cases.py used to generated pycore_opcode_metadata.h. * Update Parser/asdl_c.py used to generate pycore_ast.h. * Cleanup also includes in _testcapimodule.c and _testinternalcapi.c.
* gh-84805: Autogenerate signature for METH_NOARGS and METH_O extension ↵Serhiy Storchaka2023-08-111-1/+1
| | | | functions (GH-107794)
* gh-107630: Initialize Each Interpreter's refchain Properly (gh-107733)Eric Snow2023-08-071-0/+1
| | | This finishes fixing the crashes in Py_TRACE_REFS builds. We missed this part in gh-107567.
* gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters (gh-107567)Eric Snow2023-08-031-2/+2
| | | The linked list of objects was a global variable, which broke isolation between interpreters, causing crashes. To solve this, we've moved the linked list to each interpreter.
* gh-107211: No longer export internal variables (#107218)Victor Stinner2023-07-251-3/+6
| | | | | | | | | | | | | | | | No longer export these 5 internal C API variables: * _PyBufferWrapper_Type * _PyImport_FrozenBootstrap * _PyImport_FrozenStdlib * _PyImport_FrozenTest * _Py_SwappedOp Fix the definition of these internal functions, replace PyAPI_DATA() with PyAPI_FUNC(): * _PyImport_ClearExtension() * _PyObject_IsFreed() * _PyThreadState_GetCurrent()
* gh-107211: No longer export internal functions (4) (#107217)Victor Stinner2023-07-251-1/+2
| | | | | | | | | No longer export these 2 internal C API functions: * _PyEval_SignalAsyncExc() * _PyEval_SignalReceived() Add also comments explaining why some internal functions have to be exported, and update existing comments.
* gh-107211: No longer export internal functions (2) (#107214)Victor Stinner2023-07-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No longer export these 43 internal C API functions: * _PyDict_CheckConsistency() * _PyErr_ChainStackItem() * _PyErr_CheckSignals() * _PyErr_CheckSignalsTstate() * _PyErr_Clear() * _PyErr_ExceptionMatches() * _PyErr_Fetch() * _PyErr_Format() * _PyErr_FormatFromCauseTstate() * _PyErr_GetExcInfo() * _PyErr_GetHandledException() * _PyErr_GetTopmostException() * _PyErr_NoMemory() * _PyErr_NormalizeException() * _PyErr_Restore() * _PyErr_SetHandledException() * _PyErr_SetNone() * _PyErr_SetObject() * _PyErr_SetString() * _PyErr_StackItemToExcInfoTuple() * _PyExc_CreateExceptionGroup() * _PyExc_PrepReraiseStar() * _PyException_AddNote() * _PyInterpreterState_Enable() * _PyLong_FormatAdvancedWriter() * _PyLong_FormatBytesWriter() * _PyLong_FormatWriter() * _PyMem_GetAllocatorName() * _PyMem_SetDefaultAllocator() * _PyMem_SetupAllocators() * _PyOS_InterruptOccurred() * _PyRuntimeState_Fini() * _PyRuntimeState_Init() * _PyRuntime_Finalize() * _PyRuntime_Initialize() * _PyThreadState_Bind() * _PyThreadState_DeleteExcept() * _PyThreadState_New() * _PyThreadState_Swap() * _PyType_CheckConsistency() * _PyUnicodeTranslateError_Create() * _Py_DumpExtensionModules() * _Py_FatalErrorFormat()
* gh-106320: Remove private _PyObject C API (#107159)Victor Stinner2023-07-231-1/+10
| | | | | | | | | | | | | Move private _PyObject and private _PyType functions to the internal C API (pycore_object.h): * _PyObject_GetMethod() * _PyObject_IsAbstract() * _PyObject_NextNotImplemented() * _PyType_CalculateMetaclass() * _PyType_GetDocFromInternalDoc() * _PyType_GetTextSignatureFromInternalDoc() No longer export these functions.