Skip to content

Commit d3e5e3f

Browse files
committed
Adjust a test to cope with 3.14 tuple changes
PyTupleObject now includes a cached hash. Adjust our heuristics about how to find the items inside a tuple.
1 parent 89db0be commit d3e5e3f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/integration/test_local_variables.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ class TupleObject(ctypes.Structure):
582582
_fields_ = [
583583
("ob_type", ctypes.c_void_p),
584584
("ob_size", ctypes.c_ssize_t),
585+
]
586+
587+
class TupleItems(ctypes.Structure):
588+
_fields_ = [
585589
("ob_item0", ctypes.c_void_p),
586590
("ob_item1", ctypes.c_void_p),
587591
]
@@ -590,15 +594,19 @@ def ob_type_field(obj):
590594
# Assume ob_type is the last field of PyObject
591595
return id(obj) + sys.getsizeof(None) - ctypes.sizeof(ctypes.c_void_p)
592596
597+
def tuple_ob_items_field(tup):
598+
assert isinstance(tup, tuple)
599+
return id(tup) + sys.getsizeof(()) - sys.getsizeof(None)
600+
593601
def main():
594602
bad_type = (1, 2, 3)
595603
bad_elem = (4, 5, 6)
596604
nullelem = (7, 8, 9)
597605
bad_list = [0, 1, 2]
598606
599607
TupleObject.from_address(ob_type_field(bad_type)).ob_type = 0xded
600-
TupleObject.from_address(ob_type_field(bad_elem)).ob_item1 = 0xbad
601-
TupleObject.from_address(ob_type_field(nullelem)).ob_item1 = 0x0
608+
TupleItems.from_address(tuple_ob_items_field(bad_elem)).ob_item1 = 0xbad
609+
TupleItems.from_address(tuple_ob_items_field(nullelem)).ob_item1 = 0x0
602610
ListObject.from_address(ob_type_field(bad_list)).ob_item = 0x0
603611
604612
fifo = sys.argv[1]

0 commit comments

Comments
 (0)