-
Notifications
You must be signed in to change notification settings - Fork 1
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
Scope of the limited API #41
Comments
Oh, I just saw this issue 10 min after creating #42 which is similar.
As an user, I would like to write a C extension using the limited C API, I expect a convenient API, and be able to distribute a single wheel binary (per platform-architecture combination). "Convenient" is obviously hard to define here. For example, for me, If your goal is to write the bare minimum API such as Native Interface API, obviously, all "convenient" API should go. For me, the Native Interface API is more for machines, and the limited C API is more for human who write code manually. Another criteria is performance: Example on micro-benchmark on _PyLong_AsByteArray() to discuss if this function deserves to become a public C API, rather than calling Python On considering to make _PyLong_GCD() a public function, Serhiy wrote:
IMO we should also consider to take in account how common an API is used. Very commonly used APIs deserve a public API, whereas having to go through By the way, when the PyFrameObject members were removed from Python 3.12 C API, I documented how to update code using My goal for the long term would be to treat the "C API" basically as the limited C API: that the limited C API becomes the default. That's why I'm trying to clarifying what's "private" or "internal" in the "public C API". I don't know if it's possible, and I expect that the "C API" will always be larger than the "limited C API", since some APIs are never going to enter the limited C API by design, such as the PyTypeObject structure members. For me, there are two clear usages of "the C API":
This separation becomes more visible in Cython which started to support generating C code targeting the limited C API. Cython users can now decide their profile: stability/portability or performance. My concern is that Python has many API layers:
IMO it's very confusing for everybody :-( It would be better to only have two main layers:
|
In the mean time, people can use pythoncapi-compat to get the macro to define |
Maybe a guideline can be defined from that? Is it possible and "not too complicated" (how can it be measured? number of lines?) to reimplement the needed feature using existing limited C API? In the case of PyList_Extend() and PyList_Clear(), there is a way: #define PyList_Extend(list, arg) PyList_SetSlice((list), PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, (arg))
#define PyList_Clear(list) PyList_SetSlice((list), 0, PY_SSIZE_T_MAX, NULL) pythoncapi-compat doesn't target the limited C API. Many functions are implemented in pythoncapi-compat with functions which are excluded from the limited C API, especially private functions. |
Victor requested to add the new
PyList_Extend
andPyList_Clear
to limited API: python/cpython#111862This API can be trivially replaced by
PyObject_CallMethod
/PyObject_VectorcallMethod
-- or in this case, byPyList_SetSlice
.I would prefer to not add API that has such a trivial Python equivalent, unless there's a clear need for it (e.g. for performance) in third-party projects.
The text was updated successfully, but these errors were encountered: