32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Regress VC6 C89 compatibility of type_new_descriptors() loop index."""
|
|
import re
|
|
from pathlib import Path
|
|
|
|
source = Path("cpython/Objects/typeobject.c").read_text()
|
|
match = re.search(
|
|
r"\nstatic int\ntype_new_descriptors\(const type_new_ctx \*ctx, PyTypeObject \*type\)\n\{(.*?)\n\}",
|
|
source,
|
|
re.S,
|
|
)
|
|
assert match, "type_new_descriptors definition missing"
|
|
body = re.sub(r"/\*.*?\*/|//[^\n]*", "", match.group(1), flags=re.S)
|
|
assert re.match(
|
|
r"\s*Py_ssize_t i;"
|
|
r"\s*PyHeapTypeObject \*et = \(PyHeapTypeObject \*\)type;"
|
|
r"\s*Py_ssize_t slotoffset = ctx->base->tp_basicsize;",
|
|
body,
|
|
), "type_new_descriptors: loop index i must be in opening locals (C89)"
|
|
assert len(re.findall(r"\bPy_ssize_t\s+i\b", body)) == 1, (
|
|
"declare loop index i exactly once"
|
|
)
|
|
assert re.search(
|
|
r"if \(et->ht_slots != NULL\)\s*\{"
|
|
r"\s*PyMemberDef \*mp = _PyHeapType_GET_MEMBERS\(et\);"
|
|
r"\s*Py_ssize_t nslot = PyTuple_GET_SIZE\(et->ht_slots\);"
|
|
r"\s*for \(i = 0; i < nslot; i\+\+, mp\+\+\)\s*\{"
|
|
r"\s*mp->name = PyUnicode_AsUTF8\(\s*PyTuple_GET_ITEM\(et->ht_slots, i\)\);",
|
|
body,
|
|
), "preserve guarded slot setup, loop start, bound, increments, and indexing"
|
|
print("type_new_descriptors C89 loop index: PASS")
|