PEP 697 – Limited C API for Extending Opaque Types

Hi @encukou,

thank you for that PEP and as @wjakob already wrote: looks good to me as well in general.
This will definitively help C extensions and in particular HPy.

There are just two minor points I want to bring up here:

  • You proposed to use a negative basicsize (or alternatively some flag) to mark it as relative. Is that really necessary? In the limited API, a custom type structure will not embed the base type. So, IMO, the sign does not add any extra info, right? The only reason I see is to keep the type spec compatible to the unlimited API (I mean, if one does not use the limited API; not sure how you call it).

  • I’m slightly concerned that function PyObject_GetTypeData is a bit too expensive in certain situations because while the pointer computation would usually just be an offset computation, it now needs to load the type, the base and the base’s basicsize to compute the pointer. But I assume, if extension authors are aware of that, it should be acceptable since the cost for loading the data pointer can often just be amortized.

Again, thank you for that work. I’m looking forward to have that.

– Florian