-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
C API: Cython 3.0 uses private functions removed in Python 3.13 (numpy 1.25.1 fails to build) #107076
Comments
The public |
The public Is a fast unsafe replacement needed here? Where unsafe means: without error checking (use assertions instead). |
Well. It would be more fair in comparison, although that's barely a reason. For the case that characters are copied between different unicode string types a lot, especially for loads of short strings, this difference would probably be visible, i.e. Py3.13 would appear slower than Py3.12 here. But proving that would require a proper, realistic benchmark. I'll use the public function in Cython on Py3.13 for now and wait for an actual user to complain. |
It's unclear to me why Python exposes an API to modify immutable strings 😁 I'm considering adding a public API for _PyUnicodeWriter which may cover _PyUnicode_FastCopyCharacters() usecase. I'm also open to expose _PyUnicode_FastCopyCharacters() in public with an appropriate documentation. |
This isn't true - it's documented badly. #107140 I mention it because the misleading documentation caught us out when trying to replace it (and you out in the comment above) |
(Deleted previous comment because it wasn't quite right). The The use case in |
I'm not asking Cython to use slower code path on purpose. I created this issue to discuss which private functions are used by Cython and see what can be done to provide better APIs for Cython. |
By the way, the main branch of Cython uses the following private _PyDict functions:
Maybe we should consider making them public, or Cython should avoid them (which can have a negative effect on performance). See PR #107145. I kept these functions for now, to not make break Cython more :-) |
@da-woods has collected a list of CPython internals that we use in cython/cython#4635 All of these (minus bugs) are guarded by version checks or feature flags (like I think the dict internals only use version checks, probably because the dict implementation tends to change every couple of releases. In any case, there is always generic fallback code that only relies on public C-API features, usually for other Python implementations than CPython, or for the Limited API compilation mode. |
I totally get it and I create this issue to discuss that: should we expose these private functions? If they help to make C extensions faster, maybe we should expose them so more C extensions can benefit from them. |
I afraid that it is a preliminary optimization, because every dict lookup function first at all checks whether the key is a string with the cached hash, and then does a straight lookup. The overhead is virtually just the comparison of two pointers.
|
See also #89410 "[C API] Add explicit support for Cython to the C API". |
I mark this issue as duplicate of #89410 |
Similarly, nanosvg (bundled with wxPython) fails to compile with Python 3.13 because cython generates code that uses private Python API functions whose signatures have changed (namely, |
I suggest to use the new APIs: |
Newer versions of Cython fix the problem, but I agree that it would be better for Cython to not be using private API functions where possible. |
numpy 1.25.1 fails to build on Python 3.13: Cython uses private C API removed in Python 3.13. Example of build errors.
I open an issue since Python 3.13 does not provide obvious replacement for these removed functions.
(1) Cython uses removed _PyInterpreterState_GetConfig():
(2) Cython uses removed _PyVectorcall_Function() in __Pyx_PyObject_FastCallDict():
(3) Cython uses removed _PyUnicode_FastCopyCharacters() in __Pyx_PyUnicode_ConcatInPlaceImpl()
But also in __Pyx_PyUnicode_Join():
The text was updated successfully, but these errors were encountered: