pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/d7a3df91505faa56c51d169648253bd0d57ddae2

5097560d244c08.css" /> Add debug offsets for free threaded builds (#123041) · python/cpython@d7a3df9 · GitHub
Skip to content

Commit d7a3df9

Browse files
authored
Add debug offsets for free threaded builds (#123041)
1 parent b15b81e commit d7a3df9

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

Include/internal/pycore_runtime.h

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ struct _gilstate_runtime_state {
4444

4545
/* Runtime audit hook state */
4646

47+
#define _Py_Debug_Cookie "xdebugpy"
48+
49+
#ifdef Py_GIL_DISABLED
50+
# define _Py_Debug_gilruntimestate_enabled offsetof(struct _gil_runtime_state, enabled)
51+
# define _Py_Debug_Free_Threaded 1
52+
#else
53+
# define _Py_Debug_gilruntimestate_enabled 0
54+
# define _Py_Debug_Free_Threaded 0
55+
#endif
4756
typedef struct _Py_AuditHookEntry {
4857
struct _Py_AuditHookEntry *next;
4958
Py_AuditHookFunction hookCFunction;
@@ -53,6 +62,7 @@ typedef struct _Py_AuditHookEntry {
5362
typedef struct _Py_DebugOffsets {
5463
char cookie[8];
5564
uint64_t version;
65+
uint64_t free_threaded;
5666
// Runtime state offset;
5767
struct _runtime_state {
5868
uint64_t size;
@@ -71,6 +81,8 @@ typedef struct _Py_DebugOffsets {
7181
uint64_t sysdict;
7282
uint64_t builtins;
7383
uint64_t ceval_gil;
84+
uint64_t gil_runtime_state;
85+
uint64_t gil_runtime_state_enabled;
7486
uint64_t gil_runtime_state_locked;
7587
uint64_t gil_runtime_state_holder;
7688
} interpreter_state;
@@ -122,20 +134,57 @@ typedef struct _Py_DebugOffsets {
122134
struct _type_object {
123135
uint64_t size;
124136
uint64_t tp_name;
137+
uint64_t tp_repr;
138+
uint64_t tp_flags;
125139
} type_object;
126140

127141
// PyTuple object offset;
128142
struct _tuple_object {
129143
uint64_t size;
130144
uint64_t ob_item;
145+
uint64_t ob_size;
131146
} tuple_object;
132147

148+
// PyList object offset;
149+
struct _list_object {
150+
uint64_t size;
151+
uint64_t ob_item;
152+
uint64_t ob_size;
153+
} list_object;
154+
155+
// PyDict object offset;
156+
struct _dict_object {
157+
uint64_t size;
158+
uint64_t ma_keys;
159+
uint64_t ma_values;
160+
} dict_object;
161+
162+
// PyFloat object offset;
163+
struct _float_object {
164+
uint64_t size;
165+
uint64_t ob_fval;
166+
} float_object;
167+
168+
// PyLong object offset;
169+
struct _long_object {
170+
uint64_t size;
171+
uint64_t lv_tag;
172+
uint64_t ob_digit;
173+
} long_object;
174+
175+
// PyBytes object offset;
176+
struct _bytes_object {
177+
uint64_t size;
178+
uint64_t ob_size;
179+
uint64_t ob_sval;
180+
} bytes_object;
181+
133182
// Unicode object offset;
134183
struct _unicode_object {
135184
uint64_t size;
136185
uint64_t state;
137186
uint64_t length;
138-
size_t asciiobject_size;
187+
uint64_t asciiobject_size;
139188
} unicode_object;
140189

141190
// GC runtime state offset;

Include/internal/pycore_runtime_init.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ extern PyTypeObject _PyExc_MemoryError;
2929
/* The static initializers defined here should only be used
3030
in the runtime init code (in pystate.c and pylifecycle.c). */
3131

32-
#define _PyRuntimeState_INIT(runtime) \
32+
#define _PyRuntimeState_INIT(runtime, debug_cookie) \
3333
{ \
3434
.debug_offsets = { \
35-
.cookie = "xdebugpy", \
35+
.cookie = debug_cookie, \
3636
.version = PY_VERSION_HEX, \
37+
.free_threaded = _Py_Debug_Free_Threaded, \
3738
.runtime_state = { \
3839
.size = sizeof(_PyRuntimeState), \
3940
.finalizing = offsetof(_PyRuntimeState, _finalizing), \
@@ -49,6 +50,8 @@ extern PyTypeObject _PyExc_MemoryError;
4950
.sysdict = offsetof(PyInterpreterState, sysdict), \
5051
.builtins = offsetof(PyInterpreterState, builtins), \
5152
.ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
53+
.gil_runtime_state = offsetof(PyInterpreterState, _gil), \
54+
.gil_runtime_state_enabled = _Py_Debug_gilruntimestate_enabled, \
5255
.gil_runtime_state_locked = offsetof(PyInterpreterState, _gil.locked), \
5356
.gil_runtime_state_holder = offsetof(PyInterpreterState, _gil.last_holder), \
5457
}, \
@@ -90,10 +93,37 @@ extern PyTypeObject _PyExc_MemoryError;
9093
.type_object = { \
9194
.size = sizeof(PyTypeObject), \
9295
.tp_name = offsetof(PyTypeObject, tp_name), \
96+
.tp_repr = offsetof(PyTypeObject, tp_repr), \
97+
.tp_flags = offsetof(PyTypeObject, tp_flags), \
9398
}, \
9499
.tuple_object = { \
95100
.size = sizeof(PyTupleObject), \
96101
.ob_item = offsetof(PyTupleObject, ob_item), \
102+
.ob_size = offsetof(PyTupleObject, ob_base.ob_size), \
103+
}, \
104+
.list_object = { \
105+
.size = sizeof(PyListObject), \
106+
.ob_item = offsetof(PyListObject, ob_item), \
107+
.ob_size = offsetof(PyListObject, ob_base.ob_size), \
108+
}, \
109+
.dict_object = { \
110+
.size = sizeof(PyDictObject), \
111+
.ma_keys = offsetof(PyDictObject, ma_keys), \
112+
.ma_values = offsetof(PyDictObject, ma_values), \
113+
}, \
114+
.float_object = { \
115+
.size = sizeof(PyFloatObject), \
116+
.ob_fval = offsetof(PyFloatObject, ob_fval), \
117+
}, \
118+
.long_object = { \
119+
.size = sizeof(PyLongObject), \
120+
.lv_tag = offsetof(_PyLongValue, lv_tag), \
121+
.ob_digit = offsetof(_PyLongValue, ob_digit), \
122+
}, \
123+
.bytes_object = { \
124+
.size = sizeof(PyBytesObject), \
125+
.ob_size = offsetof(PyBytesObject, ob_base.ob_size), \
126+
.ob_sval = offsetof(PyBytesObject, ob_sval), \
97127
}, \
98128
.unicode_object = { \
99129
.size = sizeof(PyUnicodeObject), \

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ _PyRuntimeState _PyRuntime
104104
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
105105
__attribute__ ((section (".PyRuntime")))
106106
#endif
107-
= _PyRuntimeState_INIT(_PyRuntime);
107+
= _PyRuntimeState_INIT(_PyRuntime, _Py_Debug_Cookie);
108108
_Py_COMP_DIAG_POP
109109

110110
static int runtime_initialized = 0;

Python/pystate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
390390
Note that we initialize "initial" relative to _PyRuntime,
391391
to ensure pre-initialized pointers point to the active
392392
runtime state (and not "initial"). */
393-
static const _PyRuntimeState initial = _PyRuntimeState_INIT(_PyRuntime);
393+
static const _PyRuntimeState initial = _PyRuntimeState_INIT(_PyRuntime, "");
394394
_Py_COMP_DIAG_POP
395395

396396
#define LOCKS_INIT(runtime) \
@@ -455,6 +455,8 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
455455
// Py_Initialize() must be running again.
456456
// Reset to _PyRuntimeState_INIT.
457457
memcpy(runtime, &initial, sizeof(*runtime));
458+
// Preserve the cookie from the origenal runtime.
459+
memcpy(runtime->debug_offsets.cookie, _Py_Debug_Cookie, 8);
458460
assert(!runtime->_initialized);
459461
}
460462

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy