diff options
author | Victor Stinner <vstinner@python.org> | 2021-07-01 00:30:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-01 00:30:46 (GMT) |
commit | 818628c2da99ba0376313971816d472c65c9a9fc (patch) | |
tree | 60d50461785e6ddc16f35a047ece9dc83890eef8 /Objects/typeobject.c | |
parent | 1b28187a0e3e914ee48de8032cbba0a965dd5563 (diff) | |
download | cpython-818628c2da99ba0376313971816d472c65c9a9fc.zip cpython-818628c2da99ba0376313971816d472c65c9a9fc.tar.gz cpython-818628c2da99ba0376313971816d472c65c9a9fc.tar.bz2 |
bpo-44531: Add _PyType_AllocNoTrack() function (GH-26947)
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().
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 8ee4e81..116ac14 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1164,7 +1164,7 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) } PyObject * -PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) +_PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems) { PyObject *obj; const size_t size = _PyObject_VAR_SIZE(type, nitems+1); @@ -1189,6 +1189,16 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) else { _PyObject_InitVar((PyVarObject *)obj, type, nitems); } + return obj; +} + +PyObject * +PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) +{ + PyObject *obj = _PyType_AllocNoTrack(type, nitems); + if (obj == NULL) { + return NULL; + } if (_PyType_IS_GC(type)) { _PyObject_GC_TRACK(obj); |