summaryrefslogtreecommitdiffstats
path: root/Include/cpython/object.h
Commit message (Collapse)AuthorAgeFilesLines
* 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().
* gh-105227: Add PyType_GetDict() (GH-105747)Eric Snow2023-07-101-0/+1
| | | | | This compensates for static builtin types having `tp_dict` set to `NULL`. Co-authored-by: Petr Viktorin <encukou@gmail.com>
* Fix duplicate word typos in comments (#106225)Md Sadman Chowdhury2023-07-011-1/+1
|
* GH-91095: Specialize calls to normal Python classes. (GH-99331)Mark Shannon2023-06-221-0/+1
|
* gh-105111: remove deprecated macros Py_TRASHCAN_SAFE_BEGIN and ↵Irit Katriel2023-05-311-13/+0
| | | | Py_TRASHCAN_SAFE_END (#105112)
* gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511)Petr Viktorin2023-05-041-0/+1
| | | | Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-103091: Add PyUnstable_Type_AssignVersionTag (#103095)Brett Simmers2023-04-241-0/+7
|
* GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022)Brandt Bucher2023-03-291-0/+11
|
* gh-102304: Move the Total Refcount to PyInterpreterState (gh-102545)Eric Snow2023-03-211-0/+1
| | | | | Moving it valuable with a per-interpreter GIL. However, it is also useful without one, since it allows us to identify refleaks within a single interpreter or where references are escaping an interpreter. This becomes more important as we move the obmalloc state to PyInterpreterState. https://github.com/python/cpython/issues/102304
* gh-102304: Move _Py_RefTotal to _PyRuntimeState (gh-102543)Eric Snow2023-03-201-1/+4
| | | | | | | The essentially eliminates the global variable, with the associated benefits. This is also a precursor to isolating this bit of state to PyInterpreterState. Folks that currently read _Py_RefTotal directly would have to start using _Py_GetGlobalRefTotal() instead. https://github.com/python/cpython/issues/102304
* gh-102304: Consolidate Direct Usage of _Py_RefTotal (gh-102514)Eric Snow2023-03-081-0/+1
| | | | | This simplifies further changes to _Py_RefTotal (e.g. make it atomic or move it to PyInterpreterState). https://github.com/python/cpython/issues/102304
* gh-59956: Allow the "Trashcan" Mechanism to Work Without a Thread State ↵Eric Snow2023-01-231-1/+1
| | | | | | | | | | | | (gh-101209) We've factored out a struct from the two PyThreadState fields. This accomplishes two things: * make it clear that the trashcan-related code doesn't need any other parts of PyThreadState * allows us to use the trashcan mechanism even when there isn't a "current" thread state We still expect the caller to hold the GIL. https://github.com/python/cpython/issues/59956
* gh-98724: Fix Py_CLEAR() macro side effects (#99100) (#100070)Victor Stinner2022-12-071-20/+51
| | | | | | | | | | | | | | The Py_CLEAR(), Py_SETREF() and Py_XSETREF() macros now only evaluate their arguments once. If an argument has side effects, these side effects are no longer duplicated. Use temporary variables to avoid duplicating side effects of macro arguments. If available, use _Py_TYPEOF() to avoid type punning. Otherwise, use memcpy() for the assignment to prevent a miscompilation with strict aliasing caused by type punning. Add _Py_TYPEOF() macro: __typeof__() on GCC and clang. Add test_py_clear() and test_py_setref() unit tests to _testcapi.
* Revert "gh-98724: Fix Py_CLEAR() macro side effects" (#99737)Victor Stinner2022-11-241-24/+20
| | | | | Revert "gh-98724: Fix Py_CLEAR() macro side effects (#99100)" This reverts commit c03e05c2e72f3ea5e797389e7d1042eef85ad37a.
* GH-90699: disallow `_Py_IDENTIFIER` in core code (GH-99210)Kumar Aditya2022-11-091-2/+2
|
* gh-98724: Fix Py_CLEAR() macro side effects (#99100)Victor Stinner2022-11-091-20/+24
| | | | | | | The Py_CLEAR(), Py_SETREF() and Py_XSETREF() macros now only evaluate their argument once. If an argument has side effects, these side effects are no longer duplicated. Add test_py_clear() and test_py_setref() unit tests to _testcapi.
* gh-98410: move getbufferproc and releasebufferproc to buffer.h (#31158)David Hewitt2022-10-311-4/+0
| | | This adds them to the Limited API.
* gh-91051: allow setting a callback hook on PyType_Modified (GH-97875)Carl Meyer2022-10-211-0/+11
|
* gh-93274: Expose receiving vectorcall in the Limited API (GH-95717)Petr Viktorin2022-08-081-3/+0
|
* gh-94673: Add Per-Interpreter tp_subclasses for Static Builtin Types (gh-95301)Eric Snow2022-08-051-3/+2
|
* GH-95245: Store object values and dict pointers in single tagged pointer. ↵Mark Shannon2022-08-011-0/+4
| | | | (GH-95278)
* gh-94673: Add Per-Interpreter tp_weaklist for Static Builtin Types (#95302)Eric Snow2022-07-291-1/+1
| | | | | | | | | | | | | | | * Store tp_weaklist on the interpreter state for static builtin types. * Factor out _PyStaticType_GET_WEAKREFS_LISTPTR(). * Add _PyStaticType_ClearWeakRefs(). * Add a comment about how _PyStaticType_ClearWeakRefs() loops. * Document the change. * Update Doc/whatsnew/3.12.rst * Fix a typo.
* gh-94673: Add Per-Interpreter Storage for Static Builtin Types (#95255)Eric Snow2022-07-261-0/+1
| | | | | | | | | | | | | | This is the last precursor to storing tp_subclasses (and tp_weaklist) on the interpreter state for static builtin types. Here we add per-type storage on PyInterpreterState, but only for the static builtin types. This involves the following: * add PyInterpreterState.types * move PyInterpreterState.type_cache to it * add a "num_builtins_initialized" field * add a "builtins" field (a static array big enough for all the static builtin types) * add _PyStaticType_GetState() to look up a static builtin type's state * (temporarily) add PyTypeObject.tp_static_builtin_index (to hold the type's index into PyInterpreterState.types.builtins) We will be eliminating tp_static_builtin_index in a later change.