43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Keep vectorcall_maybe declarations C89-safe and evaluation order intact."""
|
|
import re
|
|
from pathlib import Path
|
|
|
|
source = Path("cpython/Objects/typeobject.c").read_text()
|
|
match = re.search(
|
|
r"\nstatic PyObject \*\nvectorcall_maybe\(PyThreadState \*tstate, PyObject \*name,\n"
|
|
r"\s*PyObject \*const \*args, Py_ssize_t nargs\)\n\{(.*?)\n\}",
|
|
source,
|
|
re.S,
|
|
)
|
|
assert match, "vectorcall_maybe definition missing"
|
|
body = match.group(1)
|
|
assert re.match(
|
|
r"\s*int unbound;\s*PyObject \*self;\s*PyObject \*func;"
|
|
r"\s*PyObject \*retval;\s*assert\(nargs >= 1\);",
|
|
body,
|
|
), "vectorcall_maybe: all locals must precede assert in the opening declaration block (C89)"
|
|
expected = """
|
|
int unbound;
|
|
PyObject *self;
|
|
PyObject *func;
|
|
PyObject *retval;
|
|
|
|
assert(nargs >= 1);
|
|
|
|
self = args[0];
|
|
func = lookup_maybe_method(self, name, &unbound);
|
|
if (func == NULL) {
|
|
if (!PyErr_Occurred())
|
|
Py_RETURN_NOTIMPLEMENTED;
|
|
return NULL;
|
|
}
|
|
retval = vectorcall_unbound(tstate, unbound, func, args, nargs);
|
|
Py_DECREF(func);
|
|
return retval;
|
|
"""
|
|
assert body.split() == expected.split(), (
|
|
"vectorcall_maybe: preserve all assignments, evaluation order, and control flow"
|
|
)
|
|
print("vectorcall_maybe C89 declarations and unchanged assignment/evaluation/control flow: PASS")
|