27 lines
944 B
Python
27 lines
944 B
Python
#!/usr/bin/env python3
|
|
"""Regress VC6 C89 compatibility of type_new_slots_bases() loop index."""
|
|
import re
|
|
from pathlib import Path
|
|
|
|
source = Path("cpython/Objects/typeobject.c").read_text()
|
|
match = re.search(
|
|
r"\nstatic void\ntype_new_slots_bases\(type_new_ctx \*ctx\)\n\{(.*?)\n\}",
|
|
source,
|
|
re.S,
|
|
)
|
|
assert match, "type_new_slots_bases definition missing"
|
|
body = match.group(1)
|
|
assert re.match(
|
|
r"\s*Py_ssize_t nbases = PyTuple_GET_SIZE\(ctx->bases\);"
|
|
r"\s*Py_ssize_t i;\s*if\s*\(",
|
|
body,
|
|
), "type_new_slots_bases: 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*nbases\s*;\s*i\+\+\s*\)",
|
|
body,
|
|
), "type_new_slots_bases: preserve loop start, bound, and increment"
|
|
assert not re.search(r"for\s*\(\s*Py_ssize_t\b", body), (
|
|
"type_new_slots_bases: loop initializer must reuse the declared index"
|
|
)
|
|
print("type_new_slots_bases C89 loop index: PASS")
|