port: advance VC6 typeobject frontier and preserve regression coverage
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check structseq_traverse's C89 declarations and visit/size lookup order."""
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
source = Path(sys.argv[1] if len(sys.argv) > 1 else "cpython/Objects/structseq.c")
|
||||
match = re.search(
|
||||
r"static int\nstructseq_traverse\(PyStructSequence \*obj, visitproc visit, void \*arg\)"
|
||||
r"\n\{(.*?)\n\}",
|
||||
source.read_text(),
|
||||
re.S,
|
||||
)
|
||||
assert match, "structseq_traverse definition not found"
|
||||
body = match.group(1)
|
||||
assert re.match(r"\s*Py_ssize_t i, size;", body), (
|
||||
"structseq_traverse: i and size must be declared before the heap-type check; "
|
||||
"declaration after statement is not C89 compatible"
|
||||
)
|
||||
expected = """
|
||||
Py_ssize_t i, size;
|
||||
if (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HEAPTYPE) {
|
||||
Py_VISIT(Py_TYPE(obj));
|
||||
}
|
||||
size = REAL_SIZE(obj);
|
||||
for (i = 0; i < size; ++i) {
|
||||
Py_VISIT(obj->ob_item[i]);
|
||||
}
|
||||
return 0;
|
||||
"""
|
||||
assert re.sub(r"\s+", "", body) == re.sub(r"\s+", "", expected), (
|
||||
"preserve heap-type visit and its early return before the single real-size "
|
||||
"lookup, item visit order, loop initialization, and return behavior"
|
||||
)
|
||||
print("structseq_traverse C89 declarations and visit/size lookup order: PASS")
|
||||
Reference in New Issue
Block a user