summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEddie Elizondo <eduardo.elizondorueda@gmail.com>2019-03-27 11:52:18 (GMT)
committerPetr Viktorin <encukou@gmail.com>2019-03-27 11:52:18 (GMT)
commit364f0b0f19cc3f0d5e63f571ec9163cf41c62958 (patch)
tree977c0c418780824cca9ef9b4d920b9d423253e84 /Objects
parent1fc5bf2ff27b898e8d9460d0fbc791e83009ed71 (diff)
downloadcpython-364f0b0f19cc3f0d5e63f571ec9163cf41c62958.zip
cpython-364f0b0f19cc3f0d5e63f571ec9163cf41c62958.tar.gz
cpython-364f0b0f19cc3f0d5e63f571ec9163cf41c62958.tar.bz2
bpo-35810: Incref heap-allocated types in PyObject_Init (GH-11661)
* Incref heap-allocated types in PyObject_Init * Add documentation and porting notes to What's New
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c8
-rw-r--r--Objects/structseq.c5
-rw-r--r--Objects/typeobject.c3
3 files changed, 10 insertions, 6 deletions
diff --git a/Objects/object.c b/Objects/object.c
index b446d59..bd44aca 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -230,6 +230,9 @@ PyObject_Init(PyObject *op, PyTypeObject *tp)
return PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
Py_TYPE(op) = tp;
+ if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) {
+ Py_INCREF(tp);
+ }
_Py_NewReference(op);
return op;
}
@@ -240,9 +243,8 @@ PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
if (op == NULL)
return (PyVarObject *) PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT_VAR */
- op->ob_size = size;
- Py_TYPE(op) = tp;
- _Py_NewReference((PyObject *)op);
+ Py_SIZE(op) = size;
+ PyObject_Init((PyObject *)op, tp);
return op;
}
diff --git a/Objects/structseq.c b/Objects/structseq.c
index cf36fa7..a5046c4 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -63,12 +63,17 @@ static void
structseq_dealloc(PyStructSequence *obj)
{
Py_ssize_t i, size;
+ PyTypeObject *tp;
+ tp = (PyTypeObject *) Py_TYPE(obj);
size = REAL_SIZE(obj);
for (i = 0; i < size; ++i) {
Py_XDECREF(obj->ob_item[i]);
}
PyObject_GC_Del(obj);
+ if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) {
+ Py_DECREF(tp);
+ }
}
/*[clinic input]
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 403f3ca..4c3909c 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -987,9 +987,6 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
memset(obj, '\0', size);
- if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
- Py_INCREF(type);
-
if (type->tp_itemsize == 0)
(void)PyObject_INIT(obj, type);
else