-
-
Notifications
You must be signed in to change notification settings - Fork 101
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 the CPython 3.9+ C-API usage to use newer macros #864
Adapt the CPython 3.9+ C-API usage to use newer macros #864
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #864 +/- ##
=======================================
Coverage 93.65% 93.65%
=======================================
Files 5 5
Lines 504 504
=======================================
Hits 472 472
Misses 32 32 ☔ View full report in Codecov by Sentry. |
Thanks for the PR, I've confirmed there's a segmentation fault on all three OS on the CI for Python 3.12 (https://github.com/hugovk/multidict/actions/runs/6028022143), and the commits from this PR fixes it (https://github.com/hugovk/multidict/actions/runs/6029781394). See also #877 (comment). |
multidict/_multilib/istr.h
Outdated
@@ -43,7 +43,11 @@ istr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |||
if (!ret) { | |||
goto fail; | |||
} | |||
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 9 | |||
s = PyObject_CallMethod(ret, "lower", NULL); |
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.
I hope it is not performance-sensitive code. Otherwise it it would be better to use a cached value.
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.
Please look last changes, I moved multidict_str_lower
to global vars and use it here and in pair_list
multidict/_multilib/pair_list.h
Outdated
{ | ||
PyObject *str_lower = PyUnicode_InternFromString("lower"); |
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.
Rather of caching string object "lower", it may be better to cache method object str.lower
.
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.
str.lower
can't work with CallMethod
@@ -777,9 +785,12 @@ multidict_add(MultiDictObject *self, PyObject *const *args, | |||
return NULL; | |||
} | |||
#else | |||
static _PyArg_Parser _parser = {NULL, _keywords, "add", 0}; | |||
static _PyArg_Parser _parser = { |
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.
Why this method needs keyword parameters at all?
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.
We have a test for it https://github.com/aio-libs/multidict/blob/master/tests/test_mutable_multidict.py#L333
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.
But why does such test exist at first place?
_PyArg_Parser
is a deep internal tool, it is not purposed to be used outside of CPython. It is expected that the third-party code uses good old and slow PyArg_ParseTupleAndKeywords
for parsing keyword arguments, or handle it by hand-made code.
It is out of the scope of this issue, but I would consider deprecating accepting keyword arguments in this function.
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.
This can be done in another PR
Any news on this? We're thinking about backporting this patch in conda-forge to the last released, in order to unbreak things. It's always preferable though if the respective patches are merged upstream first. |
We also backported this PR in AnacondaRecipes/multidict-feedstock#7 |
merging pulls 828, 829, 864 reduce quite a bit the compiling complains on windows |
This is still failing to build with py313 (Python 3.13.0a2+)
|
0ba9381
to
7eedf67
Compare
This patch replaces the C-APIs that have been deprecated in Python 3.9 and later removed in 3.13.
What do these changes do?
Are there changes in behavior for the user?
No
Related issue number
Fixes #862