25 lines
928 B
Python
25 lines
928 B
Python
#!/usr/bin/env python3
|
|
"""Check set_table_resize's C89 declaration and preserve resize sizing order."""
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
source = Path(sys.argv[1]).read_text()
|
|
match = re.search(
|
|
r"static int\nset_table_resize\(PySetObject \*so, Py_ssize_t minused\)\n\{(.*?)\n\}",
|
|
source,
|
|
re.S,
|
|
)
|
|
assert match, "set_table_resize not found"
|
|
body = match.group(1)
|
|
assert re.search(r"^\s*size_t newsize;\s*$", body, re.M), (
|
|
"newsize must be declared without initializer in the function declaration block"
|
|
)
|
|
assert re.search(
|
|
r"assert\(minused >= 0\);\s*/\* Find the smallest table size > minused\. \*/"
|
|
r"\s*/\* XXX speed-up with intrinsics \*/\s*newsize = PySet_MINSIZE;"
|
|
r"\s*while \(newsize <= \(size_t\)minused\)",
|
|
body,
|
|
), "newsize initialization and resize loop must remain after the assertion in original order"
|
|
print("set_table_resize C89 declaration and sizing order: PASS")
|