File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 4
4
extern "C" {
5
5
#endif
6
6
7
+ #include "pycore_moduleobject.h"
8
+
7
9
#ifndef Py_BUILD_CORE
8
10
# error "this header requires Py_BUILD_CORE define"
9
11
#endif
@@ -62,6 +64,20 @@ _PyStaticType_GET_WEAKREFS_LISTPTR(static_builtin_state *state)
62
64
return & state -> tp_weaklist ;
63
65
}
64
66
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
+
65
81
struct types_state {
66
82
struct type_cache type_cache ;
67
83
size_t num_builtins_initialized ;
Original file line number Diff line number Diff line change 3
3
#include "pycore_call.h" // _PyObject_CallNoArgs()
4
4
#include "pycore_long.h" // _PyLong_GetZero()
5
5
#include "pycore_moduleobject.h" // _PyModule_GetState()
6
+ #include "pycore_typeobject.h" // _PyType_GetModuleState()
6
7
#include "pycore_object.h" // _PyObject_GC_TRACK()
7
8
#include "pycore_tuple.h" // _PyTuple_ITEMS()
8
9
#include "structmember.h" // PyMemberDef
@@ -48,7 +49,7 @@ get_module_state(PyObject *mod)
48
49
static inline itertools_state *
49
50
get_module_state_by_cls (PyTypeObject * cls )
50
51
{
51
- void * state = PyType_GetModuleState (cls );
52
+ void * state = _PyType_GetModuleState (cls );
52
53
assert (state != NULL );
53
54
return (itertools_state * )state ;
54
55
}
You can’t perform that action at this time.
0 commit comments