capi-workgroup / api-revolution

Proposals for radical or controversial API changes
29 stars 0 forks source link

Native Interface (NI) #1

Open encukou opened 11 months ago

encukou commented 11 months ago

Let's add a brand new API layer called the Native Interface (NI) that is:

Then, let's build a C-API layer on top of that, as one of many possible layers: things like Cython, PyO3, ctypes.pythonapi would act as alternatives to C-API (and reimplement it).

The C-API layer would implement the current C-API (Limited API at first), and would consist of

zooba commented 11 months ago

This is the kind of proposal I was thinking my proposal from capi-workgroup/api-revolution#4 would merge into well (doesn't replace the whole thing, of course, but that was never my intent).

Incidentally, the building blocks are really quite minimal:

Everything else can be implemented on top of these. We should definitely provide a lot of shortcuts, but these are the most core pieces.

I really think we should avoid our type-specific implementations becoming public API again. If you want to add two values, call the general "add" function and let it figure out that PyLongObject_Add is the right implementation.

encukou commented 11 months ago

performant

To meet this requirement, the NI layer should use concrete types (e.g. PyDictObject* rather than PyObject*). Run-time type checking belongs in the layer above. (Of course, for languages more strongly typed than C, the compiler-can do many of the type checks instead. And perhaps that includes C99/C++ for some cases.)

See #3 and https://github.com/capi-workgroup/api-evolution/issues/29

pitrou commented 11 months ago

You should first explain why you call it "Native Interface" and what that implies. If that implies CPython-only, then I don't understand how this would be making any progress. And if that implies that writing CPython-only code is required for performance, then this is entirely misguided IMHO.