summaryrefslogtreecommitdiffstats
path: root/Include/cpython/object.h
Commit message (Collapse)AuthorAgeFilesLines
* gh-142217: Deprecate the private _Py_Identifier C API (#142221)Victor Stinner2025-12-121-1/+1
| | | | | | | Deprecate functions: * _PyObject_CallMethodId() * _PyObject_GetAttrId() * _PyUnicode_FromId()
* gh-130396: Remove _Py_ReachedRecursionLimitWithMargin() function (#141951)Victor Stinner2025-11-271-2/+0
| | | Move the private function to the internal C API (pycore_ceval.h).
* gh-141070: Add PyUnstable_Object_Dump() function (#141072)Victor Stinner2025-11-181-5/+9
| | | | | | | | | | * Promote _PyObject_Dump() as a public function. * Keep _PyObject_Dump() alias to PyUnstable_Object_Dump() for backward compatibility. * Replace _PyObject_Dump() with PyUnstable_Object_Dump(). Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-112075: Remove _PyObject_SetManagedDict() function (#139737)Victor Stinner2025-10-121-1/+0
| | | Move it to the internal C API and no longer export it.
* gh-138342: Move _PyObject_VisitType() to the internal C API (#139734)Victor Stinner2025-10-081-4/+0
|
* gh-138794: Communicate to PyRefTracer when they are being replaced (#138797)Pablo Galindo Salgado2025-09-151-0/+1
|
* gh-138342: Use a common utility for visiting an object's type (GH-138343)Peter Bierma2025-09-011-0/+4
| | | Add `_PyObject_VisitType` in place of `tp_traverse` functions that only visit the object's type.
* Revert "gh-133395: add option for extension modules to specialize ↵Irit Katriel2025-05-061-12/+0
| | | | BINARY_OP/SUBSCR, apply to arrays (#133396)" (#133498)
* gh-133140: Add `PyUnstable_Object_IsUniquelyReferenced` for free-threading ↵Peter Bierma2025-05-051-0/+2
| | | | (#133144)
* gh-133395: add option for extension modules to specialize BINARY_OP/SUBSCR, ↵Irit Katriel2025-05-051-0/+12
| | | | apply to arrays (#133396)
* gh-133164: Add `PyUnstable_Object_IsUniqueReferencedTemporary` C API (gh-133170)Sam Gross2025-05-021-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | After gh-130704, the interpreter replaces some uses of `LOAD_FAST` with `LOAD_FAST_BORROW` which avoid incref/decrefs by "borrowing" references on the interpreter stack when the bytecode compiler can determine that it's safe. This change broke some checks in C API extensions that relied on `Py_REFCNT()` of `1` to determine if it's safe to modify an object in-place. Objects may have a reference count of one, but still be referenced further up the interpreter stack due to borrowing of references. This provides a replacement function for those checks. `PyUnstable_Object_IsUniqueReferencedTemporary` is more conservative: it checks that the object has a reference count of one and that it exists as a unique strong reference in the interpreter's stack of temporary variables in the top most frame. See also: * https://github.com/numpy/numpy/issues/28681 Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: T. Wouters <thomas@python.org> Co-authored-by: mpage <mpage@cs.stanford.edu> Co-authored-by: Mark Shannon <mark@hotpy.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* GH-124715: Move trashcan mechanism into `Py_Dealloc` (GH-132280)Mark Shannon2025-04-301-70/+3
|
* GH-131238: Core header refactor (GH-131250)Mark Shannon2025-03-171-1/+0
| | | | | * Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h * Removes many cross-header dependencies
* gh-131306: Remove unused code related to `BINARY_SUBSCR` (#131307)Tomas R.2025-03-161-1/+1
|
* GH-130396: Increase trashcan overhead (GH-130552)Mark Shannon2025-02-261-2/+2
| | | Double trashcan overhead
* gh-130202: Fix bug in `_PyObject_ResurrectEnd` in free threaded build ↵Sam Gross2025-02-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (gh-130281) This fixes a fairly subtle bug involving finalizers and resurrection in debug free threaded builds: if `_PyObject_ResurrectEnd` returns `1` (i.e., the object was resurrected by a finalizer), it's not safe to access the object because it might still be deallocated. For example: * The finalizer may have exposed the object to another thread. That thread may hold the last reference and concurrently deallocate it any time after `_PyObject_ResurrectEnd()` returns `1`. * `_PyObject_ResurrectEnd()` may call `_Py_brc_queue_object()`, which may internally deallocate the object immediately if the owning thread is dead. Therefore, it's important not to access the object after it's resurrected. We only violate this in two cases, and only in debug builds: * We assert that the object is tracked appropriately. This is now moved up betewen the finalizer and the `_PyObject_ResurrectEnd()` call. * The `--with-trace-refs` builds may need to remember the object if it's resurrected. This is now handled by `_PyObject_ResurrectStart()` and `_PyObject_ResurrectEnd()`. Note that `--with-trace-refs` is currently disabled in `--disable-gil` builds because the refchain hash table isn't thread-safe, but this refactoring avoids an additional thread-safety issue.
* GH-130396: Use computed stack limits on linux (GH-130398)Mark Shannon2025-02-251-5/+6
| | | | | | | | | | | * Implement C recursion protection with limit pointers for Linux, MacOS and Windows * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not ↵Petr Viktorin2025-02-241-6/+5
| | | | | | | | | counters. (GH-130007)" for now (GH130413) Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now Unfortunatlely, the change broke some buildbots. This reverts commit 2498c22fa0a2b560491bc503fa676585c1a603d0.
* GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)Mark Shannon2025-02-191-5/+6
| | | | | | | | | | | | * Implement C recursion protection with limit pointers * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* gh-128844: Make `_Py_TryIncref` public as an unstable API. (#128926)Sam Gross2025-01-281-0/+6
| | | | | | | | | This exposes `_Py_TryIncref` as `PyUnstable_TryIncref()` and the helper function `_PyObject_SetMaybeWeakref` as `PyUnstable_EnableTryIncRef`. These are helpers for dealing with unowned references in a safe way, particularly in the free threading build. Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-128509: Add `PyUnstable_IsImmortal` for finding immortal objects (GH-129182)Peter Bierma2025-01-271-0/+3
| | | | | Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-128910: Remove `_PyTrash_begin` and `_PyTrash_end` C-API functions (#128919)sobolevn2025-01-161-3/+0
|
* gh-127773: Disable attribute cache on incompatible MRO entries (GH-127924)Petr Viktorin2025-01-131-1/+11
|
* gh-123619: Add an unstable C API function for enabling deferred reference ↵Peter Bierma2024-11-131-0/+7
| | | | | | counting (GH-123635) Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-124218: Use per-thread refcounts for code objects (#125216)Sam Gross2024-10-151-1/+1
| | | | | | | Use per-thread refcounting for the reference from function objects to their corresponding code object. This can be a source of contention when frequently creating nested functions. Deferred refcounting alone isn't a great fit here because these references are on the heap and may be modified by other libraries.
* gh-124153: Implement `PyType_GetBaseByToken()` and `Py_tp_token` slot ↵neonene2024-09-181-0/+1
| | | | (GH-124163)
* gh-122417: Implement per-thread heap type refcounts (#122418)Sam Gross2024-08-061-0/+3
| | | | | | | The free-threaded build partially stores heap type reference counts in distributed manner in per-thread arrays. This avoids reference count contention when creating or destroying instances. Co-authored-by: Ken Jin <kenjin@python.org>
* gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (#118807)Sam Gross2024-06-181-0/+2
| | | | | | | | | | | | This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` as an unstable C-API function to provide a thread-safe mechanism for clearing weakrefs without executing callbacks. Some C-API extensions need to clear weakrefs without calling callbacks, such as after running finalizers like we do in subtype_dealloc. Previously they could use `_PyWeakref_ClearRef` on each weakref, but that's not thread-safe in the free-threaded build. Co-authored-by: Petr Viktorin <encukou@gmail.com>
* Fix typos in comments (#120188)Xie Yanbo2024-06-071-1/+1
|
* 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-0/+10
| | | | (#115945)
* gh-118331: Handle errors in _PyObject_SetManagedDict (#118334)Sam Gross2024-04-291-1/+1
| | | | | When detaching a dict, the `copy_values` call may fail due to out-of-memory errors. This can be triggered by test_no_memory in test_repl.
* gh-112075: Make instance attributes stored in inline "dict" thread safe ↵Dino Viehland2024-04-221-0/+1
| | | | | (#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-22/+25
|
* gh-116936: Add PyType_GetModuleByDef() to the limited C API (#116937)Victor Stinner2024-03-251-1/+0
|
* GH-113462: Limit the number of versions that a single class can use. (GH-114900)Mark Shannon2024-02-051-0/+1
|
* gh-113750: Fix object resurrection in free-threaded builds (gh-113751)Sam Gross2024-01-061-0/+1
| | | | | | | | | gh-113750: Fix object resurrection on free-threaded builds This avoids the undesired re-initializing of fields like `ob_gc_bits`, `ob_mutex`, and `ob_tid` when an object is resurrected due to its finalizer being called. This change has no effect on the default (with GIL) build.
* gh-111971: Make _PyUnicode_FromId thread-safe in --disable-gil (gh-113489)Donghee Na2023-12-261-0/+4
|
* gh-112026: Restore removed private C API (#112115)Victor Stinner2023-11-151-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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()
* gh-108867: Add PyThreadState_GetUnchecked() function (#108870)Victor Stinner2023-10-031-1/+1
| | | | | | Add PyThreadState_GetUnchecked() function: similar to PyThreadState_Get(), but don't issue a fatal error if it is NULL. The caller is responsible to check if the result is NULL. Previously, this function was private and known as _PyThreadState_UncheckedGet().
* gh-107073: Make PyObject_VisitManagedDict() public (#108763)Victor Stinner2023-10-021-2/+2
| | | | | | | | Make PyObject_VisitManagedDict() and PyObject_ClearManagedDict() functions public in Python 3.13 C API. * Rename _PyObject_VisitManagedDict() to PyObject_VisitManagedDict(). * Rename _PyObject_ClearManagedDict() to PyObject_ClearManagedDict(). * Document these functions.
* gh-106320: Remove private _Py_ForgetReference() (#108664)Victor Stinner2023-08-301-5/+0
| | | | Move the private _Py_ForgetReference() function to the internal C API (pycore_object.h).
* gh-106320: Remove private _Py_Identifier API (#108593)Victor Stinner2023-08-291-42/+0
| | | | | | | | | | | | | | | Remove the private _Py_Identifier type and related private functions from the public C API: * _PyObject_GetAttrId() * _PyObject_LookupSpecialId() * _PyObject_SetAttrId() * _PyType_LookupId() * _Py_IDENTIFIER() * _Py_static_string() * _Py_static_string_init() Move them to the internal C API: add a new pycore_identifier.h header file. No longer export these functions.
* gh-91051: fix segfault when using all 8 type watchers (#107853)Carl Meyer2023-08-111-1/+1
|
* gh-106320: Remove private _PyObject C API (#107159)Victor Stinner2023-07-231-12/+0
| | | | | | | | | | | | | 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.
* gh-106320: Remove private _PyObject C API (#107147)Victor Stinner2023-07-231-22/+0
| | | | | | | | | | | | | | | | Move private debug _PyObject functions to the internal C API (pycore_object.h): * _PyDebugAllocatorStats() * _PyObject_CheckConsistency() * _PyObject_DebugTypeStats() * _PyObject_IsFreed() No longer export most of these functions, except of _PyObject_IsFreed(). Move test functions using _PyObject_IsFreed() from _testcapi to _testinternalcapi. check_pyobject_is_freed() test no longer catch _testcapi.error: the tested function cannot raise _testcapi.error.
* gh-106320: Remove _Py_SwappedOp from the C API (#107036)Victor Stinner2023-07-221-5/+0
| | | Move _Py_SwappedOp to the internal C API (pycore_object.h).
* gh-106320: Move _PyNone_Type to the internal C API (#107030)Victor Stinner2023-07-221-3/+0
| | | | Move private types _PyNone_Type and _PyNotImplemented_Type to internal C API.
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-1/+0
|
* gh-106521: Add PyObject_GetOptionalAttr() function (GH-106522)Serhiy Storchaka2023-07-111-11/+1
| | | | | | It is a new name of former _PyObject_LookupAttr(). Add also PyObject_GetOptionalAttrString().