MCPcopy Create free account
hub / github.com/pybind/pybind11 / enable_dynamic_attributes

Function enable_dynamic_attributes

include/pybind11/detail/class.h:608–624  ·  view source on GitHub ↗

Give instances of this type a `__dict__` and opt into garbage collection.

Source from the content-addressed store, hash-verified

606
607/// Give instances of this type a `__dict__` and opt into garbage collection.
608inline 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.
627extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int flags) {

Callers 2

make_new_python_typeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected