summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-42519: Replace PyObject_MALLOC() with PyObject_Malloc() (GH-23587)Victor Stinner2020-12-011-2/+2
| | | | | | | | | No longer use deprecated aliases to functions: * Replace PyObject_MALLOC() with PyObject_Malloc() * Replace PyObject_REALLOC() with PyObject_Realloc() * Replace PyObject_FREE() with PyObject_Free() * Replace PyObject_Del() with PyObject_Free() * Replace PyObject_DEL() with PyObject_Free()
* bpo-40170: Hide impl detail of Py_TRASHCAN_BEGIN macro (GH-23235)Hai Shi2020-11-241-0/+9
| | | | | The Py_TRASHCAN_BEGIN macro no longer accesses PyTypeObject attributes, but now can get the condition by calling the new private _PyTrash_cond() function which hides implementation details.
* bpo-42262: Add Py_NewRef() and Py_XNewRef() (GH-23152)Victor Stinner2020-11-051-0/+16
| | | | Added Py_NewRef() and Py_XNewRef() functions to increment the reference count of an object and return the object.
* bpo-41991: Remove _PyObject_HasAttrId (GH-22629)Serhiy Storchaka2020-10-101-11/+0
| | | It can silence arbitrary exceptions.
* Fix comment about PyObject_IsTrue. (GH-22343)Stefan Pochmann2020-10-071-1/+1
| | | The `for` statement doesn't use a condition and this function, the `while` statement does.
* Fix a small grammatical mistake in a comment (GH-21526)Brett Cannon2020-07-171-1/+1
| | | Automerge-Triggered-By: @brettcannon
* bpo-40989: PyObject_INIT() becomes an alias to PyObject_Init() (GH-20901)Victor Stinner2020-06-151-7/+9
| | | | | | | | | | | | | | 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-39465: Use _PyInterpreterState_GET() (GH-20788)Victor Stinner2020-06-101-4/+4
| | | | | | | | | | | | Replace _PyThreadState_GET() with _PyInterpreterState_GET() in: * get_small_int() * gcmodule.c: add also get_gc_state() function * _PyTrash_deposit_object() * _PyTrash_destroy_chain() * warnings_get_state() * Py_GetRecursionLimit() Cleanup listnode.c: add 'parser' variable.
* bpo-40943: Replace PY_FORMAT_SIZE_T with "z" (GH-20781)Victor Stinner2020-06-101-5/+5
| | | | | | | The PEP 353, written in 2005, introduced PY_FORMAT_SIZE_T. Python no longer supports macOS 10.4 and Visual Studio 2010, but requires more recent macOS and Visual Studio versions. In 2020 with Python 3.10, it is now safe to use directly "%zu" to format size_t and "%zi" to format Py_ssize_t.
* bpo-38787: C API for module state access from extension methods (PEP 573) ↵Petr Viktorin2020-05-071-0/+1
| | | | | | | | | (GH-19936) Module C state is now accessible from C-defined heap type methods (PEP 573). Patch by Marcel Plch and Petr Viktorin. Co-authored-by: Marcel Plch <mplch@redhat.com> Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-40170: Convert PyObject_IS_GC() macro to a function (GH-19464)Hai Shi2020-04-141-2/+2
|
* bpo-40268: Move struct _gc_runtime_state to pycore_gc.h (GH-19515)Victor Stinner2020-04-141-0/+1
|
* bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner2020-04-141-2/+2
|
* bpo-40170: PyType_HasFeature() now always calls PyType_GetFlags() (GH-19378)Victor Stinner2020-04-071-5/+5
| | | | | | | | PyType_HasFeature() now always calls PyType_GetFlags() to hide implementation details. Previously, it accessed directly the PyTypeObject.tp_flags member when the limited C API was not used. Add fast inlined version _PyType_HasFeature() and _PyType_IS_GC() for object.c and typeobject.c.
* bpo-40170: PyObject_NEW() becomes an alias to PyObject_New() (GH-19379)Victor Stinner2020-04-071-4/+5
| | | | | | | | | | | | The PyObject_NEW() macro becomes an alias to the PyObject_New() macro, and the PyObject_NEW_VAR() macro becomes an alias to the PyObject_NewVar() macro, to hide implementation details. They no longer access directly the PyTypeObject.tp_basicsize member. Exclude _PyObject_SIZE() and _PyObject_VAR_SIZE() macros from the limited C API. Replace PyObject_NEW() with PyObject_New() and replace PyObject_NEW_VAR() with PyObject_NewVar().
* bpo-40170: PyObject_GET_WEAKREFS_LISTPTR() becomes a function (GH-19377)Victor Stinner2020-04-061-0/+8
| | | | | | | | Convert the PyObject_GET_WEAKREFS_LISTPTR() macro to a function to hide implementation details: the macro accessed directly to the PyTypeObject.tp_weaklistoffset member. Add _PyObject_GET_WEAKREFS_LISTPTR() static inline function to the internal C API.
* bpo-39947: Hide implementation detail of trashcan macros (GH-18971)Victor Stinner2020-03-131-0/+24
| | | | | | Py_TRASHCAN_BEGIN_CONDITION and Py_TRASHCAN_END macro no longer access PyThreadState attributes, but call new private _PyTrash_begin() and _PyTrash_end() functions which hide implementation details.
* bpo-39947: Move Py_EnterRecursiveCall() to internal C API (GH-18972)Victor Stinner2020-03-131-0/+1
| | | | | | Move the static inline function flavor of Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() to the internal C API: they access PyThreadState attributes. The limited C API provides regular functions which hide implementation details.
* bpo-39573: Use Py_IS_TYPE() macro to check for types (GH-18809)Andy Lester2020-03-061-2/+2
| | | Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-39873: Cleanup _PyObject_CheckConsistency() (GH-18807)Victor Stinner2020-03-061-1/+0
| | | | Remove redundant check on Py_TYPE() value: it's already checked inside _PyType_CheckConsistency().
* bpo-39873: PyObject_Init() uses PyObject_INIT() (GH-18804)Victor Stinner2020-03-061-9/+2
| | | | | | Avoid duplicated code: * PyObject_Init() uses PyObject_INIT() * PyObject_InitVar() uses PyObject_INIT_VAR()
* bpo-35712: Make using NotImplemented in a boolean context issue a ↵MojoVampire2020-03-031-2/+18
| | | | deprecation warning (GH-13195)
* bpo-39573: Add Py_SET_SIZE() function (GH-18400)Victor Stinner2020-02-071-1/+1
| | | Add Py_SET_SIZE() function to set the size of an object.
* bpo-39573: Use Py_TYPE() macro in object.c (GH-18398)Victor Stinner2020-02-071-12/+8
| | | | Replace direct acccess to PyVarObject.ob_size with usage of the Py_SIZE() macro.
* bpo-39573: Add Py_SET_TYPE() function (GH-18394)Victor Stinner2020-02-071-1/+1
| | | Add Py_SET_TYPE() function to set the type of an object.
* bpo-39573: Use Py_TYPE() macro in Objects directory (GH-18392)Victor Stinner2020-02-071-34/+34
| | | Replace direct access to PyObject.ob_type with Py_TYPE().
* bpo-39573: Add Py_SET_REFCNT() function (GH-18389)Victor Stinner2020-02-071-4/+5
| | | | Add a Py_SET_REFCNT() function to set the reference counter of an object.
* bpo-39573: Use Py_REFCNT() macro (GH-18388)Victor Stinner2020-02-061-18/+18
| | | | Replace direct acccess to PyObject.ob_refcnt with usage of the Py_REFCNT() macro.
* bpo-39542: Declare _Py_AddToAllObjects() in pycore_object.h (GH-18368)Victor Stinner2020-02-051-1/+1
| | | | | | _Py_AddToAllObjects() is used in bltinmodule.c and typeobject.c when Py_TRACE_REFS is defined. Fix Py_TRACE_REFS build.
* bpo-39542: Make PyObject_INIT() opaque in limited C API (GH-18363)Victor Stinner2020-02-051-4/+8
| | | | | | | | | | | | | | In the limited C API, PyObject_INIT() and PyObject_INIT_VAR() are now defined as aliases to PyObject_Init() and PyObject_InitVar() to make their implementation opaque. It avoids to leak implementation details in the limited C API. Exclude the following functions from the limited C API, move them from object.h to cpython/object.h: * _Py_NewReference() * _Py_ForgetReference() * _PyTraceMalloc_NewReference() * _Py_GetRefTotal()
* bpo-39543: Remove unused _Py_Dealloc() macro (GH-18361)Victor Stinner2020-02-051-2/+0
| | | | | | | | | | | | The macro is defined after Py_DECREF() and so is no longer used by Py_DECREF(). Moving _Py_Dealloc() macro back from cpython/object.h to object.h would require to move a lot of definitions as well: PyTypeObject and many related types used by PyTypeObject. Keep _Py_Dealloc() as an opaque function call to avoid leaking implementation details in the limited C API (object.h): remove _Py_Dealloc() macro from cpython/object.h.
* bpo-39542: Make _Py_NewReference() opaque in C API (GH-18346)Victor Stinner2020-02-051-1/+17
| | | | | | | | | | _Py_NewReference() becomes a regular opaque function, rather than a static inline function in the C API (object.h), to better hide implementation details. Move _Py_tracemalloc_config from public pymem.h to internal pycore_pymem.h header. Make _Py_AddToAllObjects() private.
* bpo-39542: Simplify _Py_NewReference() (GH-18332)Victor Stinner2020-02-031-16/+5
| | | | | | | | | * Remove _Py_INC_REFTOTAL and _Py_DEC_REFTOTAL macros: modify directly _Py_RefTotal. * _Py_ForgetReference() is no longer defined if the Py_TRACE_REFS macro is not defined. * Remove _Py_NewReference() implementation from object.c: unify the two implementations in object.h inline function. * Fix Py_TRACE_REFS build: _Py_INC_TPALLOCS() macro has been removed.
* bpo-39489: Remove COUNT_ALLOCS special build (GH-18259)Victor Stinner2020-02-031-126/+0
| | | | | | | | | | | Remove: * COUNT_ALLOCS macro * sys.getcounts() function * SHOW_ALLOC_COUNT code in listobject.c * SHOW_TRACK_COUNT code in tupleobject.c * PyConfig.show_alloc_count field * -X showalloccount command line option * @test.support.requires_type_collecting decorator
* bpo-38631: Add _Py_NO_RETURN to functions calling Py_FatalError() (GH-18278)Victor Stinner2020-01-301-3/+3
| | | | | | | | | Add _Py_NO_RETURN to functions calling Py_FatalError(): * _PyObject_AssertFailed() * dummy_dealloc() * faulthandler_fatal_error_thread() * none_dealloc() * notimplemented_dealloc()
* bpo-38631: Avoid Py_FatalError() in init_slotdefs() (GH-18263)Victor Stinner2020-01-301-0/+6
| | | | | | Rename init_slotdefs() to _PyTypes_InitSlotDefs() and add a return value of type PyStatus. The function is now called exactly once from _PyTypes_Init(). Replace calls to init_slotdefs() with an assertion checking that slotdefs is initialized.
* bpo-38631: Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() (GH-18258)Victor Stinner2020-01-301-30/+30
| | | | | | | | | | | | | | Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() in object.c and typeobject.c to also dump the involved Python object on a fatal error. It should ease debug when such fatal error occurs. If the double linked list is inconsistent, _Py_ForgetReference() no longer dumps previous and next objects in the fatal error, it now only dumps the current object. It ensures that the error message is displayed even if dumping the object does crash Python. Enhance _Py_ForgetReference() error messages; _PyObject_ASSERT_FAILED_MSG() logs the "_Py_ForgetReference" function name.
* Remove deadcode in _Py_inc_count() (GH-18257)Victor Stinner2020-01-291-2/+0
| | | | (tp->tp_next != NULL) check became redundant with commit 45294a9562e5c360ee8ef8498d8792e05a6eb25e (merged in 2006).
* bpo-36854: Move _PyRuntimeState.gc to PyInterpreterState (GH-17287)Victor Stinner2019-11-201-7/+13
| | | | | * Rename _PyGC_InitializeRuntime() to _PyGC_InitState() * finalize_interp_clear() now also calls _PyGC_Fini() in subinterpreters (clear the GC state).
* bpo-37645: add new function _PyObject_FunctionStr() (GH-14890)Jeroen Demeyer2019-11-051-0/+58
| | | | | | | | | | | | Additional note: the `method_check_args` function in `Objects/descrobject.c` is written in such a way that it applies to all kinds of descriptors. In particular, a future re-implementation of `wrapper_descriptor` could use that code. CC @vstinner @encukou https://bugs.python.org/issue37645 Automerge-Triggered-By: @encukou
* bpo-38644: Pass tstate to Py_EnterRecursiveCall() (GH-16997)Victor Stinner2019-11-041-28/+42
| | | | | | | | | | | | | * Add _Py_EnterRecursiveCall() and _Py_LeaveRecursiveCall() which require a tstate argument. * Pass tstate to _Py_MakeRecCheck() and _Py_CheckRecursiveCall(). * Convert Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() macros to static inline functions. _PyThreadState_GET() is the most efficient way to get the tstate, and so using it with _Py_EnterRecursiveCall() and _Py_LeaveRecursiveCall() should be a little bit more efficient than using Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() which use the "slower" PyThreadState_GET().
* bpo-38400 Don't check for NULL linked list pointers in _PyObject_IsFreed ↵Pablo Galindo2019-10-071-1/+4
| | | | | | | | | (GH-16630) Some objects like Py_None are not initialized with conventional means that prepare the circular linked list pointers, leaving them unlinked from the rest of the objects. For those objects, NULL pointers does not mean that they are freed, so we need to skip the check in those cases.
* bpo-36389: Add newline to _PyObject_AssertFailed() (GH-16629)Victor Stinner2019-10-071-0/+3
| | | | Add a newline between the verbose object dump and the Py_FatalError() logs for readability.
* bpo-36389: _PyObject_CheckConsistency() available in release mode (GH-16612)Victor Stinner2019-10-071-38/+33
| | | | | | | | | | | | | | | | | | | | | bpo-36389, bpo-38376: The _PyObject_CheckConsistency() function is now also available in release mode. For example, it can be used to debug a crash in the visit_decref() function of the GC. Modify the following functions to also work in release mode: * _PyDict_CheckConsistency() * _PyObject_CheckConsistency() * _PyType_CheckConsistency() * _PyUnicode_CheckConsistency() Other changes: * _PyMem_IsPtrFreed(ptr) now also returns 1 if ptr is NULL (equals to 0). * _PyBytesWriter_CheckConsistency() now returns 1 and is only used with assert(). * Reorder _PyObject_Dump() to write safe fields first, and only attempt to render repr() at the end.
* bpo-38070: Enhance _PyObject_Dump() (GH-16243)Victor Stinner2019-09-171-6/+7
| | | | _PyObject_Dump() now dumps the object address for freed objects and objects with ob_type=NULL.
* Fix typos in comments, docs and test names (#15018)Min ho Kim2019-07-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * Fix typos in comments, docs and test names * Update test_pyparse.py account for change in string length * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: Dealloccte -> Deallocate Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Update posixmodule checksum. * Reverse idlelib changes.
* bpo-37340: remove free_list for bound method objects (GH-14232)Inada Naoki2019-07-261-2/+0
|
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-5/+5
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async
* bpo-32388: Remove cross-version binary compatibility requirement in tp_flags ↵Antoine Pitrou2019-05-291-4/+1
| | | | | | | | (GH-4944) It is now allowed to add new fields at the end of the PyTypeObject struct without having to allocate a dedicated compatibility flag in tp_flags. This will reduce the risk of running out of bits in the 32-bit tp_flags value.
* bpo-36922: implement PEP-590 Py_TPFLAGS_METHOD_DESCRIPTOR (GH-13338)Jeroen Demeyer2019-05-281-2/+1
| | | Co-authored-by: Mark Shannon <mark@hotpy.org>