summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
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/object.c
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/object.c')
-rw-r--r--Objects/object.c8
1 files changed, 5 insertions, 3 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;
}