|
14 | 14 | NAMESPACE_BEGIN(pybind11) |
15 | 15 | NAMESPACE_BEGIN(detail) |
16 | 16 |
|
| 17 | +inline PyTypeObject *type_incref(PyTypeObject *type) { |
| 18 | + Py_INCREF(type); |
| 19 | + return type; |
| 20 | +} |
| 21 | + |
17 | 22 | #if !defined(PYPY_VERSION) |
18 | 23 |
|
19 | 24 | /// `pybind11_static_property.__get__()`: Always pass the class instead of the instance. |
@@ -49,7 +54,7 @@ inline PyTypeObject *make_static_property_type() { |
49 | 54 |
|
50 | 55 | auto type = &heap_type->ht_type; |
51 | 56 | type->tp_name = name; |
52 | | - type->tp_base = &PyProperty_Type; |
| 57 | + type->tp_base = type_incref(&PyProperty_Type); |
53 | 58 | type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; |
54 | 59 | type->tp_descr_get = pybind11_static_get; |
55 | 60 | type->tp_descr_set = pybind11_static_set; |
@@ -162,7 +167,7 @@ inline PyTypeObject* make_default_metaclass() { |
162 | 167 |
|
163 | 168 | auto type = &heap_type->ht_type; |
164 | 169 | type->tp_name = name; |
165 | | - type->tp_base = &PyType_Type; |
| 170 | + type->tp_base = type_incref(&PyType_Type); |
166 | 171 | type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; |
167 | 172 |
|
168 | 173 | type->tp_setattro = pybind11_meta_setattro; |
@@ -361,7 +366,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) { |
361 | 366 |
|
362 | 367 | auto type = &heap_type->ht_type; |
363 | 368 | type->tp_name = name; |
364 | | - type->tp_base = &PyBaseObject_Type; |
| 369 | + type->tp_base = type_incref(&PyBaseObject_Type); |
365 | 370 | type->tp_basicsize = static_cast<ssize_t>(sizeof(instance)); |
366 | 371 | type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; |
367 | 372 |
|
@@ -552,7 +557,7 @@ inline PyObject* make_new_python_type(const type_record &rec) { |
552 | 557 | auto type = &heap_type->ht_type; |
553 | 558 | type->tp_name = strdup(full_name.c_str()); |
554 | 559 | type->tp_doc = tp_doc; |
555 | | - type->tp_base = (PyTypeObject *) handle(base).inc_ref().ptr(); |
| 560 | + type->tp_base = type_incref((PyTypeObject *)base); |
556 | 561 | type->tp_basicsize = static_cast<ssize_t>(sizeof(instance)); |
557 | 562 | if (bases.size() > 0) |
558 | 563 | type->tp_bases = bases.release().ptr(); |
|
0 commit comments