extern "C" {
#endif
+#include "pycore_moduleobject.h"
+
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
return &state->tp_weaklist;
}
+/* Like PyType_GetModuleState, but skips verification
+ * that type is a heap type with an associated module */
+static inline void *
+_PyType_GetModuleState(PyTypeObject *type)
+{
+ assert(PyType_Check(type));
+ assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
+ PyHeapTypeObject *et = (PyHeapTypeObject *)type;
+ assert(et->ht_module);
+ PyModuleObject *mod = (PyModuleObject *)(et->ht_module);
+ assert(mod != NULL);
+ return mod->md_state;
+}
+
struct types_state {
struct type_cache type_cache;
size_t num_builtins_initialized;
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
+#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "structmember.h" // PyMemberDef
static inline itertools_state *
get_module_state_by_cls(PyTypeObject *cls)
{
- void *state = PyType_GetModuleState(cls);
+ void *state = _PyType_GetModuleState(cls);
assert(state != NULL);
return (itertools_state *)state;
}