diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-07-27 15:55:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-27 15:55:44 (GMT) |
commit | 503a3a77c13489f909c1131d6408c2b6a0760a97 (patch) | |
tree | cc05f9c1c25464bee69dcd6434e9069adb72cfd4 /Modules | |
parent | 25086f1eed14b64b3681746569b535d70ff94b1c (diff) | |
download | cpython-503a3a77c13489f909c1131d6408c2b6a0760a97.zip cpython-503a3a77c13489f909c1131d6408c2b6a0760a97.tar.gz cpython-503a3a77c13489f909c1131d6408c2b6a0760a97.tar.bz2 |
[3.11] gh-95324: Emit a warning if an object doesn't call PyObject_GC_UnTrack during deallocation in debug mode (GH-95325) (#95336)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_abc.c | 1 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 1 | ||||
-rw-r--r-- | Modules/_threadmodule.c | 2 | ||||
-rw-r--r-- | Modules/gcmodule.c | 7 | ||||
-rw-r--r-- | Modules/xxlimited.c | 1 |
5 files changed, 12 insertions, 0 deletions
diff --git a/Modules/_abc.c b/Modules/_abc.c index 641d619..b22daa8 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -63,6 +63,7 @@ abc_data_clear(_abc_data *self) static void abc_data_dealloc(_abc_data *self) { + PyObject_GC_UnTrack(self); PyTypeObject *tp = Py_TYPE(self); (void)abc_data_clear(self); tp->tp_free(self); diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index c7234fb..13ed8b7 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -279,6 +279,7 @@ PyCField_clear(CFieldObject *self) static void PyCField_dealloc(PyObject *self) { + PyObject_GC_UnTrack(self); PyCField_clear((CFieldObject *)self); Py_TYPE(self)->tp_free((PyObject *)self); } diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index ace0282..4ac90dc 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -57,6 +57,7 @@ lock_traverse(lockobject *self, visitproc visit, void *arg) static void lock_dealloc(lockobject *self) { + PyObject_GC_UnTrack(self); if (self->in_weakreflist != NULL) { PyObject_ClearWeakRefs((PyObject *) self); } @@ -333,6 +334,7 @@ rlock_traverse(rlockobject *self, visitproc visit, void *arg) static void rlock_dealloc(rlockobject *self) { + PyObject_GC_UnTrack(self); if (self->in_weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *) self); /* self->rlock_lock can be NULL if PyThread_allocate_lock() failed diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 3bda6e4..dcd46fe 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -2347,6 +2347,13 @@ PyObject_GC_Del(void *op) size_t presize = _PyType_PreHeaderSize(((PyObject *)op)->ob_type); PyGC_Head *g = AS_GC(op); if (_PyObject_GC_IS_TRACKED(op)) { +#ifdef Py_DEBUG + if (PyErr_WarnExplicitFormat(PyExc_ResourceWarning, "gc", 0, + "gc", NULL, "Object of type %s is not untracked before destruction", + ((PyObject*)op)->ob_type->tp_name)) { + PyErr_WriteUnraisable(NULL); + } +#endif gc_list_remove(g); } GCState *gcstate = get_gc_state(); diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c index 5177ecd..e234504 100644 --- a/Modules/xxlimited.c +++ b/Modules/xxlimited.c @@ -138,6 +138,7 @@ Xxo_finalize(PyObject *self_obj) static void Xxo_dealloc(PyObject *self) { + PyObject_GC_UnTrack(self); Xxo_finalize(self); PyTypeObject *tp = Py_TYPE(self); freefunc free = PyType_GetSlot(tp, Py_tp_free); |