-
Notifications
You must be signed in to change notification settings - Fork 319
Mnt py310 compat #636
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
Mnt py310 compat #636
Conversation
There was a change in the CPython c-api to change `Py_TYPE` from a macro to an inline function (python/cpython#20290). This requires a change to using `Py_SET_TYPE` which was introduced on py39a4.
Thank you for the patch. The code in question probably dates back to ancient pythons, is there a way to get equivalent functionality using modern c api methods that work in python 3.5+? |
With this patch (which includes a compatibility macro) it should work with all py35+ so in the most trivial sense I think the answer is yes. If the question is how to refactor this code to avoid using |
I do not think it is appropriate for pycurl to define macros provided by python. If python provides a standard API that replaces |
Python only provides this macro for py39a4 . Defining the macro for earlier versions of Python means that you can put the version check in exactly one place in your code. I guess another option is to wrap the three offending lines in the #if PY_VERSION_HEX >= 0x030900a4
Py_SET_TYPE(&Curl_Type, &PyType_Type);
Py_SET_TYPE(&CurlMulti_Type, &PyType_Type);
Py_SET_TYPE(&CurlShare_Type, &PyType_Type);
#else
Py_TYPE(&Curl_Type) = &PyType_Type;
Py_TYPE(&CurlMulti_Type) = &PyType_Type;
Py_TYPE(&CurlShare_Type) = &PyType_Type;
#endif but I am not sure that is clearer. Using a compatibilty macro like I proposed is what both numpy and cython have done. |
Please find out a public Python API that accomplishes the desired effect in all supported Python versions. If this is not possible please link to a discussion/statement from Python developers where they are stating that the only way to write a Python extension is to use Python version checks as proposed in this PR. |
Please see the link in my initial post and the links back to bpo. This is how @vstinner (core CPython dev) fixed the issue in cython cython/cython@d8e93b3 and how it was fixed in numpy numpy/numpy#16417 I guess you could go with the method Victor describes in MagicStack/immutables#46 as well. With out this patch pycurl does not compile with cpython master and will be broken with py310. |
Okay. My web search is not returning any results for |
If you want to use
|
Co-authored-by: Victor Stinner <vstinner@python.org>
Why wrap the call in a |
It's an old habbit that I have, it's to reduce the risks of https://gcc.gnu.org/onlinedocs/cpp/Macro-Pitfalls.html It helps when using a macro in an For this specific macro, maybe it's safe without it. |
What does |
Merged in #660. |
There was a change in the CPython c-api to change
Py_TYPE
from a macro to an inline function (python/cpython#20290). This requires a change to usingPy_SET_TYPE
which was introduced on py39a4.