Skip to content
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

Native Interface (NI) #1

Open
encukou opened this issue Oct 9, 2023 · 3 comments
Open

Native Interface (NI) #1

encukou opened this issue Oct 9, 2023 · 3 comments

Comments

@encukou
Copy link

encukou commented Oct 9, 2023

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

  • performant
  • complete (provides all necessary building blocks)
  • meant as a base for another layer (C-API, Cython, other language bindings)
    • not ergonomic (for C)
    • can use unwieldy names with version information or argument types
  • "ABI" only -- no C macros, inline functions, compiler-dependent types, etc.

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

  • thin wrappers around the NI, autogenerated from a description that's easy to reuse for the other layers
    • the description would encode similar info as Argument Clinic: argument/return types of a C wrapper and of the called NI function, and how to convert from one to the other
  • optional hand-written wrappers that can reach into the internals for performance
    • these should have the same API as the above, and automatically replace them the above is a stable ABI is not needed
@zooba
Copy link

zooba commented Oct 9, 2023

This is the kind of proposal I was thinking my proposal from #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:

  • import
  • convert from primitive types
  • get attribute
  • call

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.

@gvanrossum gvanrossum transferred this issue from capi-workgroup/api-evolution Oct 9, 2023
@encukou
Copy link
Author

encukou commented Oct 18, 2023

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 capi-workgroup/api-evolution#29

@pitrou
Copy link

pitrou commented Oct 20, 2023

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.

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

No branches or pull requests

3 participants