C API: PyType_FromSpec(): __vectorcalloffset__ (and other special offset members) does not support Py_RELATIVE_OFFSET
#123465
Labels
Bug report
Bug description:
When declaring members of custom types via
PyType_FromSpec(), it is advisable to rely onPy_RELATIVE_OFFSETto 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
Metathat declarestp_calland vector call, along with a typeClasscreated using this metaclass. It specifies the__vectorcalloffset__using one of two different ways:Compiling this extension with
#define TRIGGER_BUG 1and instantiatingClassshows that thetp_callpath is used.If I switch over from a relative to an absolute byte offset (change
#define TRIGGER_BUG 1to#define TRIGGER_BUG 0at 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: