aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkj <28750310+Fidget-Spinner@users.noreply.github.com>2020-11-16 11:27:23 +0800
committerGitHub <noreply@github.com>2020-11-15 19:27:23 -0800
commit384b7a4bd988986bca227c7e85c32d766da74708 (patch)
treedbcb20fceb8d8e1f7e619b4007722b928c29c389 /Objects
parentMore updates to the descriptor howto guide (GH-23238) (diff)
downloadcpython-384b7a4bd988986bca227c7e85c32d766da74708.tar.gz
cpython-384b7a4bd988986bca227c7e85c32d766da74708.tar.bz2
cpython-384b7a4bd988986bca227c7e85c32d766da74708.zip
bpo-42332: Add weakref slot to types.GenericAlias (GH-23250)
Automerge-Triggered-By: GH:gvanrossum
Diffstat (limited to 'Objects')
-rw-r--r--Objects/genericaliasobject.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c
index 28ea487a44f..6102e05c165 100644
--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -10,6 +10,7 @@ typedef struct {
PyObject *origin;
PyObject *args;
PyObject *parameters;
+ PyObject* weakreflist;
} gaobject;
static void
@@ -18,6 +19,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);
@@ -599,6 +603,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,
@@ -630,6 +635,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;
}