summaryrefslogtreecommitdiffstats
path: root/Include/internal/pycore_object.h
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters ↵Eric Snow2023-08-161-2/+3
| | | | | | | | | | | (#107751) * Unrevert "[3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters (gh-107567) (#107599)". This reverts commit 6e4eec760648a71e1cd8f8f551997b1823b4bb9f (gh-107648). * Initialize each interpreter's refchain properly. * Skip test_basic_multiple_interpreters_deleted_no_reset on tracerefs builds.
* [3.12] gh-107630: Revert "[3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under ↵Eric Snow2023-08-051-2/+2
| | | | | | | Isolated Subinterpreters (gh-107567) (#107599)" (#107648) Revert "[3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters (gh-107567) (#107599)" This reverts commit 58af2293c52a1ad3754d254690c0e54f787c545b.
* [3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters ↵Miss Islington (bot)2023-08-031-2/+2
| | | | | | | | | | (gh-107567) (#107599) gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters (gh-107567) 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. (cherry picked from commit 58ef74186795c56e3ec86e8c8f351a1d7826638a) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.12] gh-105020: Share tp_bases and tp_mro Between Interpreters For All ↵Miss Islington (bot)2023-06-011-0/+15
| | | | | | | | Static Builtin Types (gh-105115) (gh-105124) In gh-103912 we added tp_bases and tp_mro to each PyInterpreterState.types.builtins entry. However, doing so ignored the fact that both PyTypeObject fields are public API, and not documented as internal (as opposed to tp_subclasses). We address that here by reverting back to shared objects, making them immortal in the process. (cherry picked from commit 7be667d) Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
* GH-104142: Fix _Py_RefcntAdd to respect immortality (GH-104143)Brandt Bucher2023-05-051-0/+3
|
* gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511)Petr Viktorin2023-05-041-5/+0
| | | | Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-94673: Hide Objects in PyTypeObject Behind Accessors (gh-104074)Eric Snow2023-05-021-6/+0
| | | This makes it much cleaner to move more PyTypeObject fields to PyInterpreterState.
* gh-94673: Properly Initialize and Finalize Static Builtin Types for Each ↵Eric Snow2023-05-021-1/+2
| | | | | Interpreter (gh-104072) Until now, we haven't been initializing nor finalizing the per-interpreter state properly.
* gh-84436: Implement Immortal Objects (gh-19474)Eddie Elizondo2023-04-221-15/+33
| | | | | | | | | 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-102213: Revert "gh-102213: Optimize the performance of `__getattr__` ↵Nikita Sobolev2023-04-071-1/+0
| | | | | (GH-102248)" (GH-103332) This reverts commit aa0a73d1bc53dcb6348a869df1e775138991e561.
* GH-101291: Rearrange the size bits in PyLongObject (GH-102464)Mark Shannon2023-03-221-1/+2
| | | | | | | | | | * Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
* gh-102304: Move the Total Refcount to PyInterpreterState (gh-102545)Eric Snow2023-03-211-7/+9
| | | | | 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/+3
| | | | | | | 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-102213: Optimize the performance of `__getattr__` (GH-102248)wangxiang-hz2023-03-111-0/+1
| | | | When __getattr__ is defined, python with try to find an attribute using _PyObject_GenericGetAttrWithDict find nothing is reasonable so we don't need an exception, it will hurt performance.
* gh-102304: Consolidate Direct Usage of _Py_RefTotal (gh-102514)Eric Snow2023-03-081-3/+20
| | | | | This simplifies further changes to _Py_RefTotal (e.g. make it atomic or move it to PyInterpreterState). https://github.com/python/cpython/issues/102304
* no-issue: Fix typo in pycore_object.h (gh-99994)Ikko Ashimine2022-12-051-1/+1
|
* gh-89653: PEP 670: Convert macros to functions (#99843)Victor Stinner2022-11-281-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert macros to static inline functions to avoid macro pitfalls, like duplication of side effects: * DK_ENTRIES() * DK_UNICODE_ENTRIES() * PyCode_GetNumFree() * PyFloat_AS_DOUBLE() * PyInstanceMethod_GET_FUNCTION() * PyMemoryView_GET_BASE() * PyMemoryView_GET_BUFFER() * PyMethod_GET_FUNCTION() * PyMethod_GET_SELF() * PySet_GET_SIZE() * _PyHeapType_GET_MEMBERS() Changes: * PyCode_GetNumFree() casts PyCode_GetNumFree.co_nfreevars from int to Py_ssize_t to be future proof, and because Py_ssize_t is commonly used in the C API. * PyCode_GetNumFree() doesn't cast its argument: the replaced macro already required the exact type PyCodeObject*. * Add assertions in some functions using "CAST" macros to check the arguments type when Python is built with assertions (debug build). * Remove an outdated comment in unicodeobject.h.
* GH-95245: Move weakreflist into the pre-header. (GH-95996)Mark Shannon2022-08-161-3/+3
|
* gh-94673: Add Per-Interpreter tp_subclasses for Static Builtin Types (gh-95301)Eric Snow2022-08-051-0/+1
|
* gh-94673: Recover Weaklist Lookup Performance (gh-95544)Eric Snow2022-08-041-0/+33
| | | gh-95302 seems to have introduced a small performance regression. Here we make some minor changes to recover that lost performance.
* GH-95245: Store object values and dict pointers in single tagged pointer. ↵Mark Shannon2022-08-011-9/+34
| | | | (GH-95278)
* gh-94673: Add Per-Interpreter tp_weaklist for Static Builtin Types (#95302)Eric Snow2022-07-291-0/+6
| | | | | | | | | | | | | | | * 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-91247: Use memcpy for list and tuple repeat (#91482)Pieter Eendebak2022-07-261-0/+10
| | | | | | | * Add _Py_memory_repeat function to pycore_list * Add _Py_RefcntAdd function to pycore_object * Use the new functions in tuplerepeat, list_repeat, and list_inplace_repeat
* GH-94851: check refcnt of immortal objects after finalization (GH-95001)Kumar Aditya2022-07-251-1/+6
|
* gh-87347: Add parenthesis around macro arguments (#93915)Victor Stinner2022-06-201-4/+5
| | | Add unit test on Py_MEMBER_SIZE() and some other macros.
* Improve object stats (#92845)Mark Shannon2022-05-161-0/+2
| | | | | * Add incref/decref stats * Show ratios for allocation in summary
* gh-90667: Add specializations of Py_DECREF when types are known (GH-30872)Dennis Sweeney2022-04-191-1/+36
|
* bpo-47162: Add call trampoline to mitigate bad fpcasts on Emscripten (GH-32189)Christian Heimes2022-03-301-0/+27
|
* bpo-45107: Specialize `LOAD_METHOD` for instances with dict. (GH-31531)Mark Shannon2022-02-241-0/+2
|
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-40170: Remove PyHeapType_GET_MEMBERS() macro (GH-30942)Victor Stinner2022-01-271-0/+4
| | | | | | | | Remove the PyHeapType_GET_MEMBERS() macro. It was exposed in the public C API by mistake, it must only be used by Python internally. Use the PyTypeObject.tp_members member instead. Rename PyHeapType_GET_MEMBERS() to _PyHeapType_GET_MEMBERS() and move it to the internal C API.
* bpo-40170: Move _Py_GetAllocatedBlocks() to pycore_pymem.h (GH-30943)Victor Stinner2022-01-271-9/+0
| | | | | Move _Py_GetAllocatedBlocks() and _PyObject_DebugMallocStats() declarations to pycore_pymem.h. These functions are related to memory allocators, not to the PyObject structure.
* bpo-40170: Remove _Py_GetAllocatedBlocks() function (GH-30940)Victor Stinner2022-01-271-0/+9
| | | | Move _Py_GetAllocatedBlocks() and _PyObject_DebugMallocStats() private functions to the internal C API.
* bpo-40170: PyType_SUPPORTS_WEAKREFS() becomes a regular function (GH-30938)Victor Stinner2022-01-271-0/+5
| | | | | | | | Convert the PyType_SUPPORTS_WEAKREFS() macro to a regular function. It no longer access the PyTypeObject.tp_weaklistoffset member directly. Add _PyType_SUPPORTS_WEAKREFS() static inline functions, used internally by Python for best performance.
* bpo-46417: Add _PyType_GetSubclasses() function (GH-30761)Victor Stinner2022-01-211-5/+6
| | | | | | | | | | | | | | Add a new _PyType_GetSubclasses() function to get type's subclasses. _PyType_GetSubclasses(type) returns a list which holds strong refererences to subclasses. It is safer than iterating on type->tp_subclasses which yields weak references and can be modified in the loop. _PyType_GetSubclasses(type) now holds a reference to the tp_subclasses dict while creating the list of subclasses. set_collection_flag_recursive() of _abc.c now uses _PyType_GetSubclasses().
* bpo-46370: Move the static initializer for _PyRuntime to its own header ↵Eric Snow2022-01-131-0/+13
| | | | | file. (gh-30587) https://bugs.python.org/issue46370
* bpo-45947: Place dict and values pointer at fixed (negative) offset just ↵Mark Shannon2021-12-071-1/+22
| | | | | | | | | | | | | | | | | | | before GC header. (GH-29879) * Place __dict__ immediately before GC header for plain Python objects. * Fix up lazy dict creation logic to use managed dict pointers. * Manage values pointer, placing them directly before managed dict pointers. * Convert hint-based load/store attr specialization target managed dict classes. * Specialize LOAD_METHOD for managed dict objects. * Remove unsafe _PyObject_GC_Calloc function. * Remove unsafe _PyObject_GC_Malloc() function. * Add comment explaning use of Py_TPFLAGS_MANAGED_DICT.
* bpo-45340: Don't create object dictionaries unless actually needed (GH-28802)Mark Shannon2021-10-131-0/+10
| | | | | | | | | | | | | | * Never change types' cached keys. It could invalidate inline attribute objects. * Lazily create object dictionaries. * Update specialization of LOAD/STORE_ATTR. * Don't update shared keys version for deletion of value. * Update gdb support to handle instance values. * Rename SPLIT_KEYS opcodes to INSTANCE_VALUE.
* [codemod] Fix non-matching bracket pairs (GH-28473)Mohamad Mansour2021-09-211-1/+1
| | | | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-44821: Eagerly assign __dict__ for new objects. (GH-27589)Mark Shannon2021-08-041-0/+2
|
* bpo-44531: Add _PyType_AllocNoTrack() function (GH-26947)Victor Stinner2021-07-011-0/+2
| | | | | | | | | | | | Add an internal _PyType_AllocNoTrack() function to allocate an object without tracking it in the GC. Modify dict_new() to use _PyType_AllocNoTrack(): dict subclasses are now only tracked once all PyDictObject members are initialized. Calling _PyObject_GC_UNTRACK() is no longer needed for the dict type. Similar change in tuple_subtype_new() for tuple subclasses. Replace tuple_gc_track() with _PyObject_GC_TRACK().
* bpo-43770: Refactor PyType_Ready() function (GH-25336)Victor Stinner2021-04-111-0/+4
| | | | | | * Split PyType_Ready() into sub-functions. * type_ready_mro() now checks if bases are static types earlier. * Check tp_name earlier, in type_ready_checks(). * Add _PyType_IsReady() macro to check if a type is ready.
* bpo-43268: Replace _PyThreadState_GET() with _PyInterpreterState_GET() ↵Victor Stinner2021-02-191-5/+5
| | | | | | | | | | | (GH-24576) Replace _PyThreadState_GET() with _PyInterpreterState_GET() in functions which only need the current interpreter, but don't need the current Python thread state. Replace also _PyThreadState_UncheckedGet() with _PyThreadState_GET() in faulthandler.c, since _PyThreadState_UncheckedGet() is just an alias to _PyThreadState_GET() in practice.
* bpo-42979: Enhance abstract.c assertions checking slot result (GH-24352)Victor Stinner2021-01-271-0/+6
| | | | | | | | * bpo-42979: Enhance abstract.c assertions checking slot result Add _Py_CheckSlotResult() function which fails with a fatal error if a slot function succeeded with an exception set or failed with no exception set: write the slot name, the type name and the current exception (if an exception is set).
* bpo-42745: Make the type cache per-interpreter (GH-23947)Victor Stinner2020-12-261-0/+3
| | | | | | | | | | | Make the type attribute lookup cache per-interpreter. Add private _PyType_InitCache() function, called by PyInterpreterState_New(). Continue to share next_version_tag between interpreters, since static types are still shared by interpreters. Remove MCACHE macro: the cache is no longer disabled if the EXPERIMENTAL_ISOLATED_SUBINTERPRETERS macro is defined.
* bpo-35059: Enhance _PyObject_GC_TRACK() macros (GH-20931)Victor Stinner2020-06-171-14/+34
| | | | | * Rename _PyObject_GC_TRACK_impl() to _PyObject_GC_TRACK() * Rename _PyObject_GC_UNTRACK_impl() to _PyObject_GC_UNTRACK() * Omit filename and lineno parameters if NDEBUG is defined.
* bpo-40989: Make _PyTraceMalloc_NewReference() internal (GH-20915)Victor Stinner2020-06-161-0/+6
| | | | Make the _PyTraceMalloc_NewReference() function fully internal: remove it from the public C API and don't export it anymore.
* bpo-40989: PyObject_INIT() becomes an alias to PyObject_Init() (GH-20901)Victor Stinner2020-06-151-6/+31
| | | | | | | | | | | | | | The PyObject_INIT() and PyObject_INIT_VAR() macros become aliases to, respectively, PyObject_Init() and PyObject_InitVar() functions. Rename _PyObject_INIT() and _PyObject_INIT_VAR() static inline functions to, respectively, _PyObject_Init() and _PyObject_InitVar(), and move them to pycore_object.h. Remove their return value: their return type becomes void. The _datetime module is now built with the Py_BUILD_CORE_MODULE macro defined. Remove an outdated comment on _Py_tracemalloc_config.
* bpo-40170: Convert PyObject_IS_GC() macro to a function (GH-19464)Hai Shi2020-04-141-0/+9
|
* bpo-40268: Include explicitly pycore_interp.h (GH-19505)Victor Stinner2020-04-141-1/+3
| | | | pycore_pystate.h no longer includes pycore_interp.h: it's now included explicitly in files accessing PyInterpreterState.