Skip to content

tool test: TestPython add more examples - #947

Merged
xushiwei merged 1 commit into
goplus:mainfrom
xushiwei:q
Oct 6, 2026
Merged

xushiwei merged 1 commit into
goplus:mainfrom
xushiwei:q

Conversation

@xushiwei

@xushiwei xushiwei commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: adds PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *x, PyObject *index);
  • llcppg.cfg: FuncPrefix ["Py_"] → ["Py_", "Py"]
  • pythread.go (golden output): adds func (self *Object) Item(index *Object) *Object linked to C.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:

  • FuncPrefix ordering ["Py_", "Py"] is correct and significant. rmPrefix returns on the first matching prefix, so Py_IsTrue → IsTrue and PyList_GetItem → List_GetItem (then → method Item via MethodCheck "Py*_: $1" + cutMethodPrefix). Reversing to ["Py", "Py_"] would mis-strip Py_IsTrue to 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 is len(params) == 2 && params[1].Type() == t, which uses Go interface identity (==), not types.Identical. Both PyObject * params map to separate *types.Pointer allocations (types.NewPointer is not interned), so params[1].Type() == t is false, 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 standalone go/types check.)

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.

@xushiwei
xushiwei merged commit 08ec1a5 into goplus:main Oct 6, 2026
2 checks passed
@xushiwei
xushiwei deleted the q branch October 6, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant