Skip to content

Commit 9b5ecd6

Browse files
Update structseq and whatsnew
1 parent 88616bb commit 9b5ecd6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Doc/whatsnew/3.8.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,20 @@ Build and C API Changes
347347

348348
(Contributed by Antoine Pitrou in :issue:`32430`.)
349349

350+
* Heap-allocated Types will now incref through :c:func:`PyObject_Init` (and
351+
its parallel macro PyObject_INIT) instead of :c:func:`PyType_GenericAlloc`.
352+
353+
All instance allocation C APIs that call
354+
:c:func:`PyObject_Init` will incref the Type accordingly. This
355+
includes: :c:func:`PyObject_New`, :c:func:`PyObject_NewVar`,
356+
:c:func:`PyObject_GC_New`, :c:func:`PyObject_GC_NewVar`, and all their
357+
corresponding macros.
358+
359+
To prevent leaks tp_dealloc has be updated to decref the Type if it's not
360+
already doing so.
361+
362+
(Contributed by Eddie Elizondo in :issue:`35810`.)
363+
350364

351365
Deprecated
352366
==========

Modules/_curses_panel.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo)
250250
static void
251251
PyCursesPanel_Dealloc(PyCursesPanelObject *po)
252252
{
253-
PyObject *tp = (PyObject *) Py_TYPE(po);
254-
PyObject *obj = (PyObject *) panel_userptr(po->pan);
253+
PyObject *tp, *obj;
254+
255+
tp = (PyObject *) Py_TYPE(po);
256+
obj = (PyObject *) panel_userptr(po->pan);
255257
if (obj) {
256258
(void)set_panel_userptr(po->pan, NULL);
257259
Py_DECREF(obj);

Objects/structseq.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@ static void
6262
structseq_dealloc(PyStructSequence *obj)
6363
{
6464
Py_ssize_t i, size;
65+
PyTypeObject *tp;
6566

67+
tp = (PyTypeObject *) Py_TYPE(obj);
6668
size = REAL_SIZE(obj);
6769
for (i = 0; i < size; ++i) {
6870
Py_XDECREF(obj->ob_item[i]);
6971
}
7072
PyObject_GC_Del(obj);
73+
if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) {
74+
Py_DECREF(tp);
75+
}
7176
}
7277

7378
/*[clinic input]

0 commit comments

Comments
 (0)