#!/usr/bin/env python3 """Keep vectorcall_method 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_method\(PyObject \*name, PyObject \*const \*args, Py_ssize_t nargs\)\n\{(.*?)\n\}", source, re.S, ) assert match, "vectorcall_method definition missing" body = match.group(1) assert re.match( r"\s*PyThreadState \*tstate;\s*int unbound;\s*PyObject \*self;" r"\s*PyObject \*func;\s*PyObject \*retval;\s*assert\(nargs >= 1\);", body, ), "vectorcall_method: all locals must precede assert in the opening declaration block (C89)" expected = """ PyThreadState *tstate; int unbound; PyObject *self; PyObject *func; PyObject *retval; assert(nargs >= 1); tstate = _PyThreadState_GET(); self = args[0]; func = lookup_method(self, name, &unbound); if (func == NULL) { return NULL; } retval = vectorcall_unbound(tstate, unbound, func, args, nargs); Py_DECREF(func); return retval; """ assert body.split() == expected.split(), ( "vectorcall_method: preserve all assignments, evaluation order, and control flow" ) print("vectorcall_method C89 declarations and unchanged assignment/evaluation/control flow: PASS")