Skip to content

Commit 5da486c

Browse files
committed
Fix windows
1 parent eb61f38 commit 5da486c

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

Modules/_remote_debugging_module.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,37 @@
4141
#define GET_MEMBER(type, obj, offset) (*(type*)((char*)(obj) + (offset)))
4242

4343
/* Size macros for opaque buffers */
44-
#define SIZEOF_UNICODE_OBJ sizeof(PyUnicodeObject)
4544
#define SIZEOF_BYTES_OBJ sizeof(PyBytesObject)
46-
#define SIZEOF_INTERP_FRAME sizeof(_PyInterpreterFrame)
45+
#define SIZEOF_CODE_OBJ sizeof(PyCodeObject)
4746
#define SIZEOF_GEN_OBJ sizeof(PyGenObject)
47+
#define SIZEOF_INTERP_FRAME sizeof(_PyInterpreterFrame)
48+
#define SIZEOF_LLIST_NODE sizeof(struct llist_node)
49+
#define SIZEOF_PAGE_CACHE_ENTRY sizeof(page_cache_entry_t)
50+
#define SIZEOF_PYOBJECT sizeof(PyObject)
4851
#define SIZEOF_SET_OBJ sizeof(PySetObject)
49-
#define SIZEOF_TYPE_OBJ sizeof(PyTypeObject)
5052
#define SIZEOF_TASK_OBJ 4096
51-
#define SIZEOF_PYOBJECT sizeof(PyObject)
52-
#define SIZEOF_LLIST_NODE sizeof(struct llist_node)
5353
#define SIZEOF_THREAD_STATE sizeof(PyThreadState)
54-
#define SIZEOF_CODE_OBJ sizeof(PyCodeObject)
54+
#define SIZEOF_TYPE_OBJ sizeof(PyTypeObject)
55+
#define SIZEOF_UNICODE_OBJ sizeof(PyUnicodeObject)
5556

5657
// Calculate the minimum buffer size needed to read interpreter state fields
5758
// We need to read code_object_generation and potentially tlbc_generation
59+
#ifndef MAX
60+
#define _MAX(a, b) ((a) > (b) ? (a) : (b))
61+
#else
62+
#define _MAX(a, b) MAX(a, b)
63+
#endif
64+
5865
#ifdef Py_GIL_DISABLED
59-
#define INTERP_STATE_MIN_SIZE MAX(MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \
66+
#define INTERP_STATE_MIN_SIZE _MAX(_MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \
6067
offsetof(PyInterpreterState, tlbc_indices.tlbc_generation) + sizeof(uint32_t)), \
6168
offsetof(PyInterpreterState, threads.head) + sizeof(void*))
6269
#else
63-
#define INTERP_STATE_MIN_SIZE MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \
70+
#define INTERP_STATE_MIN_SIZE _MAX(offsetof(PyInterpreterState, _code_object_generation) + sizeof(uint64_t), \
6471
offsetof(PyInterpreterState, threads.head) + sizeof(void*))
6572
#endif
66-
#define INTERP_STATE_BUFFER_SIZE MAX(INTERP_STATE_MIN_SIZE, 256)
73+
#define INTERP_STATE_BUFFER_SIZE _MAX(INTERP_STATE_MIN_SIZE, 256)
74+
#undef _MAX
6775

6876

6977

@@ -392,7 +400,7 @@ read_py_long(
392400
unsigned int shift = PYLONG_BITS_IN_DIGIT;
393401

394402
// Read the entire PyLongObject at once
395-
char long_obj[unwinder->debug_offsets.long_object.size];
403+
char long_obj[SIZEOF_LONG_OBJ];
396404
int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
397405
&unwinder->handle,
398406
address,
@@ -531,7 +539,7 @@ parse_task_name(
531539
uintptr_t task_address
532540
) {
533541
// Read the entire TaskObj at once
534-
char task_obj[unwinder->async_debug_offsets.asyncio_task_object.size];
542+
char task_obj[SIZEOF_TASK_OBJ];
535543
int err = _Py_RemoteDebug_PagedReadRemoteMemory(
536544
&unwinder->handle,
537545
task_address,
@@ -594,7 +602,7 @@ static int parse_task_awaited_by(
594602
int recurse_task
595603
) {
596604
// Read the entire TaskObj at once
597-
char task_obj[unwinder->async_debug_offsets.asyncio_task_object.size];
605+
char task_obj[SIZEOF_TASK_OBJ];
598606
if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address,
599607
unwinder->async_debug_offsets.asyncio_task_object.size,
600608
task_obj) < 0) {
@@ -745,7 +753,7 @@ create_task_result(
745753
PyObject* result = NULL;
746754
PyObject *call_stack = NULL;
747755
PyObject *tn = NULL;
748-
char task_obj[unwinder->async_debug_offsets.asyncio_task_object.size];
756+
char task_obj[SIZEOF_TASK_OBJ];
749757
uintptr_t coro_addr;
750758

751759
result = PyList_New(0);

Python/remote_debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef struct {
106106
HANDLE hProcess;
107107
#endif
108108
page_cache_entry_t pages[MAX_PAGES];
109-
int page_size;
109+
Py_ssize_t page_size;
110110
} proc_handle_t;
111111

112112
static void

0 commit comments

Comments
 (0)