Files
Python3-Win9x/scripts/vc6-setobject-vectorcall-c89.test.py
T

45 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Check set_vectorcall's C89 declaration and unchanged evaluation order."""
import re
import sys
from pathlib import Path
source = Path(sys.argv[1]).read_text()
match = re.search(
r"static PyObject\*\nset_vectorcall\(PyObject \*type, PyObject \* const\*args,"
r"\s*size_t nargsf, PyObject \*kwnames\)\n\{(.*?)\n\}",
source,
re.S,
)
assert match, "set_vectorcall not found"
body = match.group(1)
assert re.match(r"\s*Py_ssize_t nargs;", body), (
"set_vectorcall: nargs must be declared without an initializer before "
"assert(PyType_Check(type)); late declaration is not C89 compatible"
)
expected = """
Py_ssize_t nargs;
assert(PyType_Check(type));
if (!_PyArg_NoKwnames("set", kwnames)) {
return NULL;
}
nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("set", nargs, 0, 1)) {
return NULL;
}
if (nargs) {
return make_new_set(_PyType_CAST(type), args[0]);
}
return make_new_set(_PyType_CAST(type), NULL);
"""
assert re.sub(r"\s+", "", body) == re.sub(r"\s+", "", expected), (
"preserve type assertion, keyword rejection, nargs evaluation, positional "
"rejection, guarded args[0] access, and construction in their original order"
)
print("set_vectorcall C89 declaration and evaluation order: PASS")