diff options
author | kj <28750310+Fidget-Spinner@users.noreply.github.com> | 2020-11-17 22:45:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 22:45:08 (GMT) |
commit | 71ba5f52d2a80e7beffc923c54c0b6345cd0637a (patch) | |
tree | d8a107c47353ca2c875f417321172d85221247ec /Objects | |
parent | 48a9c0eb2a3304ea64d1b32fdf9db853d5d8c429 (diff) | |
download | cpython-71ba5f52d2a80e7beffc923c54c0b6345cd0637a.zip cpython-71ba5f52d2a80e7beffc923c54c0b6345cd0637a.tar.gz cpython-71ba5f52d2a80e7beffc923c54c0b6345cd0637a.tar.bz2 |
[3.9] bpo-42332: Add weakref slot to types.GenericAlias (GH-23250) (GH-23309)
(cherry picked from commit 384b7a4bd988986bca227c7e85c32d766da74708)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/genericaliasobject.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index 3e850b5..4b6c8c6 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -9,6 +9,7 @@ typedef struct { PyObject *origin; PyObject *args; PyObject *parameters; + PyObject* weakreflist; } gaobject; static void @@ -17,6 +18,9 @@ ga_dealloc(PyObject *self) gaobject *alias = (gaobject *)self; _PyObject_GC_UNTRACK(self); + if (alias->weakreflist != NULL) { + PyObject_ClearWeakRefs((PyObject *)alias); + } Py_XDECREF(alias->origin); Py_XDECREF(alias->args); Py_XDECREF(alias->parameters); @@ -593,6 +597,7 @@ PyTypeObject Py_GenericAliasType = { .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, .tp_traverse = ga_traverse, .tp_richcompare = ga_richcompare, + .tp_weaklistoffset = offsetof(gaobject, weakreflist), .tp_methods = ga_methods, .tp_members = ga_members, .tp_alloc = PyType_GenericAlloc, @@ -624,6 +629,7 @@ Py_GenericAlias(PyObject *origin, PyObject *args) alias->origin = origin; alias->args = args; alias->parameters = NULL; + alias->weakreflist = NULL; _PyObject_GC_TRACK(alias); return (PyObject *)alias; } |