Files
Python3-Win9x/scripts/vc6-typeobject-type-new-visit-slots-index-c89.test.py

24 lines
890 B
Python

#!/usr/bin/env python3
"""Regress VC6 C89 compatibility of type_new_visit_slots() loop index."""
import re
from pathlib import Path
source = Path("cpython/Objects/typeobject.c").read_text()
match = re.search(
r"\nstatic int\ntype_new_visit_slots\(type_new_ctx \*ctx\)\n\{(.*?)\n\}",
source,
re.S,
)
assert match, "type_new_visit_slots definition missing"
body = match.group(1)
assert re.match(r"\s*PyObject \*slots = ctx->slots;\s*Py_ssize_t nslot = ctx->nslot;", body), (
"type_new_visit_slots opening locals changed unexpectedly"
)
assert re.search(r"\bPy_ssize_t i;", body), (
"type_new_visit_slots: C89 loop index i must be declared before statements"
)
assert re.search(r"for\s*\(\s*i\s*=\s*0\s*;\s*i\s*<\s*nslot\s*;\s*i\+\+\s*\)", body), (
"type_new_visit_slots: preserve loop start, bound, and increment"
)
print("type_new_visit_slots C89 loop index: PASS")