Debian Codegraph @

Include/internal/pycore_global_objects.h

raw
1 #ifndef Py_INTERNAL_GLOBAL_OBJECTS_H
2 #define Py_INTERNAL_GLOBAL_OBJECTS_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_context.h" // _PyContextTokenMissing
12 #include "pycore_gc.h" // _PyGC_Head_UNUSED
13 #include "pycore_global_strings.h" // struct _Py_global_strings
14 #include "pycore_hamt.h" // PyHamtNode_Bitmap
15 #include "pycore_hashtable.h" // _Py_hashtable_t
16 #include "pycore_typeobject.h" // pytype_slotdef
17
18
19 // These would be in pycore_long.h if it weren't for an include cycle.
20 #define _PY_NSMALLPOSINTS 257
21 #define _PY_NSMALLNEGINTS 5
22
23
24 // Only immutable objects should be considered runtime-global.
25 // All others must be per-interpreter.
26
27 #define _Py_GLOBAL_OBJECT(NAME) \
28 _PyRuntime.static_objects.NAME
29 #define _Py_SINGLETON(NAME) \
30 _Py_GLOBAL_OBJECT(singletons.NAME)
31
32 struct _Py_cached_objects {
33 // XXX We could statically allocate the hashtable.
34 _Py_hashtable_t *interned_strings;
35 };
36
37 struct _Py_static_objects {
38 struct {
39 /* Small integers are preallocated in this array so that they
40 * can be shared.
41 * The integers that are preallocated are those in the range
42 * -_PY_NSMALLNEGINTS (inclusive) to _PY_NSMALLPOSINTS (exclusive).
43 */
44 PyLongObject small_ints[_PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS];
45
46 PyBytesObject bytes_empty;
47 struct {
48 PyBytesObject ob;
49 char eos;
50 } bytes_characters[256];
51
52 struct _Py_global_strings strings;
53
54 _PyGC_Head_UNUSED _tuple_empty_gc_not_used;
55 PyTupleObject tuple_empty;
56
57 _PyGC_Head_UNUSED _hamt_bitmap_node_empty_gc_not_used;
58 PyHamtNode_Bitmap hamt_bitmap_node_empty;
59 _PyContextTokenMissing context_token_missing;
60 } singletons;
61 };
62
63 #define _Py_INTERP_CACHED_OBJECT(interp, NAME) \
64 (interp)->cached_objects.NAME
65
66 struct _Py_interp_cached_objects {
67 PyObject *interned_strings;
68
69 /* AST */
70 PyObject *_unused_str_replace_inf; // kept in 3.13 for ABI compatibility
71
72 /* object.__reduce__ */
73 PyObject *objreduce;
74 PyObject *type_slots_pname;
75 pytype_slotdef *type_slots_ptrs[MAX_EQUIV];
76
77 /* TypeVar and related types */
78 PyTypeObject *generic_type;
79 PyTypeObject *typevar_type;
80 PyTypeObject *typevartuple_type;
81 PyTypeObject *paramspec_type;
82 PyTypeObject *paramspecargs_type;
83 PyTypeObject *paramspeckwargs_type;
84 };
85
86 #define _Py_INTERP_STATIC_OBJECT(interp, NAME) \
87 (interp)->static_objects.NAME
88 #define _Py_INTERP_SINGLETON(interp, NAME) \
89 _Py_INTERP_STATIC_OBJECT(interp, singletons.NAME)
90
91 struct _Py_interp_static_objects {
92 struct {
93 int _not_used;
94 // hamt_empty is here instead of global because of its weakreflist.
95 _PyGC_Head_UNUSED _hamt_empty_gc_not_used;
96 PyHamtObject hamt_empty;
97 PyBaseExceptionObject last_resort_memory_error;
98 } singletons;
99 };
100
101
102 #ifdef __cplusplus
103 }
104 #endif
105 #endif /* !Py_INTERNAL_GLOBAL_OBJECTS_H */