port: advance VC6 typeobject frontier and preserve regression coverage

This commit is contained in:
RayPals
2026-10-26 18:09:33 +00:00
parent 35caf1a558
commit 5ab291a68c
162 changed files with 15675 additions and 85 deletions
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
"""Check PyTuple_New's C89 loop declaration and initialization 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"PyObject \*\nPyTuple_New\(Py_ssize_t size\)\n\{(.*?)\n\}",
source.read_text(),
re.S,
)
assert match, "PyTuple_New definition not found"
body = match.group(1)
assert re.match(r"\s*PyTupleObject \*op;\s*Py_ssize_t i;", body), (
"PyTuple_New: i must be declared before the size check; "
"for-loop declarations are not C89 compatible"
)
expected = """
PyTupleObject *op;
Py_ssize_t i;
if (size == 0) {
return tuple_get_empty();
}
op = tuple_alloc(size);
if (op == NULL) {
return NULL;
}
for (i = 0; i < size; i++) {
op->ob_item[i] = NULL;
}
_PyObject_GC_TRACK(op);
return (PyObject *) op;
"""
assert re.sub(r"\s+", "", body) == re.sub(r"\s+", "", expected), (
"preserve empty-tuple return, single allocation and failure return, loop "
"initialization/condition/increment, item clearing, GC tracking, and return order"
)
print("PyTuple_New C89 loop declaration and initialization order: PASS")