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
Adapt to C-API changes in CPython 3.13 #5767
Conversation
Looks OK except for running it on Github actions |
Yeah, CPython 3.13a1 is only freshly released. It'll become available eventually. This isn't meant for 3.0.4. |
For the record, we tried to use this with Python 3.13.0a1 in Fedora and we see:
|
Apparently, there was a huge CPython core initiative earlier this summer to break existing Python packages using their existing "private by convention" APIs. I'm yet to understand why this happened, why so much effort from their side was put into deliberate breakage of existing code. Some of the API functions are probably easy to replace, but we'll have to see how it goes. I don't see a replacement for |
…ks a lot like "0x03000000", whereas "0x030d0000" is easier to distinguish.
I think I got rid of the removed C-API calls. That was easy because all of them were using private C-API functions for which we have compatibility replacements that I just had to enable for Py3.13+. The replacement for |
…s is gone in Py3.13).
Unfortunately, I still have:
The rest is gone. |
I see there is a pull request open by you to get it back. I can wait, just wanted to report back. |
|
|
Also fix a test output check in Py3.13+: the error message starts with a capital letter in CPython.
I still get |
Ok, I'll try it myself. Or do you have a quick indication where this happens? A stacktrace would help. |
I have this traceback:
|
It looks like the CPython devs also tightened the C-API checks, and while doing that, might have made a couple of … interesting decisions. I'll investigate, but I'm really annoyed by this. |
I've tried to use the pure Python version of Cython to build lxml instead. This is what I get now:
|
The missing check in
Git blame says that this was added in 2011 so it isn't a new check, The associated comment says
I believe that's still true. I think what failing is cython/Cython/Utility/ObjectHandling.c Lines 3082 to 3086 in 526e1fc
The failure is:
So that seems like a reasonable failure. I think we just need to move the incref after. |
@@ -3066,7 +3075,7 @@ static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_le | |||
__Pyx_INCREF(*p_left); | |||
|
|||
// copy 'right' into the newly allocated area of 'left' | |||
#if PY_VERSION_HEX >= 0x030D0000 | |||
#if PY_VERSION_HEX >= 0x030d0000 | |||
if (unlikely(PyUnicode_CopyCharacters(*p_left, left_len, right, 0, right_len) < 0)) return NULL; | |||
#else | |||
_PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't propose a change because it goes outside what github considers the edited region, but this block should be:
}
// copy 'right' into the newly allocated area of 'left'
#if PY_VERSION_HEX >= 0x030d0000
if (unlikely(PyUnicode_CopyCharacters(*p_left, left_len, right, 0, right_len) < 0)) return NULL;
#else
_PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len);
#endif
__Pyx_INCREF(*p_left); // Incref accounts for the returned reference to *p_left
return *p_left;
The incref shouldn't happen on the return NULL
error path I believe.
…ET_ITEM() in a valid use case. See python/cpython#106168
…reference counting of the result and to make sure we only resize and copy into strings to which we own the only reference. Background is that PyUnicode_CopyCharacters() gained an additional check in Py3.13a1 that conflicts with our previous safety net of early incref-ing the resized string. See cython#5767 (comment)
I was able to build pyyaml (tests passed) and python-lxml (tests errored due to unrelated Python 3.13 incompatibility) with the pure Python version of Cython from this PR. |
I was also able to build Cython itself. |
And with the self-compiled Cython, I've successfully built a couple of other packages. |
|
I think this gets close enough to looking good that we should include it in 3.0.5. The test suite builds with some test failures. Given that Py3.13 is only in it's earliest alpha stage, I think it's important to unblock dependent projects by having a Cython release that allows them to build and test. I'll merge this and fix the remaining issues later. |
Thank you so much for getting this into a buildable state despite all the hurdles. |
No description provided.