-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C API: PyType_FromSpec()
: __vectorcalloffset__
(and other special offset members) does not support Py_RELATIVE_OFFSET
#123465
Labels
Comments
cc @encukou |
encukou
changed the title
C API:
C API: Aug 29, 2024
PyType_FromSpec()
: __vectorcalloffset__
does not support Py_RELATIVE_OFFSET
PyType_FromSpec()
: __vectorcalloffset__
(and other special offset members) does not support Py_RELATIVE_OFFSET
encukou
added a commit
to encukou/cpython
that referenced
this issue
Aug 29, 2024
It does, thank you! |
encukou
added a commit
that referenced
this issue
Sep 5, 2024
encukou
pushed a commit
that referenced
this issue
Nov 13, 2024
picnixz
pushed a commit
to picnixz/cpython
that referenced
this issue
Dec 8, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Bug description:
When declaring members of custom types via
PyType_FromSpec()
, it is advisable to rely onPy_RELATIVE_OFFSET
to declare their position using a relative byte offset.This is needed to create portable stable API / limited ABI extensions since we don't need to make assumptions about the layout of the base type, and how Python concatenates the two (e.g. is there intermediate padding/alignment?)
In addition, one can specify a special member called
__vectorcalloffset__
to declare the byte offset of a pointer that implements a vector call handler.Unfortunately, these two features don't work together. That is bad news for anyone who wants to extend an opaque type (e.g.
PyTypeObject
) and add the ability to dispatch vector calls. I ran into this issue while looking for temporary workarounds for #100554.I created a minified reproducer here: https://github.com/wjakob/vectorcall_issue (installable via
pip install https://github.com/wjakob/vectorcall_issue
)This extension creates a metaclass
Meta
that declarestp_call
and vector call, along with a typeClass
created using this metaclass. It specifies the__vectorcalloffset__
using one of two different ways:Compiling this extension with
#define TRIGGER_BUG 1
and instantiatingClass
shows that thetp_call
path is used.If I switch over from a relative to an absolute byte offset (change
#define TRIGGER_BUG 1
to#define TRIGGER_BUG 0
at the top), the vector call is used. But that is not portable.CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
The text was updated successfully, but these errors were encountered: