-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-132775: Expand the Capability of Interpreter.call() #133484
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
gh-132775: Expand the Capability of Interpreter.call() #133484
Conversation
4fdc11a
to
4327098
Compare
27d83f1
to
f9f7666
Compare
f9f7666
to
b8171d9
Compare
def call(self, callable, /, *args, **kwargs): | ||
"""Call the object in the interpreter with given args/kwargs. | ||
|
||
Only functions that take no arguments and have no closure |
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.
The docstring looks partially outdated (here or in Lib/interpreters/__init__.py
). The same would apply for _interpretersmodule.c
?
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.
fixed
d58f54e
to
4152f17
Compare
4152f17
to
d173ec0
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
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 review focuses on the refleaks in test_api
(Py_GIL_DISABLED
seems to skip the test).
_PyFunction_VerifyStateless:
Line 1267 in 0d499c7
if (defaults != NULL && defaults != Py_None && PyDict_Size(defaults) > 0) |
PyDict_Size(defaults)
needsPyDict_Check()
or_PyErr_Clear()
.- The same goes for
PyDict_Size(kwdefaults)
at L1275.
Modules/_interpretersmodule.c
Outdated
struct interp_call temp = *call; | ||
*call = (struct interp_call){0}; | ||
if (temp.func != NULL) { | ||
_PyXIData_Clear(NULL, temp.func); |
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.
_PyXIData_Clear()
here does not work expectedly on MSVC.
struct interp_call temp = *call;
printf("before: %p %p %p\n", temp.func, temp.func->data, temp.func->obj);
*call = (struct interp_call){0};
printf("after : %p %p %p\n", temp.func, temp.func->data, temp.func->obj);
before: 0000000000C3CF58 00000000057763B0 0000000002BFCEF0
after : 0000000000C3CF58 0000000000000000 0000000000000000
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.
Yeah, the logic here is wrong because the pointers in temp
point to the call
fields, which have been nulled out. I'm fixing that.
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.
fixed
Modules/_interpretersmodule.c
Outdated
PyObject *exc = _PyErr_GetRaisedException(tstate); | ||
if (_PyPickle_GetXIData(tstate, func, &call->_preallocated.func) < 0) { | ||
_PyErr_SetRaisedException(tstate, exc); | ||
//unwrap_not_shareable(tstate); | ||
return -1; | ||
} |
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.
Py_DECREF(exc)
seems missing after L472.
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.
fixed
} | ||
|
||
_PyXI_FreeSession(session); | ||
return res; |
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.
Py_CLEAR(result.preserved)
before L665 seems effective?
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.
fixed
Modules/_interpretersmodule.c
Outdated
PyObject *func, *args, *kwargs; | ||
if (_interp_call_unpack(call, &func, &args, &kwargs) == 0) { | ||
// Either the problem is intermittent or only affects subinterpreters. | ||
// This is highly unlikely. |
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.
Py_DECREF(func); Py_DECREF(args); Py_XDECREF(kwargs);
?
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.
fixed
if (kwargs_obj != NULL) { | ||
_PyErr_SetString(tstate, PyExc_ValueError, "got unexpected kwargs"); | ||
struct interp_call call = {0}; | ||
if (_interp_call_pack(tstate, &call, callable, args_obj, kwargs_obj) < 0) { |
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.
_interp_call_clear(&call)
in the branch?
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.
fixed
Nice catch. I also got it wrong with |
!buildbot AMD64 Fedora Stable Refleaks |
🤖 New build scheduled with the buildbot fleet by @ericsnowcurrently for commit 17beeda 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133484%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
@neonene, thanks again for all the help chasing down leaks! You saved me a bunch of time. |
Unless there are any objections, I'll merge this first thing in the morning (~16:00 UTC). |
Thanks @ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…h-133484) It now supports most callables, full args, and return values. (cherry picked from commit 52deabe) Co-authored-by: Eric Snow <[email protected]>
GH-134933 is a backport of this pull request to the 3.14 branch. |
) It now supports most callables, full args, and return values. (cherry picked from commit 52deabe, AKA gh-133484) Co-authored-by: Eric Snow [email protected]
It now supports most callables, full args, and return values.