Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/python3.12/internal/pycore_typeobject.h
$ cat -n /usr/include/python3.12/internal/pycore_typeobject.h 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 /* state */ 15 16 #define _Py_TYPE_BASE_VERSION_TAG (2<<16) 17 #define _Py_MAX_GLOBAL_TYPE_VERSION_TAG (_Py_TYPE_BASE_VERSION_TAG - 1) 18 19 struct _types_runtime_state { 20 /* Used to set PyTypeObject.tp_version_tag for core static types. */ 21 // bpo-42745: next_version_tag remains shared by all interpreters 22 // because of static types. 23 unsigned int next_version_tag; 24 }; 25 26 27 // Type attribute lookup cache: speed up attribute and method lookups, 28 // see _PyType_Lookup(). 29 struct type_cache_entry { 30 unsigned int version; // initialized from type->tp_version_tag 31 PyObject *name; // reference to exactly a str or None 32 PyObject *value; // borrowed reference or NULL 33 }; 34 35 #define MCACHE_SIZE_EXP 12 36 37 struct type_cache { 38 struct type_cache_entry hashtable[1 << MCACHE_SIZE_EXP]; 39 }; 40 41 /* For now we hard-code this to a value for which we are confident 42 all the static builtin types will fit (for all builds). */ 43 #define _Py_MAX_STATIC_BUILTIN_TYPES 200 44 45 typedef struct { 46 PyTypeObject *type; 47 int readying; 48 int ready; 49 // XXX tp_dict can probably be statically allocated, 50 // instead of dynamically and stored on the interpreter. 51 PyObject *tp_dict; 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 struct types_state { 61 /* Used to set PyTypeObject.tp_version_tag. 62 It starts at _Py_MAX_GLOBAL_TYPE_VERSION_TAG + 1, 63 where all those lower numbers are used for core static types. */ 64 unsigned int next_version_tag; 65 66 struct type_cache type_cache; 67 size_t num_builtins_initialized; 68 static_builtin_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES]; 69 }; 70 71 72 /* runtime lifecycle */ 73 74 extern PyStatus _PyTypes_InitTypes(PyInterpreterState *); 75 extern void _PyTypes_FiniTypes(PyInterpreterState *); 76 extern void _PyTypes_Fini(PyInterpreterState *); 77 78 79 /* other API */ 80 81 /* Length of array of slotdef pointers used to store slots with the 82 same __name__. There should be at most MAX_EQUIV-1 slotdef entries with 83 the same __name__, for any __name__. Since that's a static property, it is 84 appropriate to declare fixed-size arrays for this. */ 85 #define MAX_EQUIV 10 86 87 typedef struct wrapperbase pytype_slotdef; 88 89 90 static inline PyObject ** 91 _PyStaticType_GET_WEAKREFS_LISTPTR(static_builtin_state *state) 92 { 93 assert(state != NULL); 94 return &state->tp_weaklist; 95 } 96 97 /* Like PyType_GetModuleState, but skips verification 98 * that type is a heap type with an associated module */ 99 static inline void * 100 _PyType_GetModuleState(PyTypeObject *type) 101 { 102 assert(PyType_Check(type)); 103 assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); 104 PyHeapTypeObject *et = (PyHeapTypeObject *)type; 105 assert(et->ht_module); 106 PyModuleObject *mod = (PyModuleObject *)(et->ht_module); 107 assert(mod != NULL); 108 return mod->md_state; 109 } 110 111 112 extern int _PyStaticType_InitBuiltin(PyInterpreterState *, PyTypeObject *type); 113 extern static_builtin_state * _PyStaticType_GetState(PyInterpreterState *, PyTypeObject *); 114 extern void _PyStaticType_ClearWeakRefs(PyInterpreterState *, PyTypeObject *type); 115 extern void _PyStaticType_Dealloc(PyInterpreterState *, PyTypeObject *); 116 117 PyAPI_FUNC(PyObject *) _PyType_GetDict(PyTypeObject *); 118 extern PyObject * _PyType_GetBases(PyTypeObject *type); 119 extern PyObject * _PyType_GetMRO(PyTypeObject *type); 120 extern PyObject* _PyType_GetSubclasses(PyTypeObject *); 121 extern int _PyType_HasSubclasses(PyTypeObject *); 122 123 // PyType_Ready() must be called if _PyType_IsReady() is false. 124 // See also the Py_TPFLAGS_READY flag. 125 static inline int 126 _PyType_IsReady(PyTypeObject *type) 127 { 128 return _PyType_GetDict(type) != NULL; 129 } 130 131 PyObject * 132 _Py_type_getattro_impl(PyTypeObject *type, PyObject *name, int *suppress_missing_attribute); 133 PyObject * 134 _Py_type_getattro(PyTypeObject *type, PyObject *name); 135 136 extern PyObject* _Py_BaseObject_RichCompare(PyObject* self, PyObject* other, int op); 137 138 PyObject *_Py_slot_tp_getattro(PyObject *self, PyObject *name); 139 PyObject *_Py_slot_tp_getattr_hook(PyObject *self, PyObject *name); 140 141 PyAPI_DATA(PyTypeObject) _PyBufferWrapper_Type; 142 143 PyObject * 144 _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found); 145 146 #ifdef __cplusplus 147 } 148 #endif 149 #endif /* !Py_INTERNAL_TYPEOBJECT_H */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™