Skip to content

BUG: fix free-threaded PyObject layout in replace_scalar_type_names helper#30686

Merged
ngoldbaum merged 1 commit intonumpy:mainfrom
ngoldbaum:fix-ft-docs-build
Jan 20, 2026
Merged

BUG: fix free-threaded PyObject layout in replace_scalar_type_names helper#30686
ngoldbaum merged 1 commit intonumpy:mainfrom
ngoldbaum:fix-ft-docs-build

Conversation

@ngoldbaum
Copy link
Copy Markdown
Member

Fixes #30681.

This function models the layout of PyObject and pokes at it via ctypes. It was poking at bits outside of tp_name on the free-threaded build. The fix is to model PyObject correctly on free-threading.

The layout of PyObject is different on 3.13t but the size is the same so this should still work there. I tested on 3.14.2t.

@ngoldbaum ngoldbaum added 04 - Documentation 09 - Backport-Candidate PRs tagged should be backported 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) labels Jan 20, 2026
# an anonymous struct that we don't try to model
('__private', ctypes.c_int64),
('ob_type', ctypes.POINTER(PyTypeObject)),
]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ngoldbaum ngoldbaum changed the title BUG: fix ft PyObject layout in replace_scalar_type_names helper BUG: fix free-threaded PyObject layout in replace_scalar_type_names helper Jan 20, 2026
Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Jeesh, this is terrible, I wonder if we should just have a private helper in C to do this, seems almost saner...
(At least using PyObject_Type() for the first step...)

Anyway, LGTM, maybe ugly, but it'll keep working for many years probably so...

@ngoldbaum
Copy link
Copy Markdown
Member Author

Merging since the docs build passed.

@ngoldbaum ngoldbaum merged commit 754cb2c into numpy:main Jan 20, 2026
2 of 3 checks passed
charris pushed a commit to charris/numpy that referenced this pull request Jan 21, 2026
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 21, 2026
charris added a commit that referenced this pull request Jan 21, 2026
BUG: fix free-threaded PyObject layout in replace_scalar_type_names helper (#30686)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 04 - Documentation 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: doc build on 3.14t interpreter leads to bus error

3 participants