Skip to content

RFC: treat PyTypeObject as an opaque struct for Limited API compliance#157

Draft
neutrinoceros wants to merge 2 commits intobrandon-rhodes:masterfrom
neutrinoceros:rfc/tp_alloc
Draft

RFC: treat PyTypeObject as an opaque struct for Limited API compliance#157
neutrinoceros wants to merge 2 commits intobrandon-rhodes:masterfrom
neutrinoceros:rfc/tp_alloc

Conversation

@neutrinoceros
Copy link

@neutrinoceros neutrinoceros commented Mar 11, 2026

needed for #151
based off #153

This one doesn't compile yet, but the good news is that the errors are identical wether I force abi3 or not.

extension/wrapper.cpp:124:15: error: cannot initialize a variable of type 'allocfunc' (aka '_object *(*)(_typeobject *, long)') with an rvalue of type 'void *'
  124 |     allocfunc alloc_func = PyType_GetSlot(cls, Py_tp_alloc);
      |               ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extension/wrapper.cpp:514:15: error: cannot initialize a variable of type 'allocfunc' (aka '_object *(*)(_typeobject *, long)') with an rvalue of type 'void *'
  514 |     allocfunc alloc_func = PyType_GetSlot(type, Py_tp_alloc);
      |               ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

@neutrinoceros
Copy link
Author

The only difference I can see between this broken code and the known-working examples I have in astropy is that this module is C++ while the ones I can compile are C... if that's the meaningful difference I may be out of my depth, as I cannot think of a single reason why that would matter.

@neutrinoceros
Copy link
Author

found inspiration from this stack overflow thread. It compiles okay if I use type casting. Maybe C compilers just do the exact same thing implicitly and I never knew it was needed ?

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