Skip to content

Commit

Permalink
V-tables track lifetime of the generic type instantiation
Browse files Browse the repository at this point in the history
Summary: This gets rid of 3 of the hooks that we use in static Python. These are used to visit/free the type parameters for generic types. We know track the lifetime of these via the v-table, which means we need to eagerly initialize v-tables for generic instantiations.

Reviewed By: alexmalyshev

Differential Revision: D59879504

fbshipit-source-id: 2513246889f9c5d94f63882e6691bee39be048af
  • Loading branch information
DinoV authored and facebook-github-bot committed Jul 26, 2024
1 parent f0cf0cf commit a899b62
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4553,6 +4553,10 @@ type_dealloc(PyTypeObject *type)
Py_XDECREF(type->tp_mro);
Py_XDECREF(type->tp_cache);
Py_XDECREF(type->tp_subclasses);
/* A type's tp_doc is heap allocated, unlike the tp_doc slots
* of most other objects. It's okay to cast it to char *.
*/
PyObject_Free((char *)type->tp_doc);
Py_XDECREF(et->ht_name);
Py_XDECREF(et->ht_qualname);
Py_XDECREF(et->ht_slots);
Expand All @@ -4561,13 +4565,6 @@ type_dealloc(PyTypeObject *type)
}
Py_XDECREF(et->ht_module);

if (!(Ci_hook_type_dealloc && Ci_hook_type_dealloc(type))) {
/* A type's tp_doc is heap allocated, unlike the tp_doc slots
* of most other objects. It's okay to cast it to char *.
*/
PyObject_Free((char *)type->tp_doc);
}

Py_TYPE(type)->tp_free((PyObject *)type);
}

Expand Down Expand Up @@ -4761,10 +4758,6 @@ type_traverse(PyTypeObject *type, visitproc visit, void *arg)
((PyHeapTypeObject *)type)->ht_slots, because they can't be involved
in cycles; tp_subclasses is a list of weak references,
and slots is a tuple of strings. */

if (Ci_hook_type_traverse) {
Ci_hook_type_traverse(type, visit, arg);
}
return 0;
}

Expand Down Expand Up @@ -4818,10 +4811,6 @@ type_clear(PyTypeObject *type)

Py_CLEAR(type->tp_mro);

if (Ci_hook_type_clear) {
Ci_hook_type_clear(type);
}

return 0;
}

Expand Down

0 comments on commit a899b62

Please sign in to comment.