Give instances of this type a `__dict__` and opt into garbage collection.
| 606 | |
| 607 | /// Give instances of this type a `__dict__` and opt into garbage collection. |
| 608 | inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) { |
| 609 | auto *type = &heap_type->ht_type; |
| 610 | type->tp_flags |= Py_TPFLAGS_HAVE_GC; |
| 611 | #ifdef PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET |
| 612 | type->tp_dictoffset = type->tp_basicsize; // place dict at the end |
| 613 | type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it |
| 614 | #else |
| 615 | type->tp_flags |= Py_TPFLAGS_MANAGED_DICT; |
| 616 | #endif |
| 617 | type->tp_traverse = pybind11_traverse; |
| 618 | type->tp_clear = pybind11_clear; |
| 619 | |
| 620 | static PyGetSetDef getset[] |
| 621 | = {{"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict, nullptr, nullptr}, |
| 622 | {nullptr, nullptr, nullptr, nullptr, nullptr}}; |
| 623 | type->tp_getset = getset; |
| 624 | } |
| 625 | |
| 626 | /// buffer_protocol: Fill in the view as specified by flags. |
| 627 | extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int flags) { |
no outgoing calls
no test coverage detected