summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists ↵Donghee Na2024-02-101-0/+15
| | | | (gh-114899)
* gh-110481: Implement inter-thread queue for biased reference counting (#114824)Sam Gross2024-02-091-6/+2
| | | | | | | | | Biased reference counting maintains two refcount fields in each object: `ob_ref_local` and `ob_ref_shared`. The true refcount is the sum of these two fields. In some cases, when refcounting operations are split across threads, the ob_ref_shared field can be negative (although the total refcount must be at least zero). In this case, the thread that decremented the refcount requests that the owning thread give up ownership and merge the refcount fields.
* gh-115184: Fix refleak tracking issues in free-threaded build (#115188)Sam Gross2024-02-091-4/+7
| | | | | | | | Fixes a few issues related to refleak tracking in the free-threaded build: - Count blocks in abandoned segments - Call `_mi_page_free_collect` earlier during heap traversal in order to get an accurate count of blocks in use. - Add missing refcount tracking in `_Py_DecRefSharedDebug` and `_Py_ExplicitMergeRefcount`. - Pause threads in `get_num_global_allocated_blocks` to ensure that traversing the mimalloc heaps is safe.
* GH-108362: Revert "GH-108362: Incremental GC implementation (GH-108038)" ↵Mark Shannon2024-02-071-15/+0
| | | | | | | (#115132) Revert "GH-108362: Incremental GC implementation (GH-108038)" This reverts commit 36518e69d74607e5f094ce55286188e4545a947d.
* GH-108362: Incremental GC implementation (GH-108038)Mark Shannon2024-02-051-0/+15
|
* gh-112529: Remove PyGC_Head from object pre-header in free-threaded build ↵Sam Gross2024-02-011-2/+11
| | | | | | | | | | | | | | | | | (#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-113750: Fix object resurrection in free-threaded builds (gh-113751)Sam Gross2024-01-061-3/+12
| | | | | | | | | 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-111178: Make slot functions in typeobject.c have compatible types (GH-112752)Christopher Chavez2023-12-201-1/+1
|
* gh-112125: Fix None.__ne__(None) returning NotImplemented instead of False ↵andrewluotechnologies2023-12-071-1/+1
| | | | (#112504)
* gh-111863: Rename `Py_NOGIL` to `Py_GIL_DISABLED` (#111864)Hugo van Kemenade2023-11-201-3/+3
| | | Rename Py_NOGIL to Py_GIL_DISABLED
* gh-111789: Use PyDict_GetItemRef() in Objects/ (GH-111827)Serhiy Storchaka2023-11-141-20/+11
|
* gh-110481: fix 'unused function' warning for `is_shared_refcnt_dead`. ↵Sam Gross2023-11-101-4/+6
| | | | | | | (gh-111974) Fix 'unused function' warning for `is_shared_refcnt_dead`. The `is_shared_refcnt_dead` function is only used if `Py_REF_DEBUG` is set.
* gh-111569: Implement Python critical section API (gh-111571)Sam Gross2023-11-081-1/+1
| | | | | | | | Critical sections are helpers to replace the global interpreter lock with finer grained locking. They provide similar guarantees to the GIL and avoid the deadlock risk that plain locking involves. Critical sections are implicitly ended whenever the GIL would be released. They are resumed when the GIL would be acquired. Nested critical sections behave as if the sections were interleaved.
* gh-106672: C API: Report indiscriminately ignored errors (GH-106674)Serhiy Storchaka2023-11-071-2/+8
| | | | | Functions which indiscriminately ignore all errors now report them as unraisable errors.
* gh-111506: Implement Py_SET_REFCNT() as opaque function in limited C API ↵Victor Stinner2023-11-031-0/+8
| | | | | | | | (#111508) In the limited C API version 3.13, Py_SET_REFCNT() function is now implemented as an opaque function call. Add _Py_SetRefcnt() to the stable ABI.
* gh-110481: Implement biased reference counting (gh-110764)Sam Gross2023-10-301-8/+129
|
* GH-111339: Fix initialization and finalization of static optimizer types ↵Savannah Ostrowski2023-10-291-0/+6
| | | | (GH-111430)
* gh-110079: Remove extern "C" { ...} in C code (#110080)Victor Stinner2023-09-291-8/+0
|
* gh-108511: Add C API functions which do not silently ignore errors (GH-109025)Serhiy Storchaka2023-09-171-22/+25
| | | | | | | | | Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
* gh-108634: PyInterpreterState_New() no longer calls Py_FatalError() (#108748)Victor Stinner2023-09-011-2/+3
| | | | | | | | | | | | 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-101/+173
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Remove _PyAnextAwaitable_Type from the public C API (#108597)Victor Stinner2023-08-291-3/+4
| | | | It's not needed to declare it in Include/iterobject.h: just use "extern" where it's used (only in object.c).
* gh-106320: Remove private _PyManagedBuffer_Type (#108431)Victor Stinner2023-08-241-1/+3
| | | | Remove private _PyManagedBuffer_Type variable. Move it to the internal C API and no longer export it.
* GH-106485: Create object's dict-values instead of creating __dict__, when we ↵Mark Shannon2023-08-111-0/+8
| | | | can. (GH-107843)
* gh-107630: Initialize Each Interpreter's refchain Properly (gh-107733)Eric Snow2023-08-071-1/+21
| | | 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-19/+32
| | | 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-101524: Only Use Public C-API in the _xxsubinterpreters Module (gh-107359)Eric Snow2023-07-271-3/+3
| | | The _xxsubinterpreters module should not rely on internal API. Some of the functions it uses were recently moved there however. Here we move them back (and expose them properly).
* gh-102304: Rename _Py_IncRefTotal_DO_NOT_USE_THIS() (#107193)Victor Stinner2023-07-241-2/+2
| | | | | * Rename _Py_IncRefTotal_DO_NOT_USE_THIS() to _Py_INCREF_IncRefTotal() * Rename _Py_DecRefTotal_DO_NOT_USE_THIS() to _Py_DECREF_DecRefTotal() * Remove temporary _Py_INC_REFTOTAL() and _Py_DEC_REFTOTAL() macros
* gh-106320: Move _PyMethodWrapper_Type to internal C API (#107064)Victor Stinner2023-07-221-0/+1
|
* gh-106320: Remove private _PyInterpreterID C API (#107053)Victor Stinner2023-07-221-2/+2
| | | | | | | Move the private _PyInterpreterID C API to the internal C API: add a new pycore_interp_id.h header file. Remove Include/interpreteridobject.h and Include/cpython/interpreteridobject.h header files.
* gh-106320: Remove _Py_SwappedOp from the C API (#107036)Victor Stinner2023-07-221-1/+1
| | | Move _Py_SwappedOp to the internal C API (pycore_object.h).
* gh-96663: Add a better error message for __dict__-less classes setattr (#103232)James Hilton-Balfe2023-07-221-3/+13
|
* gh-106521: Add PyObject_GetOptionalAttr() function (GH-106522)Serhiy Storchaka2023-07-111-10/+24
| | | | | | It is a new name of former _PyObject_LookupAttr(). Add also PyObject_GetOptionalAttrString().
* gh-106572: Convert PyObject_DelAttr() to a function (#106611)Victor Stinner2023-07-111-0/+12
| | | | | | | | * Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name).
* gh-105340: include hidden fast-locals in locals() (#105715)Carl Meyer2023-07-051-3/+4
| | | * gh-105340: include hidden fast-locals in locals()
* gh-101524: Only Use Public C-API in the _xxsubinterpreters Module (gh-105258)Eric Snow2023-06-021-1/+1
| | | The _xxsubinterpreters module was meant to only use public API. Some internal C-API usage snuck in over the last few years (e.g. gh-28969). This fixes that.
* gh-92536: Remove PyUnicode_READY() calls (#105210)Victor Stinner2023-06-011-14/+0
| | | | Since Python 3.12, PyUnicode_READY() does nothing and always returns 0.
* gh-104549: Set __module__ on TypeAliasType (#104550)Jelle Zijlstra2023-05-181-1/+2
|
* gh-103763: Implement PEP 695 (#103764)Jelle Zijlstra2023-05-161-0/+6
| | | | | | | | | | | | | | This implements PEP 695, Type Parameter Syntax. It adds support for: - Generic functions (def func[T](): ...) - Generic classes (class X[T](): ...) - Type aliases (type X = ...) - New scoping when the new syntax is used within a class body - Compiler and interpreter changes to support the new syntax and scoping rules Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Eric Traut <eric@traut.com> Co-authored-by: Larry Hastings <larry@hastings.org> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-102500: Implement PEP 688 (#102521)Jelle Zijlstra2023-05-041-0/+2
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* gh-104066: Improve performance of hasattr for module objects (#104063)Itamar Ostricher2023-05-041-0/+11
|
* gh-104078: Improve performance of PyObject_HasAttrString (#104079)Itamar Ostricher2023-05-031-6/+17
|
* gh-94673: Properly Initialize and Finalize Static Builtin Types for Each ↵Eric Snow2023-05-021-6/+2
| | | | | Interpreter (gh-104072) Until now, we haven't been initializing nor finalizing the per-interpreter state properly.
* gh-94673: Fix _PyTypes_InitTypes() and get_type_attr_as_size() (gh-103961)Eric Snow2023-04-281-4/+0
| | | | | | This change has two small parts: 1. a follow-up to gh-103940 with one case I missed 2. adding a missing return that I noticed while working on related code
* gh-94673: Ensure Builtin Static Types are Readied Properly (gh-103940)Eric Snow2023-04-271-3/+4
| | | There were cases where we do unnecessary work for builtin static types. This also simplifies some work necessary for a per-interpreter GIL.
* gh-101659: Isolate "obmalloc" State to Each Interpreter (gh-101660)Eric Snow2023-04-241-1/+1
| | | | | | | | | | | | | | This is strictly about moving the "obmalloc" runtime state from `_PyRuntimeState` to `PyInterpreterState`. Doing so improves isolation between interpreters, specifically most of the memory (incl. objects) allocated for each interpreter's use. This is important for a per-interpreter GIL, but such isolation is valuable even without it. FWIW, a per-interpreter obmalloc is the proverbial canary-in-the-coalmine when it comes to the isolation of objects between interpreters. Any object that leaks (unintentionally) to another interpreter is highly likely to cause a crash (on debug builds at least). That's a useful thing to know, relative to interpreter isolation.
* gh-103712: Increase the length of the type name in AttributeError messages ↵Alex Gaynor2023-04-241-4/+4
| | | | (#103713)
* gh-84436: Implement Immortal Objects (gh-19474)Eddie Elizondo2023-04-221-12/+20
| | | | | | | | | This is the implementation of PEP683 Motivation: The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime. Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
* gh-103092: Isolate winreg (#103250)AN Long2023-04-171-6/+0
|
* GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython ↵Mark Shannon2023-04-121-0/+2
| | | | | | | | | | (GH-103083) * The majority of the monitoring code is in instrumentation.c * The new instrumentation bytecodes are in bytecodes.c * legacy_tracing.c adapts the new API to the old sys.setrace and sys.setprofile APIs