summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-112125: Fix None.__ne__(None) returning NotImplemented instead of ↵Victor Stinner2023-12-071-1/+1
| | | | | | | | | … (#112827) gh-112125: Fix None.__ne__(None) returning NotImplemented instead of False (#112504) (cherry picked from commit 9c3458e05865093dd55d7608810a9d0ef0765978) Co-authored-by: andrewluotechnologies <44252973+andrewluotechnologies@users.noreply.github.com>
* [3.12] gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters ↵Eric Snow2023-08-161-20/+53
| | | | | | | | | | | (#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-32/+19
| | | | | | | 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-19/+32
| | | | | | | | | | (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-101524: Only Use Public C-API in the _xxsubinterpreters Module ↵Miss Islington (bot)2023-07-271-1/+1
| | | | | | | | (gh-105258) (gh-107303) 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. (cherry picked from commit e6373c0d8b59512aa7f0dea7f3fb162b6ed10fa4) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.12] gh-102304: Rename _Py_IncRefTotal_DO_NOT_USE_THIS() (GH-107193) (#107199)Miss Islington (bot)2023-07-241-2/+2
| | | | | | | | | | gh-102304: Rename _Py_IncRefTotal_DO_NOT_USE_THIS() (GH-107193) * 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 (cherry picked from commit 8ebc9fc321ba1eeb3282c2170f351c54956893e6) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.12] gh-105340: include hidden fast-locals in locals() (GH-105715) (#106470)Miss Islington (bot)2023-07-051-3/+4
| | | | | | | | gh-105340: include hidden fast-locals in locals() (GH-105715) * gh-105340: include hidden fast-locals in locals() (cherry picked from commit 104d7b760fed18055e4f04e5da3ca619e28bfc81) Co-authored-by: Carl Meyer <carl@oddbird.net>
* 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
* gh-102213: Revert "gh-102213: Optimize the performance of `__getattr__` ↵Nikita Sobolev2023-04-071-6/+0
| | | | | (GH-102248)" (GH-103332) This reverts commit aa0a73d1bc53dcb6348a869df1e775138991e561.
* gh-102304: Move the Total Refcount to PyInterpreterState (gh-102545)Eric Snow2023-03-211-22/+57
| | | | | 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-25/+76
| | | | | | | 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/+6
| | | | 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-11/+68
| | | | | 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-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives ↵Irit Katriel2023-03-081-15/+10
| | | | (in Objects/) (#102218)
* gh-101430: Update tracemalloc to handle presize properly. (gh-101745)Dong-hee Na2023-02-091-7/+2
|
* GH-101578: Normalize the current exception (GH-101607)Mark Shannon2023-02-081-6/+6
| | | | | | | | | | * Make sure that the current exception is always normalized. * Remove redundant type and traceback fields for the current exception. * Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException * Add new API functions: PyException_GetArgs, PyException_SetArgs
* gh-59956: Allow the "Trashcan" Mechanism to Work Without a Thread State ↵Eric Snow2023-01-231-21/+66
| | | | | | | | | | | | (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-92216: improve performance of `hasattr` for type objects (GH-99979)Pieter Eendebak2022-12-231-1/+9
|
* gh-99540: Constant hash for _PyNone_Type to aid reproducibility (GH-99541)yonillasky2022-12-161-1/+6
| | | Needed for ASLR builds of Python.
* gh-99845: Clean up _PyObject_VAR_SIZE() usage (#99847)Victor Stinner2022-11-291-5/+8
| | | | | | * code_sizeof() now uses an unsigned type (size_t) to compute the result. * Fix _PyObject_ComputedDictPointer(): cast _PyObject_VAR_SIZE() to Py_ssize_t, rather than long: it's a different type on 64-bit Windows. * Clarify that _PyObject_VAR_SIZE() uses an unsigned type (size_t).
* gh-81057: Move Globals in Core Code to _PyRuntimeState (gh-99496)Eric Snow2022-11-151-1/+1
| | | | | This is the first of several changes to consolidate non-object globals in core code. https://github.com/python/cpython/issues/81057
* gh-99300: Use Py_NewRef() in Objects/ directory (#99354)Victor Stinner2022-11-101-10/+5
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
* gh-98421: Clean Up PyObject_Print (GH-98422)MonadChains2022-10-201-17/+8
| | | | | Work on test coverage for `PyObject_Print` made it clear that some lines can't get executed. Simplify the function by excluding the checks for non-string types. Also eliminate creating a temporary bytes object.
* gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict ↵philg3142022-09-081-0/+2
| | | | (#96353)
* GH-90699: use statically allocated interned strings in typeobject's slotdefs ↵Kumar Aditya2022-09-071-18/+0
| | | | (GH-94706)
* GH-95707: Fix uses of `Py_TPFLAGS_MANAGED_DICT` (GH-95854)Mark Shannon2022-08-151-0/+1
| | | | | | * Make sure that tp_dictoffset is correct with Py_TPFLAGS_MANAGED_DICT is set. * Avoid traversing managed dict twice when subclassing class with Py_TPFLAGS_MANAGED_DICT set.
* GH-92678: Document that you shouldn't be doing your own dictionary offset ↵Mark Shannon2022-08-091-1/+5
| | | | | | calculations. (GH-95598) Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
* GH-95245: Store object values and dict pointers in single tagged pointer. ↵Mark Shannon2022-08-011-78/+90
| | | | (GH-95278)
* gh-94673: Add _PyStaticType_InitBuiltin() (#95152)Eric Snow2022-07-251-2/+2
| | | | | | | | | | | | This is the first of several precursors to storing tp_subclasses (and tp_weaklist) on the interpreter state for static builtin types. We do the following: * add `_PyStaticType_InitBuiltin()` * add `_Py_TPFLAGS_STATIC_BUILTIN` * set it on all static builtin types in `_PyStaticType_InitBuiltin()` * shuffle some code around to be able to use _PyStaticType_InitBuiltin() * rename `_PyStructSequence_InitType()` to `_PyStructSequence_InitBuiltinWithFlags()` * add `_PyStructSequence_InitBuiltin()`.
* gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938)Victor Stinner2022-06-191-1/+0
| | | | | | | | | | | | | | | | Move the follow functions and type from frameobject.h to pyframe.h, so the standard <Python.h> provide frame getter functions: * PyFrame_Check() * PyFrame_GetBack() * PyFrame_GetBuiltins() * PyFrame_GetGenerator() * PyFrame_GetGlobals() * PyFrame_GetLasti() * PyFrame_GetLocals() * PyFrame_Type Remove #include "frameobject.h" from many C files. It's no longer needed.
* gh-93202: Always use %zd printf formatter (#93201)Victor Stinner2022-05-251-7/+2
| | | | | | | | | | | | | | | | Python now always use the ``%zu`` and ``%zd`` printf formats to format a size_t or Py_ssize_t number. Building Python 3.12 requires a C11 compiler, so these printf formats are now always supported. * PyObject_Print() and _PyObject_Dump() now use the printf %zd format to display an object reference count. * Update PY_FORMAT_SIZE_T comment. * Remove outdated notes about the %zd format in PyBytes_FromFormat() and PyUnicode_FromFormat() documentations. * configure no longer checks for the %zd format and no longer defines PY_FORMAT_SIZE_T macro in pyconfig.h. * pymacconfig.h no longer undefines PY_FORMAT_SIZE_T: macOS 10.4 is no longer supported. Python 3.12 now requires macOS 10.6 (Snow Leopard) or newer.
* GH-92955: fix memory leak in code object lines and positions iterators ↵Kumar Aditya2022-05-191-0/+4
| | | | (gh-92956)
* GH-92804: Fix memory leak in memoryview iterator (gh-92805)Kumar Aditya2022-05-141-0/+2
|
* gh-89653: PEP 670: Convert pycore_gc.h macros to functions (#92649)Victor Stinner2022-05-111-1/+1
| | | | | | | | | | | | | | Convert the following macros to static inline functions: * _Py_AS_GC() * _PyGCHead_FINALIZED(), _PyGCHead_SET_FINALIZED() * _PyGCHead_NEXT(), _PyGCHead_SET_NEXT() * _PyGCHead_PREV(), _PyGCHead_SET_PREV() * _PyGC_FINALIZED(), _PyGC_SET_FINALIZED() * _PyObject_GC_IS_TRACKED() * _PyObject_GC_MAY_BE_TRACKED() Add a macro wrapping the _PyObject_GC_IS_TRACKED() function to cast the argument to PyObject*.
* bpo-43857: Improve the AttributeError message when deleting a missing ↵Géry Ogam2022-05-051-4/+14
| | | | | attribute (#25424) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* Use static inline function Py_EnterRecursiveCall() (#91988)Victor Stinner2022-05-041-8/+8
| | | | | | | | | | | | | | | | Currently, calling Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() may use a function call or a static inline function call, depending if the internal pycore_ceval.h header file is included or not. Use a different name for the static inline function to ensure that the static inline function is always used in Python internals for best performance. Similar approach than PyThreadState_GET() (function call) and _PyThreadState_GET() (static inline function). * Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate() * Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate() * pycore_ceval.h: Rename Py_EnterRecursiveCall() to _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and _Py_LeaveRecursiveCall()
* gh-89373: _Py_Dealloc() checks tp_dealloc exception (#32357)Victor Stinner2022-04-211-1/+35
| | | | If Python is built in debug mode, _Py_Dealloc() now ensures that the tp_dealloc function leaves the current exception unchanged.
* gh-91632: Fix generic_alias_iterator to be finalized at exit. (GH-91727)Dong-hee Na2022-04-201-0/+2
|