Files
Python3-Win9x/scripts/vc6-setobject-make-new-set-c89.test.py
T

28 lines
1.0 KiB
Python

#!/usr/bin/env python3
"""Check make_new_set's C89 declaration and assertion/allocation order."""
import re
import sys
from pathlib import Path
source = Path(sys.argv[1]).read_text()
match = re.search(
r"static PyObject \*\nmake_new_set\(PyTypeObject \*type, PyObject \*iterable\)"
r"\n\{(.*?)\n\}",
source,
re.S,
)
assert match, "make_new_set not found"
body = match.group(1)
assert re.match(r"\s*PySetObject \*so;", body), (
"so must be declared without initializer before the assertion"
)
assert re.match(
r"\s*PySetObject \*so;\s*assert\(PyType_Check\(type\)\);"
r"\s*so = \(PySetObject \*\)type->tp_alloc\(type, 0\);"
r"\s*if \(so == NULL\)\s*return NULL;",
body,
), "type assertion, allocation, and allocation failure check must retain their order"
assert body.count("PySetObject *so;") == 1, "so must be declared exactly once"
assert body.count("type->tp_alloc(") == 1, "allocation must occur exactly once"
print("make_new_set C89 declaration and assertion/allocation order: PASS")