File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 44extern "C" {
55#endif
66
7+ #include "pycore_moduleobject.h"
8+
79#ifndef Py_BUILD_CORE
810# error "this header requires Py_BUILD_CORE define"
911#endif
@@ -62,6 +64,20 @@ _PyStaticType_GET_WEAKREFS_LISTPTR(static_builtin_state *state)
6264 return & state -> tp_weaklist ;
6365}
6466
67+ /* Like PyType_GetModuleState, but skips verification
68+ * that type is a heap type with an associated module */
69+ static inline void *
70+ _PyType_GetModuleState (PyTypeObject * type )
71+ {
72+ assert (PyType_Check (type ));
73+ assert (type -> tp_flags & Py_TPFLAGS_HEAPTYPE );
74+ PyHeapTypeObject * et = (PyHeapTypeObject * )type ;
75+ assert (et -> ht_module );
76+ PyModuleObject * mod = (PyModuleObject * )(et -> ht_module );
77+ assert (mod != NULL );
78+ return mod -> md_state ;
79+ }
80+
6581struct types_state {
6682 struct type_cache type_cache ;
6783 size_t num_builtins_initialized ;
Original file line number Diff line number Diff line change 33#include "pycore_call.h" // _PyObject_CallNoArgs()
44#include "pycore_long.h" // _PyLong_GetZero()
55#include "pycore_moduleobject.h" // _PyModule_GetState()
6+ #include "pycore_typeobject.h" // _PyType_GetModuleState()
67#include "pycore_object.h" // _PyObject_GC_TRACK()
78#include "pycore_tuple.h" // _PyTuple_ITEMS()
89#include "structmember.h" // PyMemberDef
@@ -48,7 +49,7 @@ get_module_state(PyObject *mod)
4849static inline itertools_state *
4950get_module_state_by_cls (PyTypeObject * cls )
5051{
51- void * state = PyType_GetModuleState (cls );
52+ void * state = _PyType_GetModuleState (cls );
5253 assert (state != NULL );
5354 return (itertools_state * )state ;
5455}
You can’t perform that action at this time.
0 commit comments