Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/python3.14/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 #ifndef Py_BUILD_CORE 8 # error "this header requires Py_BUILD_CORE define" 9 #endif 10 11 #include "pycore_interp_structs.h" // managed_static_type_state 12 #include "pycore_moduleobject.h" // PyModuleObject 13 14 15 /* state */ 16 17 #define _Py_TYPE_VERSION_INT 1 18 #define _Py_TYPE_VERSION_FLOAT 2 19 #define _Py_TYPE_VERSION_LIST 3 20 #define _Py_TYPE_VERSION_TUPLE 4 21 #define _Py_TYPE_VERSION_STR 5 22 #define _Py_TYPE_VERSION_SET 6 23 #define _Py_TYPE_VERSION_FROZEN_SET 7 24 #define _Py_TYPE_VERSION_DICT 8 25 #define _Py_TYPE_VERSION_BYTEARRAY 9 26 #define _Py_TYPE_VERSION_BYTES 10 27 #define _Py_TYPE_VERSION_COMPLEX 11 28 29 #define _Py_TYPE_VERSION_NEXT 16 30 31 32 #define _Py_TYPE_BASE_VERSION_TAG (2<<16) 33 #define _Py_MAX_GLOBAL_TYPE_VERSION_TAG (_Py_TYPE_BASE_VERSION_TAG - 1) 34 35 36 /* runtime lifecycle */ 37 38 extern PyStatus _PyTypes_InitTypes(PyInterpreterState *); 39 extern void _PyTypes_FiniTypes(PyInterpreterState *); 40 extern void _PyTypes_FiniExtTypes(PyInterpreterState *interp); 41 extern void _PyTypes_Fini(PyInterpreterState *); 42 extern void _PyTypes_AfterFork(void); 43 44 static inline PyObject ** 45 _PyStaticType_GET_WEAKREFS_LISTPTR(managed_static_type_state *state) 46 { 47 assert(state != NULL); 48 return &state->tp_weaklist; 49 } 50 51 extern int _PyStaticType_InitBuiltin( 52 PyInterpreterState *interp, 53 PyTypeObject *type); 54 extern void _PyStaticType_FiniBuiltin( 55 PyInterpreterState *interp, 56 PyTypeObject *type); 57 extern void _PyStaticType_ClearWeakRefs( 58 PyInterpreterState *interp, 59 PyTypeObject *type); 60 extern managed_static_type_state * _PyStaticType_GetState( 61 PyInterpreterState *interp, 62 PyTypeObject *type); 63 64 // Export for '_datetime' shared extension. 65 PyAPI_FUNC(int) _PyStaticType_InitForExtension( 66 PyInterpreterState *interp, 67 PyTypeObject *self); 68 69 // Export for _testinternalcapi extension. 70 PyAPI_FUNC(PyObject *) _PyStaticType_GetBuiltins(void); 71 72 73 /* Like PyType_GetModuleState, but skips verification 74 * that type is a heap type with an associated module */ 75 static inline void * 76 _PyType_GetModuleState(PyTypeObject *type) 77 { 78 assert(PyType_Check(type)); 79 assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); 80 PyHeapTypeObject *et = (PyHeapTypeObject *)type; 81 assert(et->ht_module); 82 PyModuleObject *mod = (PyModuleObject *)(et->ht_module); 83 assert(mod != NULL); 84 return mod->md_state; 85 } 86 87 88 // Export for 'math' shared extension, used via _PyType_IsReady() static inline 89 // function 90 PyAPI_FUNC(PyObject *) _PyType_GetDict(PyTypeObject *); 91 92 extern PyObject * _PyType_GetBases(PyTypeObject *type); 93 extern PyObject * _PyType_GetMRO(PyTypeObject *type); 94 extern PyObject* _PyType_GetSubclasses(PyTypeObject *); 95 extern int _PyType_HasSubclasses(PyTypeObject *); 96 97 // Export for _testinternalcapi extension. 98 PyAPI_FUNC(PyObject *) _PyType_GetSlotWrapperNames(void); 99 100 // PyType_Ready() must be called if _PyType_IsReady() is false. 101 // See also the Py_TPFLAGS_READY flag. 102 static inline int 103 _PyType_IsReady(PyTypeObject *type) 104 { 105 return _PyType_GetDict(type) != NULL; 106 } 107 108 extern PyObject* _Py_type_getattro_impl(PyTypeObject *type, PyObject *name, 109 int *suppress_missing_attribute); 110 extern PyObject* _Py_type_getattro(PyObject *type, PyObject *name); 111 112 extern PyObject* _Py_BaseObject_RichCompare(PyObject* self, PyObject* other, int op); 113 114 extern PyObject* _Py_slot_tp_getattro(PyObject *self, PyObject *name); 115 extern PyObject* _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name); 116 117 extern PyTypeObject _PyBufferWrapper_Type; 118 119 PyAPI_FUNC(PyObject*) _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, 120 PyObject *name, int *meth_found); 121 122 extern PyObject* _PyType_GetFullyQualifiedName(PyTypeObject *type, char sep); 123 124 // Perform the following operation, in a thread-safe way when required by the 125 // build mode. 126 // 127 // self->tp_flags = (self->tp_flags & ~mask) | flags; 128 extern void _PyType_SetFlags(PyTypeObject *self, unsigned long mask, 129 unsigned long flags); 130 extern int _PyType_AddMethod(PyTypeObject *, PyMethodDef *); 131 132 // Like _PyType_SetFlags(), but apply the operation to self and any of its 133 // subclasses without Py_TPFLAGS_IMMUTABLETYPE set. 134 extern void _PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask, 135 unsigned long flags); 136 137 extern unsigned int _PyType_GetVersionForCurrentState(PyTypeObject *tp); 138 PyAPI_FUNC(void) _PyType_SetVersion(PyTypeObject *tp, unsigned int version); 139 PyTypeObject *_PyType_LookupByVersion(unsigned int version); 140 141 // Function pointer type for user-defined validation function that will be 142 // called by _PyType_Validate(). 143 // It should return 0 if the validation is passed, otherwise it will return -1. 144 typedef int (*_py_validate_type)(PyTypeObject *); 145 146 // It will verify the ``ty`` through user-defined validation function ``validate``, 147 // and if the validation is passed, it will set the ``tp_version`` as valid 148 // tp_version_tag from the ``ty``. 149 extern int _PyType_Validate(PyTypeObject *ty, _py_validate_type validate, unsigned int *tp_version); 150 extern int _PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor, uint32_t tp_version); 151 152 // Like PyType_GetBaseByToken, but does not modify refcounts. 153 // Cannot fail; arguments must be valid. 154 PyAPI_FUNC(int) 155 _PyType_GetBaseByToken_Borrow(PyTypeObject *type, void *token, PyTypeObject **result); 156 157 #ifdef __cplusplus 158 } 159 #endif 160 #endif /* !Py_INTERNAL_TYPEOBJECT_H */