38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Check only maybe_freelist_clear's C89 index and teardown 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"static void\nmaybe_freelist_clear\(PyInterpreterState \*interp, int fini\)\n\{(.*?)\n\}",
|
|
source.read_text(),
|
|
re.S,
|
|
)
|
|
assert match, "maybe_freelist_clear definition missing"
|
|
body = match.group(1)
|
|
assert re.match(r"\s*#if PyTuple_NFREELISTS > 0\s*Py_ssize_t i;", body), (
|
|
"maybe_freelist_clear: i must be declared before the loop for C89"
|
|
)
|
|
expected = """
|
|
#if PyTuple_NFREELISTS > 0
|
|
Py_ssize_t i;
|
|
for (i = 0; i < PyTuple_NFREELISTS; i++) {
|
|
PyTupleObject *p = STATE.free_list[i];
|
|
STATE.free_list[i] = NULL;
|
|
STATE.numfree[i] = fini ? -1 : 0;
|
|
while (p) {
|
|
PyTupleObject *q = p;
|
|
p = (PyTupleObject *)(p->ob_item[0]);
|
|
PyObject_GC_Del(q);
|
|
}
|
|
}
|
|
#endif
|
|
"""
|
|
assert re.sub(r"\s+", "", body) == re.sub(r"\s+", "", expected), (
|
|
"maybe_freelist_clear: preserve loop assignment, bounds, increment, "
|
|
"freelist reset, fini count, and linked-list deletion order"
|
|
)
|
|
print("maybe_freelist_clear C89 index and teardown order: PASS")
|