Repository navigation
tool test: TestPython add more examples - #947
Conversation
There was a problem hiding this comment.
Review: generator test fixture for PyList_GetItem method generation
This PR extends the python-3.14.8 llcppg test fixture to exercise the C-global-function → Go-method path:
include/pythread.h: addsPyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *x, PyObject *index);llcppg.cfg:FuncPrefix["Py_"]→["Py_", "Py"]pythread.go(golden output): addsfunc (self *Object) Item(index *Object) *Objectlinked toC.PyList_GetItem
Conclusion: no blocking issues. The header input, config change, and golden Go output are mutually consistent.
Verified against the generator in cl/name.go / cl/func.go:
FuncPrefixordering["Py_", "Py"]is correct and significant.rmPrefixreturns on the first matching prefix, soPy_IsTrue→IsTrueandPyList_GetItem→List_GetItem(then → methodItemviaMethodCheck "Py*_: $1"+cutMethodPrefix). Reversing to["Py", "Py_"]would mis-stripPy_IsTrueto a leading-underscore name. Existing golden entries (IsTrue, etc.) remain correct.- The two-same-type guard in
tryToMethod(cl/func.go) does not suppress this conversion. The guard islen(params) == 2 && params[1].Type() == t, which uses Go interface identity (==), nottypes.Identical. BothPyObject *params map to separate*types.Pointerallocations (types.NewPointeris not interned), soparams[1].Type() == tisfalse, the guard does not fire, and the function is correctly emitted as the method(*Object).Item— matching the committed golden file. (Empirically confirmed with a standalonego/typescheck.)
Note (optional, non-blocking): include/pythread.h — the fixture declares PyList_GetItem(PyObject *x, PyObject *index), whereas the real CPython prototype is PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index) (the index is an integer, not a PyObject*). This is harmless and intentional for a synthetic generation fixture, but since these files mirror CPython header layout, a brief comment noting the declaration is crafted to drive the method-generation test would keep a future contributor from "correcting" the type and silently changing coverage.
I could not run go test ./tool/ in this environment (the fixture test requires the llgo/libclang toolchain, which fails to link here), so the above rests on static analysis of the generator plus a direct go/types identity check rather than an executed golden-file diff.
MethodCheck— Logical-Type Method Detection in llcppg #945