Warning, file /jana2/src/python/externals/pybind11-2.10.3/include/pybind11/detail/class.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #pragma once
0011
0012 #include "../attr.h"
0013 #include "../options.h"
0014
0015 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
0016 PYBIND11_NAMESPACE_BEGIN(detail)
0017
0018 #if !defined(PYPY_VERSION)
0019 # define PYBIND11_BUILTIN_QUALNAME
0020 # define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj)
0021 #else
0022
0023
0024 # define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj) \
0025 setattr((PyObject *) obj, "__qualname__", nameobj)
0026 #endif
0027
0028 inline std::string get_fully_qualified_tp_name(PyTypeObject *type) {
0029 #if !defined(PYPY_VERSION)
0030 return type->tp_name;
0031 #else
0032 auto module_name = handle((PyObject *) type).attr("__module__").cast<std::string>();
0033 if (module_name == PYBIND11_BUILTINS_MODULE)
0034 return type->tp_name;
0035 else
0036 return std::move(module_name) + "." + type->tp_name;
0037 #endif
0038 }
0039
0040 inline PyTypeObject *type_incref(PyTypeObject *type) {
0041 Py_INCREF(type);
0042 return type;
0043 }
0044
0045 #if !defined(PYPY_VERSION)
0046
0047
0048 extern "C" inline PyObject *pybind11_static_get(PyObject *self, PyObject * , PyObject *cls) {
0049 return PyProperty_Type.tp_descr_get(self, cls, cls);
0050 }
0051
0052
0053 extern "C" inline int pybind11_static_set(PyObject *self, PyObject *obj, PyObject *value) {
0054 PyObject *cls = PyType_Check(obj) ? obj : (PyObject *) Py_TYPE(obj);
0055 return PyProperty_Type.tp_descr_set(self, cls, value);
0056 }
0057
0058
0059 inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type);
0060
0061
0062
0063
0064 inline PyTypeObject *make_static_property_type() {
0065 constexpr auto *name = "pybind11_static_property";
0066 auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name));
0067
0068
0069
0070
0071
0072 auto *heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0);
0073 if (!heap_type) {
0074 pybind11_fail("make_static_property_type(): error allocating type!");
0075 }
0076
0077 heap_type->ht_name = name_obj.inc_ref().ptr();
0078 # ifdef PYBIND11_BUILTIN_QUALNAME
0079 heap_type->ht_qualname = name_obj.inc_ref().ptr();
0080 # endif
0081
0082 auto *type = &heap_type->ht_type;
0083 type->tp_name = name;
0084 type->tp_base = type_incref(&PyProperty_Type);
0085 type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
0086 type->tp_descr_get = pybind11_static_get;
0087 type->tp_descr_set = pybind11_static_set;
0088
0089 if (PyType_Ready(type) < 0) {
0090 pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
0091 }
0092
0093 # if PY_VERSION_HEX >= 0x030C0000
0094
0095
0096
0097 enable_dynamic_attributes(heap_type);
0098 # endif
0099
0100 setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
0101 PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
0102
0103 return type;
0104 }
0105
0106 #else
0107
0108
0109
0110
0111 inline PyTypeObject *make_static_property_type() {
0112 auto d = dict();
0113 PyObject *result = PyRun_String(R"(\
0114 class pybind11_static_property(property):
0115 def __get__(self, obj, cls):
0116 return property.__get__(self, cls, cls)
0117
0118 def __set__(self, obj, value):
0119 cls = obj if isinstance(obj, type) else type(obj)
0120 property.__set__(self, cls, value)
0121 )",
0122 Py_file_input,
0123 d.ptr(),
0124 d.ptr());
0125 if (result == nullptr)
0126 throw error_already_set();
0127 Py_DECREF(result);
0128 return (PyTypeObject *) d["pybind11_static_property"].cast<object>().release().ptr();
0129 }
0130
0131 #endif
0132
0133
0134
0135
0136
0137 extern "C" inline int pybind11_meta_setattro(PyObject *obj, PyObject *name, PyObject *value) {
0138
0139
0140 PyObject *descr = _PyType_Lookup((PyTypeObject *) obj, name);
0141
0142
0143
0144
0145
0146 auto *const static_prop = (PyObject *) get_internals().static_property_type;
0147 const auto call_descr_set = (descr != nullptr) && (value != nullptr)
0148 && (PyObject_IsInstance(descr, static_prop) != 0)
0149 && (PyObject_IsInstance(value, static_prop) == 0);
0150 if (call_descr_set) {
0151
0152 #if !defined(PYPY_VERSION)
0153 return Py_TYPE(descr)->tp_descr_set(descr, obj, value);
0154 #else
0155 if (PyObject *result = PyObject_CallMethod(descr, "__set__", "OO", obj, value)) {
0156 Py_DECREF(result);
0157 return 0;
0158 } else {
0159 return -1;
0160 }
0161 #endif
0162 } else {
0163
0164 return PyType_Type.tp_setattro(obj, name, value);
0165 }
0166 }
0167
0168
0169
0170
0171
0172
0173
0174 extern "C" inline PyObject *pybind11_meta_getattro(PyObject *obj, PyObject *name) {
0175 PyObject *descr = _PyType_Lookup((PyTypeObject *) obj, name);
0176 if (descr && PyInstanceMethod_Check(descr)) {
0177 Py_INCREF(descr);
0178 return descr;
0179 }
0180 return PyType_Type.tp_getattro(obj, name);
0181 }
0182
0183
0184 extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, PyObject *kwargs) {
0185
0186
0187 PyObject *self = PyType_Type.tp_call(type, args, kwargs);
0188 if (self == nullptr) {
0189 return nullptr;
0190 }
0191
0192
0193 auto *instance = reinterpret_cast<detail::instance *>(self);
0194
0195
0196 for (const auto &vh : values_and_holders(instance)) {
0197 if (!vh.holder_constructed()) {
0198 PyErr_Format(PyExc_TypeError,
0199 "%.200s.__init__() must be called when overriding __init__",
0200 get_fully_qualified_tp_name(vh.type->type).c_str());
0201 Py_DECREF(self);
0202 return nullptr;
0203 }
0204 }
0205
0206 return self;
0207 }
0208
0209
0210 extern "C" inline void pybind11_meta_dealloc(PyObject *obj) {
0211 auto *type = (PyTypeObject *) obj;
0212 auto &internals = get_internals();
0213
0214
0215
0216
0217 auto found_type = internals.registered_types_py.find(type);
0218 if (found_type != internals.registered_types_py.end() && found_type->second.size() == 1
0219 && found_type->second[0]->type == type) {
0220
0221 auto *tinfo = found_type->second[0];
0222 auto tindex = std::type_index(*tinfo->cpptype);
0223 internals.direct_conversions.erase(tindex);
0224
0225 if (tinfo->module_local) {
0226 get_local_internals().registered_types_cpp.erase(tindex);
0227 } else {
0228 internals.registered_types_cpp.erase(tindex);
0229 }
0230 internals.registered_types_py.erase(tinfo->type);
0231
0232
0233 auto &cache = internals.inactive_override_cache;
0234 for (auto it = cache.begin(), last = cache.end(); it != last;) {
0235 if (it->first == (PyObject *) tinfo->type) {
0236 it = cache.erase(it);
0237 } else {
0238 ++it;
0239 }
0240 }
0241
0242 delete tinfo;
0243 }
0244
0245 PyType_Type.tp_dealloc(obj);
0246 }
0247
0248
0249
0250
0251 inline PyTypeObject *make_default_metaclass() {
0252 constexpr auto *name = "pybind11_type";
0253 auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name));
0254
0255
0256
0257
0258
0259 auto *heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0);
0260 if (!heap_type) {
0261 pybind11_fail("make_default_metaclass(): error allocating metaclass!");
0262 }
0263
0264 heap_type->ht_name = name_obj.inc_ref().ptr();
0265 #ifdef PYBIND11_BUILTIN_QUALNAME
0266 heap_type->ht_qualname = name_obj.inc_ref().ptr();
0267 #endif
0268
0269 auto *type = &heap_type->ht_type;
0270 type->tp_name = name;
0271 type->tp_base = type_incref(&PyType_Type);
0272 type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
0273
0274 type->tp_call = pybind11_meta_call;
0275
0276 type->tp_setattro = pybind11_meta_setattro;
0277 type->tp_getattro = pybind11_meta_getattro;
0278
0279 type->tp_dealloc = pybind11_meta_dealloc;
0280
0281 if (PyType_Ready(type) < 0) {
0282 pybind11_fail("make_default_metaclass(): failure in PyType_Ready()!");
0283 }
0284
0285 setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
0286 PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
0287
0288 return type;
0289 }
0290
0291
0292
0293
0294
0295 inline void traverse_offset_bases(void *valueptr,
0296 const detail::type_info *tinfo,
0297 instance *self,
0298 bool (*f)(void * , instance * )) {
0299 for (handle h : reinterpret_borrow<tuple>(tinfo->type->tp_bases)) {
0300 if (auto *parent_tinfo = get_type_info((PyTypeObject *) h.ptr())) {
0301 for (auto &c : parent_tinfo->implicit_casts) {
0302 if (c.first == tinfo->cpptype) {
0303 auto *parentptr = c.second(valueptr);
0304 if (parentptr != valueptr) {
0305 f(parentptr, self);
0306 }
0307 traverse_offset_bases(parentptr, parent_tinfo, self, f);
0308 break;
0309 }
0310 }
0311 }
0312 }
0313 }
0314
0315 inline bool register_instance_impl(void *ptr, instance *self) {
0316 get_internals().registered_instances.emplace(ptr, self);
0317 return true;
0318 }
0319 inline bool deregister_instance_impl(void *ptr, instance *self) {
0320 auto ®istered_instances = get_internals().registered_instances;
0321 auto range = registered_instances.equal_range(ptr);
0322 for (auto it = range.first; it != range.second; ++it) {
0323 if (self == it->second) {
0324 registered_instances.erase(it);
0325 return true;
0326 }
0327 }
0328 return false;
0329 }
0330
0331 inline void register_instance(instance *self, void *valptr, const type_info *tinfo) {
0332 register_instance_impl(valptr, self);
0333 if (!tinfo->simple_ancestors) {
0334 traverse_offset_bases(valptr, tinfo, self, register_instance_impl);
0335 }
0336 }
0337
0338 inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo) {
0339 bool ret = deregister_instance_impl(valptr, self);
0340 if (!tinfo->simple_ancestors) {
0341 traverse_offset_bases(valptr, tinfo, self, deregister_instance_impl);
0342 }
0343 return ret;
0344 }
0345
0346
0347
0348
0349 inline PyObject *make_new_instance(PyTypeObject *type) {
0350 #if defined(PYPY_VERSION)
0351
0352
0353 ssize_t instance_size = static_cast<ssize_t>(sizeof(instance));
0354 if (type->tp_basicsize < instance_size) {
0355 type->tp_basicsize = instance_size;
0356 }
0357 #endif
0358 PyObject *self = type->tp_alloc(type, 0);
0359 auto *inst = reinterpret_cast<instance *>(self);
0360
0361 inst->allocate_layout();
0362
0363 return self;
0364 }
0365
0366
0367
0368 extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *) {
0369 return make_new_instance(type);
0370 }
0371
0372
0373
0374
0375 extern "C" inline int pybind11_object_init(PyObject *self, PyObject *, PyObject *) {
0376 PyTypeObject *type = Py_TYPE(self);
0377 std::string msg = get_fully_qualified_tp_name(type) + ": No constructor defined!";
0378 PyErr_SetString(PyExc_TypeError, msg.c_str());
0379 return -1;
0380 }
0381
0382 inline void add_patient(PyObject *nurse, PyObject *patient) {
0383 auto &internals = get_internals();
0384 auto *instance = reinterpret_cast<detail::instance *>(nurse);
0385 instance->has_patients = true;
0386 Py_INCREF(patient);
0387 internals.patients[nurse].push_back(patient);
0388 }
0389
0390 inline void clear_patients(PyObject *self) {
0391 auto *instance = reinterpret_cast<detail::instance *>(self);
0392 auto &internals = get_internals();
0393 auto pos = internals.patients.find(self);
0394 assert(pos != internals.patients.end());
0395
0396
0397
0398 auto patients = std::move(pos->second);
0399 internals.patients.erase(pos);
0400 instance->has_patients = false;
0401 for (PyObject *&patient : patients) {
0402 Py_CLEAR(patient);
0403 }
0404 }
0405
0406
0407
0408 inline void clear_instance(PyObject *self) {
0409 auto *instance = reinterpret_cast<detail::instance *>(self);
0410
0411
0412 for (auto &v_h : values_and_holders(instance)) {
0413 if (v_h) {
0414
0415
0416
0417 if (v_h.instance_registered()
0418 && !deregister_instance(instance, v_h.value_ptr(), v_h.type)) {
0419 pybind11_fail(
0420 "pybind11_object_dealloc(): Tried to deallocate unregistered instance!");
0421 }
0422
0423 if (instance->owned || v_h.holder_constructed()) {
0424 v_h.type->dealloc(v_h);
0425 }
0426 }
0427 }
0428
0429 instance->deallocate_layout();
0430
0431 if (instance->weakrefs) {
0432 PyObject_ClearWeakRefs(self);
0433 }
0434
0435 PyObject **dict_ptr = _PyObject_GetDictPtr(self);
0436 if (dict_ptr) {
0437 Py_CLEAR(*dict_ptr);
0438 }
0439
0440 if (instance->has_patients) {
0441 clear_patients(self);
0442 }
0443 }
0444
0445
0446
0447 extern "C" inline void pybind11_object_dealloc(PyObject *self) {
0448 clear_instance(self);
0449
0450 auto *type = Py_TYPE(self);
0451 type->tp_free(self);
0452
0453 #if PY_VERSION_HEX < 0x03080000
0454
0455
0456
0457
0458 auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base;
0459 if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
0460 Py_DECREF(type);
0461 #else
0462
0463
0464 Py_DECREF(type);
0465 #endif
0466 }
0467
0468 std::string error_string();
0469
0470
0471
0472
0473 inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
0474 constexpr auto *name = "pybind11_object";
0475 auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name));
0476
0477
0478
0479
0480
0481 auto *heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0);
0482 if (!heap_type) {
0483 pybind11_fail("make_object_base_type(): error allocating type!");
0484 }
0485
0486 heap_type->ht_name = name_obj.inc_ref().ptr();
0487 #ifdef PYBIND11_BUILTIN_QUALNAME
0488 heap_type->ht_qualname = name_obj.inc_ref().ptr();
0489 #endif
0490
0491 auto *type = &heap_type->ht_type;
0492 type->tp_name = name;
0493 type->tp_base = type_incref(&PyBaseObject_Type);
0494 type->tp_basicsize = static_cast<ssize_t>(sizeof(instance));
0495 type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
0496
0497 type->tp_new = pybind11_object_new;
0498 type->tp_init = pybind11_object_init;
0499 type->tp_dealloc = pybind11_object_dealloc;
0500
0501
0502 type->tp_weaklistoffset = offsetof(instance, weakrefs);
0503
0504 if (PyType_Ready(type) < 0) {
0505 pybind11_fail("PyType_Ready failed in make_object_base_type(): " + error_string());
0506 }
0507
0508 setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
0509 PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
0510
0511 assert(!PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC));
0512 return (PyObject *) heap_type;
0513 }
0514
0515
0516 extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *arg) {
0517 PyObject *&dict = *_PyObject_GetDictPtr(self);
0518 Py_VISIT(dict);
0519
0520 #if PY_VERSION_HEX >= 0x03090000
0521 Py_VISIT(Py_TYPE(self));
0522 #endif
0523 return 0;
0524 }
0525
0526
0527 extern "C" inline int pybind11_clear(PyObject *self) {
0528 PyObject *&dict = *_PyObject_GetDictPtr(self);
0529 Py_CLEAR(dict);
0530 return 0;
0531 }
0532
0533
0534 inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
0535 auto *type = &heap_type->ht_type;
0536 type->tp_flags |= Py_TPFLAGS_HAVE_GC;
0537 #if PY_VERSION_HEX < 0x030B0000
0538 type->tp_dictoffset = type->tp_basicsize;
0539 type->tp_basicsize += (ssize_t) sizeof(PyObject *);
0540 #else
0541 type->tp_flags |= Py_TPFLAGS_MANAGED_DICT;
0542 #endif
0543 type->tp_traverse = pybind11_traverse;
0544 type->tp_clear = pybind11_clear;
0545
0546 static PyGetSetDef getset[] = {{
0547 #if PY_VERSION_HEX < 0x03070000
0548 const_cast<char *>("__dict__"),
0549 #else
0550 "__dict__",
0551 #endif
0552 PyObject_GenericGetDict,
0553 PyObject_GenericSetDict,
0554 nullptr,
0555 nullptr},
0556 {nullptr, nullptr, nullptr, nullptr, nullptr}};
0557 type->tp_getset = getset;
0558 }
0559
0560
0561 extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int flags) {
0562
0563 type_info *tinfo = nullptr;
0564 for (auto type : reinterpret_borrow<tuple>(Py_TYPE(obj)->tp_mro)) {
0565 tinfo = get_type_info((PyTypeObject *) type.ptr());
0566 if (tinfo && tinfo->get_buffer) {
0567 break;
0568 }
0569 }
0570 if (view == nullptr || !tinfo || !tinfo->get_buffer) {
0571 if (view) {
0572 view->obj = nullptr;
0573 }
0574 PyErr_SetString(PyExc_BufferError, "pybind11_getbuffer(): Internal error");
0575 return -1;
0576 }
0577 std::memset(view, 0, sizeof(Py_buffer));
0578 buffer_info *info = tinfo->get_buffer(obj, tinfo->get_buffer_data);
0579 if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE && info->readonly) {
0580 delete info;
0581
0582 PyErr_SetString(PyExc_BufferError, "Writable buffer requested for readonly storage");
0583 return -1;
0584 }
0585 view->obj = obj;
0586 view->ndim = 1;
0587 view->internal = info;
0588 view->buf = info->ptr;
0589 view->itemsize = info->itemsize;
0590 view->len = view->itemsize;
0591 for (auto s : info->shape) {
0592 view->len *= s;
0593 }
0594 view->readonly = static_cast<int>(info->readonly);
0595 if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) {
0596 view->format = const_cast<char *>(info->format.c_str());
0597 }
0598 if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
0599 view->ndim = (int) info->ndim;
0600 view->strides = info->strides.data();
0601 view->shape = info->shape.data();
0602 }
0603 Py_INCREF(view->obj);
0604 return 0;
0605 }
0606
0607
0608 extern "C" inline void pybind11_releasebuffer(PyObject *, Py_buffer *view) {
0609 delete (buffer_info *) view->internal;
0610 }
0611
0612
0613 inline void enable_buffer_protocol(PyHeapTypeObject *heap_type) {
0614 heap_type->ht_type.tp_as_buffer = &heap_type->as_buffer;
0615
0616 heap_type->as_buffer.bf_getbuffer = pybind11_getbuffer;
0617 heap_type->as_buffer.bf_releasebuffer = pybind11_releasebuffer;
0618 }
0619
0620
0621
0622 inline PyObject *make_new_python_type(const type_record &rec) {
0623 auto name = reinterpret_steal<object>(PYBIND11_FROM_STRING(rec.name));
0624
0625 auto qualname = name;
0626 if (rec.scope && !PyModule_Check(rec.scope.ptr()) && hasattr(rec.scope, "__qualname__")) {
0627 qualname = reinterpret_steal<object>(
0628 PyUnicode_FromFormat("%U.%U", rec.scope.attr("__qualname__").ptr(), name.ptr()));
0629 }
0630
0631 object module_;
0632 if (rec.scope) {
0633 if (hasattr(rec.scope, "__module__")) {
0634 module_ = rec.scope.attr("__module__");
0635 } else if (hasattr(rec.scope, "__name__")) {
0636 module_ = rec.scope.attr("__name__");
0637 }
0638 }
0639
0640 const auto *full_name = c_str(
0641 #if !defined(PYPY_VERSION)
0642 module_ ? str(module_).cast<std::string>() + "." + rec.name :
0643 #endif
0644 rec.name);
0645
0646 char *tp_doc = nullptr;
0647 if (rec.doc && options::show_user_defined_docstrings()) {
0648
0649
0650 size_t size = std::strlen(rec.doc) + 1;
0651 tp_doc = (char *) PyObject_MALLOC(size);
0652 std::memcpy((void *) tp_doc, rec.doc, size);
0653 }
0654
0655 auto &internals = get_internals();
0656 auto bases = tuple(rec.bases);
0657 auto *base = (bases.empty()) ? internals.instance_base : bases[0].ptr();
0658
0659
0660
0661
0662
0663 auto *metaclass
0664 = rec.metaclass.ptr() ? (PyTypeObject *) rec.metaclass.ptr() : internals.default_metaclass;
0665
0666 auto *heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0);
0667 if (!heap_type) {
0668 pybind11_fail(std::string(rec.name) + ": Unable to create type object!");
0669 }
0670
0671 heap_type->ht_name = name.release().ptr();
0672 #ifdef PYBIND11_BUILTIN_QUALNAME
0673 heap_type->ht_qualname = qualname.inc_ref().ptr();
0674 #endif
0675
0676 auto *type = &heap_type->ht_type;
0677 type->tp_name = full_name;
0678 type->tp_doc = tp_doc;
0679 type->tp_base = type_incref((PyTypeObject *) base);
0680 type->tp_basicsize = static_cast<ssize_t>(sizeof(instance));
0681 if (!bases.empty()) {
0682 type->tp_bases = bases.release().ptr();
0683 }
0684
0685
0686 type->tp_init = pybind11_object_init;
0687
0688
0689 type->tp_as_number = &heap_type->as_number;
0690 type->tp_as_sequence = &heap_type->as_sequence;
0691 type->tp_as_mapping = &heap_type->as_mapping;
0692 type->tp_as_async = &heap_type->as_async;
0693
0694
0695 type->tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE;
0696 if (!rec.is_final) {
0697 type->tp_flags |= Py_TPFLAGS_BASETYPE;
0698 }
0699
0700 if (rec.dynamic_attr) {
0701 enable_dynamic_attributes(heap_type);
0702 }
0703
0704 if (rec.buffer_protocol) {
0705 enable_buffer_protocol(heap_type);
0706 }
0707
0708 if (rec.custom_type_setup_callback) {
0709 rec.custom_type_setup_callback(heap_type);
0710 }
0711
0712 if (PyType_Ready(type) < 0) {
0713 pybind11_fail(std::string(rec.name) + ": PyType_Ready failed: " + error_string());
0714 }
0715
0716 assert(!rec.dynamic_attr || PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC));
0717
0718
0719 if (rec.scope) {
0720 setattr(rec.scope, rec.name, (PyObject *) type);
0721 } else {
0722 Py_INCREF(type);
0723 }
0724
0725 if (module_) {
0726 setattr((PyObject *) type, "__module__", module_);
0727 }
0728
0729 PYBIND11_SET_OLDPY_QUALNAME(type, qualname);
0730
0731 return (PyObject *) type;
0732 }
0733
0734 PYBIND11_NAMESPACE_END(detail)
0735 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)