8000 bpo-37879: Suppress subtype_dealloc decref when base type is a C heap type by eduardo-elizondo · Pull Request #15323 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-37879: Suppress subtype_dealloc decref when base type is a C heap type #15323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 11, 2019
Prev Previous commit
Next Next commit
Add docstrings to C classes
This is mainly to make the intention clearer to readers of the code:
the docstrings serve as headings.
  • Loading branch information
encukou committed Sep 10, 2019
commit f4258a1bf71951133a0a72e70fce9d21acb6f40d
21 changes: 21 additions & 0 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6001,6 +6001,10 @@ static PyTypeObject MethodDescriptor2_Type = {
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | _Py_TPFLAGS_HAVE_VECTORCALL,
};

PyDoc_STRVAR(heapgctype__doc__,
"A heap type with GC, and with overridden dealloc.\n\n"
"The 'value' attribute is set to 10 in __init__.");

typedef struct {
PyObject_HEAD
int value;
Expand Down Expand Up @@ -6031,6 +6035,7 @@ static PyType_Slot HeapGcCType_slots[] = {
{Py_tp_init, heapctype_init},
{Py_tp_members, heapctype_members},
{Py_tp_dealloc, heapgcctype_dealloc},
{Py_tp_doc, heapgctype__doc__},
{0, 0},
};

Expand All @@ -6042,6 +6047,10 @@ static PyType_Spec HeapGcCType_spec = {
HeapGcCType_slots
};

PyDoc_STRVAR(heapctype__doc__,
"A heap type without GC, but with overridden dealloc.\n\n"
"The 'value' attribute is set to 10 in __init__.");

static void
heapctype_dealloc(HeapCTypeObject *self)
{
Expand All @@ -6054,6 +6063,7 @@ static PyType_Slot HeapCType_slots[] = {
{Py_tp_init, heapctype_init},
{Py_tp_members, heapctype_members},
{Py_tp_dealloc, heapctype_dealloc},
{Py_tp_doc, heapctype__doc__},
{0, 0},
};

Expand All @@ -6065,6 +6075,10 @@ static PyType_Spec HeapCType_spec = {
HeapCType_slots
};

PyDoc_STRVAR(heapctypesubclass__doc__,
"Subclass of HeapCType, without GC.\n\n"
"__init__ sets the 'value' attribute to 10 and 'value2' to 20.");

typedef struct {
HeapCTypeObject base;
int value2;
Expand All @@ -6090,6 +6104,7 @@ static struct PyMemberDef heapctypesubclass_members[] = {
static PyType_Slot HeapCTypeSubclass_slots[] = {
{Py_tp_init, heapctypesubclass_init},
{Py_tp_members, heapctypesubclass_members},
{Py_tp_doc, heapctypesubclass__doc__},
{0, 0},
};

Expand All @@ -6101,6 +6116,11 @@ static PyType_Spec HeapCTypeSubclass_spec = {
HeapCTypeSubclass_slots
};

PyDoc_STRVAR(heapctypesubclasswithfinalizer__doc__,
"Subclass of HeapCType with a finalizer that reassigns __class__.\n\n"
"__class__ is set to plain HeapCTypeSubclass during finalization.\n"
"__init__ sets the 'value' attribute to 10 and 'value2' to 20.");

static int
heapctypesubclasswithfinalizer_init(PyObject *self, PyObject *args, PyObject *kwargs)
{
Expand Down Expand Up @@ -6152,6 +6172,7 @@ static PyType_Slot HeapCTypeSubclassWithFinalizer_slots[] = {
{Py_tp_init, heapctypesubclasswithfinalizer_init},
{Py_tp_members, heapctypesubclass_members},
{Py_tp_finalize, heapctypesubclasswithfinalizer_finalize},
{Py_tp_doc, heapctypesubclasswithfinalizer__doc__},
{0, 0},
};

Expand Down
0