Skip to content

Commit 0423da8

Browse files
authored
Stop assuming that memory addresses are signed (#15111)
See the commit message for details. Fixes #15107.
2 parents 4d71bcf + 4d0cb19 commit 0423da8

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

IPython/extensions/deduperreload/deduperreload_patching.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
NULL: object = object()
88
_MAX_FIELD_SEARCH_OFFSET = 50
99

10-
if sys.maxsize > 2**32:
11-
WORD_TYPE: type[ctypes.c_int32] | type[ctypes.c_int64] = ctypes.c_int64
12-
WORD_N_BYTES = 8
13-
else:
14-
WORD_TYPE = ctypes.c_int32
15-
WORD_N_BYTES = 4
10+
POINTER_N_BYTES = ctypes.sizeof(ctypes.c_void_p)
1611

1712

1813
class DeduperReloaderPatchingMixin:
@@ -32,7 +27,7 @@ def infer_field_offset(
3227
for offset in range(1, _MAX_FIELD_SEARCH_OFFSET):
3328
if (
3429
ctypes.cast(
35-
obj_addr + WORD_N_BYTES * offset, ctypes.POINTER(WORD_TYPE)
30+
obj_addr + POINTER_N_BYTES * offset, ctypes.POINTER(ctypes.c_void_p)
3631
).contents.value
3732
== field_addr
3833
):
@@ -69,7 +64,7 @@ def try_write_readonly_attr(
6964
if new_value not in (None, NULL):
7065
ctypes.pythonapi.Py_IncRef(ctypes.py_object(new_value))
7166
ctypes.cast(
72-
obj_addr + WORD_N_BYTES * offset, ctypes.POINTER(WORD_TYPE)
67+
obj_addr + POINTER_N_BYTES * offset, ctypes.POINTER(ctypes.c_void_p)
7368
).contents.value = new_value_addr
7469

7570
@classmethod

0 commit comments

Comments
 (0)