Repository navigation
Conversation
- Remove dead #ifndef PyCapsule_Type guards in _frame.c (2 sites) and _stream.c (1 site) — PyCapsule_Type is not a macro, so #ifndef is always true. The #else branches (Python 2.6 capsulethunk compat) are dead code that casts PyObject* directly to struct pointers. - Remove dead MSVC 2008 stdint.h fallback in _block.c and _stream.c — MSVC 2008 (_MSC_VER < 1600) cannot build Python 3.9+. Replace with unconditional #include <stdint.h>. - Remove dead #ifndef Py_UNUSED guard in _block.c — Py_UNUSED has been defined since Python 3.4, and minimum is 3.9. - Change METH_VARARGS to METH_NOARGS for library_version_number and library_version_string in _version.c — these functions take no arguments but METH_VARARGS silently accepts and ignores any args passed by the caller. Found using cext-review-toolkit (https://github.com/devdanzin/cext-review-toolkit). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fallenmi
left a comment
There was a problem hiding this comment.
Reviewed exact head 3f85fd83a64d571e24e16b09158eefa454400740 with OpenAI Codex.
The METH_NOARGS flag change fixes the observable bug: on the exact base, both version functions accept arbitrary positional arguments; on this head they correctly raise TypeError. However, the two callbacks must retain their second unused PyObject * parameter.
CPython's methodobject.h defines PyCFunction as a two-parameter function and explicitly states that a METH_NOARGS function with one parameter has undefined behavior when Python calls it with two (bpo-33012). This head confirms the mismatch twice under Clang with -Werror=cast-function-type-strict; the exact base passes the same compile check.
Please restore PyObject * Py_UNUSED(args) to both callback signatures while keeping METH_NOARGS. The 17 focused version/frame tests pass on base and head; the broader head frame/block run reached 19,802 passing tests, with its one memory-usage failure passing immediately in isolation.
Summary
#ifndef PyCapsule_Typeguards in_frame.c(2 sites) and_stream.c(1 site) —PyCapsule_Typeis an extern symbol, not a macro, so#ifndefis always true. The#elsebranches (Python 2.6 capsulethunk compat) are dead code that unsafely castsPyObject*directly to struct pointers.stdint.hfallback in_block.cand_stream.c— MSVC 2008 (_MSC_VER < 1600) cannot build Python 3.9+. Replace with unconditional#include <stdint.h>.#ifndef Py_UNUSEDguard in_block.c—Py_UNUSEDhas been defined since Python 3.4, and minimum is 3.9.METH_VARARGStoMETH_NOARGSforlibrary_version_numberandlibrary_version_stringin_version.c— these functions take no arguments butMETH_VARARGSsilently accepts and ignores any arguments passed by the caller.69 lines of dead code removed.
Found using cext-review-toolkit.
Note
This PR was authored and submitted by Claude Code (Anthropic).
It was reviewed by a human before submission.
Test plan
library_version_string()still workslibrary_version_string(1, 2, 3)now raisesTypeErrorinstead of silently succeeding