31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Check only tuplerepeat's dest_end declaration and assignment order."""
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
source = Path(sys.argv[1] if len(sys.argv) > 1 else "cpython/Objects/tupleobject.c")
|
|
match = re.search(
|
|
r"tuplerepeat\(PyTupleObject \*a, Py_ssize_t n\)\n\{(.*?)\n\}",
|
|
source.read_text(),
|
|
re.S,
|
|
)
|
|
assert match, "tuplerepeat definition missing"
|
|
body = match.group(1)
|
|
assert re.match(
|
|
r"\s*Py_ssize_t size;\s*PyTupleObject \*np;\s*PyObject \*\*dest;"
|
|
r"\s*PyObject \*\*dest_end;\s*if",
|
|
body,
|
|
), "tuplerepeat: dest_end must be declared in the opening declaration block"
|
|
assert len(re.findall(r"PyObject\s*\*\*dest_end\b", body)) == 1, (
|
|
"tuplerepeat: exactly one uninitialized dest_end declaration required"
|
|
)
|
|
assert re.search(
|
|
r"dest = np->ob_item;\s*dest_end = dest \+ size;",
|
|
body,
|
|
), "tuplerepeat: assign dest_end immediately after dest at its original evaluation point"
|
|
assert len(re.findall(r"\bdest_end\s*=", body)) == 1, (
|
|
"tuplerepeat: exactly one dest_end assignment required"
|
|
)
|
|
print("tuplerepeat dest_end C89 declaration and assignment order: PASS")
|