Branch data Line data Source code
1 : : #ifndef Py_INTERNAL_TYPEOBJECT_H 2 : : #define Py_INTERNAL_TYPEOBJECT_H 3 : : #ifdef __cplusplus 4 : : extern "C" { 5 : : #endif 6 : : 7 : : #include "pycore_moduleobject.h" 8 : : 9 : : #ifndef Py_BUILD_CORE 10 : : # error "this header requires Py_BUILD_CORE define" 11 : : #endif 12 : : 13 : : 14 : : /* runtime lifecycle */ 15 : : 16 : : extern PyStatus _PyTypes_InitTypes(PyInterpreterState *); 17 : : extern void _PyTypes_FiniTypes(PyInterpreterState *); 18 : : extern void _PyTypes_Fini(PyInterpreterState *); 19 : : 20 : : 21 : : /* other API */ 22 : : 23 : : /* Length of array of slotdef pointers used to store slots with the 24 : : same __name__. There should be at most MAX_EQUIV-1 slotdef entries with 25 : : the same __name__, for any __name__. Since that's a static property, it is 26 : : appropriate to declare fixed-size arrays for this. */ 27 : : #define MAX_EQUIV 10 28 : : 29 : : typedef struct wrapperbase pytype_slotdef; 30 : : 31 : : 32 : : // Type attribute lookup cache: speed up attribute and method lookups, 33 : : // see _PyType_Lookup(). 34 : : struct type_cache_entry { 35 : : unsigned int version; // initialized from type->tp_version_tag 36 : : PyObject *name; // reference to exactly a str or None 37 : : PyObject *value; // borrowed reference or NULL 38 : : }; 39 : : 40 : : #define MCACHE_SIZE_EXP 12 41 : : 42 : : struct type_cache { 43 : : struct type_cache_entry hashtable[1 << MCACHE_SIZE_EXP]; 44 : : }; 45 : : 46 : : /* For now we hard-code this to a value for which we are confident 47 : : all the static builtin types will fit (for all builds). */ 48 : : #define _Py_MAX_STATIC_BUILTIN_TYPES 200 49 : : 50 : : typedef struct { 51 : : PyTypeObject *type; 52 : : PyObject *tp_subclasses; 53 : : /* We never clean up weakrefs for static builtin types since 54 : : they will effectively never get triggered. However, there 55 : : are also some diagnostic uses for the list of weakrefs, 56 : : so we still keep it. */ 57 : : PyObject *tp_weaklist; 58 : : } static_builtin_state; 59 : : 60 : : static inline PyObject ** 61 : 97444 : _PyStaticType_GET_WEAKREFS_LISTPTR(static_builtin_state *state) 62 : : { 63 : : assert(state != NULL); 64 : 97444 : return &state->tp_weaklist; 65 : : } 66 : : 67 : : /* Like PyType_GetModuleState, but skips verification 68 : : * that type is a heap type with an associated module */ 69 : : static inline void * 70 : 964 : _PyType_GetModuleState(PyTypeObject *type) 71 : : { 72 : : assert(PyType_Check(type)); 73 : : assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); 74 : 964 : PyHeapTypeObject *et = (PyHeapTypeObject *)type; 75 : : assert(et->ht_module); 76 : 964 : PyModuleObject *mod = (PyModuleObject *)(et->ht_module); 77 : : assert(mod != NULL); 78 : 964 : return mod->md_state; 79 : : } 80 : : 81 : : struct types_state { 82 : : struct type_cache type_cache; 83 : : size_t num_builtins_initialized; 84 : : static_builtin_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES]; 85 : : }; 86 : : 87 : : 88 : : extern int _PyStaticType_InitBuiltin(PyTypeObject *type); 89 : : extern static_builtin_state * _PyStaticType_GetState(PyTypeObject *); 90 : : extern void _PyStaticType_ClearWeakRefs(PyTypeObject *type); 91 : : extern void _PyStaticType_Dealloc(PyTypeObject *type); 92 : : 93 : : PyObject * 94 : : _Py_type_getattro_impl(PyTypeObject *type, PyObject *name, int *suppress_missing_attribute); 95 : : PyObject * 96 : : _Py_type_getattro(PyTypeObject *type, PyObject *name); 97 : : 98 : : PyObject *_Py_slot_tp_getattro(PyObject *self, PyObject *name); 99 : : PyObject *_Py_slot_tp_getattr_hook(PyObject *self, PyObject *name); 100 : : 101 : : #ifdef __cplusplus 102 : : } 103 : : #endif 104 : : #endif /* !Py_INTERNAL_TYPEOBJECT_H */