Skip to content

Remove dead Python 2.6/MSVC 2008 compat code, use METH_NOARGS for version functions#334

Open
devdanzin wants to merge 1 commit intopython-lz4:masterfrom
devdanzin:fix/cleanup-dead-compat-and-meth-varargs
Open

Remove dead Python 2.6/MSVC 2008 compat code, use METH_NOARGS for version functions#334
devdanzin wants to merge 1 commit intopython-lz4:masterfrom
devdanzin:fix/cleanup-dead-compat-and-meth-varargs

Conversation

@devdanzin
Copy link
Copy Markdown

Summary

  • Remove dead #ifndef PyCapsule_Type guards in _frame.c (2 sites) and _stream.c (1 site) — PyCapsule_Type is an extern symbol, not a macro, so #ifndef is always true. The #else branches (Python 2.6 capsulethunk compat) are dead code that unsafely 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.cPy_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 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

  • Existing tests pass
  • library_version_string() still works
  • library_version_string(1, 2, 3) now raises TypeError instead of silently succeeding

- 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>
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