-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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-98831: rewrite GET_LEN, GET_ITER, BEFORE_WITH and a few simple opcodes in the instruction definition DSL #101443
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
26fc7a3
gh-98831: rewrite GET_LEN, GET_ITER, BEFORE_WITH and a few simple opc…
iritkatriel 6bfec26
goto instead of ERROR_IF to avoid leaks
iritkatriel 2ee6241
revert BEFORE_WITH
iritkatriel 0a5f78d
Revert "revert BEFORE_WITH"
iritkatriel a925498
fix refleak of exit when __enter__ raises
iritkatriel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2053,8 +2053,7 @@ dummy_func( | |
} | ||
} | ||
|
||
// stack effect: ( -- ) | ||
inst(JUMP_BACKWARD_NO_INTERRUPT) { | ||
inst(JUMP_BACKWARD_NO_INTERRUPT, (--)) { | ||
/* This bytecode is used in the `yield from` or `await` loop. | ||
* If there is an interrupt, we want it handled in the innermost | ||
* generator or coroutine, so we deliberately do not check it here. | ||
|
@@ -2063,18 +2062,12 @@ dummy_func( | |
JUMPBY(-oparg); | ||
} | ||
|
||
// stack effect: ( -- __0) | ||
inst(GET_LEN) { | ||
inst(GET_LEN, (obj -- obj, len_o)) { | ||
// PUSH(len(TOS)) | ||
Py_ssize_t len_i = PyObject_Length(TOP()); | ||
if (len_i < 0) { | ||
goto error; | ||
} | ||
PyObject *len_o = PyLong_FromSsize_t(len_i); | ||
if (len_o == NULL) { | ||
goto error; | ||
} | ||
PUSH(len_o); | ||
Py_ssize_t len_i = PyObject_Length(obj); | ||
ERROR_IF(len_i < 0, error); | ||
len_o = PyLong_FromSsize_t(len_i); | ||
ERROR_IF(len_o == NULL, error); | ||
} | ||
|
||
inst(MATCH_CLASS, (subject, type, names -- attrs)) { | ||
|
@@ -2110,15 +2103,11 @@ dummy_func( | |
ERROR_IF(values_or_none == NULL, error); | ||
} | ||
|
||
// stack effect: ( -- ) | ||
inst(GET_ITER) { | ||
inst(GET_ITER, (iterable -- iter)) { | ||
/* before: [obj]; after [getiter(obj)] */ | ||
PyObject *iterable = TOP(); | ||
PyObject *iter = PyObject_GetIter(iterable); | ||
Py_DECREF(iterable); | ||
SET_TOP(iter); | ||
if (iter == NULL) | ||
goto error; | ||
iter = PyObject_GetIter(iterable); | ||
DECREF_INPUTS(); | ||
ERROR_IF(iter == NULL, error); | ||
} | ||
|
||
// stack effect: ( -- ) | ||
|
@@ -2313,10 +2302,10 @@ dummy_func( | |
PREDICT(GET_AWAITABLE); | ||
} | ||
|
||
// stack effect: ( -- __0) | ||
inst(BEFORE_WITH) { | ||
PyObject *mgr = TOP(); | ||
PyObject *res; | ||
inst(BEFORE_WITH, (mgr -- exit, res)) { | ||
/* pop the context manager, push its __exit__ and the | ||
* value returned from calling its __enter__ | ||
*/ | ||
PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__enter__)); | ||
if (enter == NULL) { | ||
if (!_PyErr_Occurred(tstate)) { | ||
|
@@ -2325,9 +2314,9 @@ dummy_func( | |
"context manager protocol", | ||
Py_TYPE(mgr)->tp_name); | ||
} | ||
goto error; | ||
ERROR_IF(true, error); | ||
} | ||
PyObject *exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__exit__)); | ||
exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__exit__)); | ||
if (exit == NULL) { | ||
if (!_PyErr_Occurred(tstate)) { | ||
_PyErr_Format(tstate, PyExc_TypeError, | ||
|
@@ -2337,16 +2326,12 @@ dummy_func( | |
Py_TYPE(mgr)->tp_name); | ||
} | ||
Py_DECREF(enter); | ||
goto error; | ||
ERROR_IF(true, error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
} | ||
SET_TOP(exit); | ||
Py_DECREF(mgr); | ||
DECREF_INPUTS(); | ||
res = _PyObject_CallNoArgs(enter); | ||
Py_DECREF(enter); | ||
if (res == NULL) { | ||
goto error; | ||
} | ||
PUSH(res); | ||
ERROR_IF(res == NULL, error); | ||
} | ||
|
||
inst(WITH_EXCEPT_START, (exit_func, lasti, unused, val -- exit_func, lasti, unused, val, res)) { | ||
|
@@ -2469,8 +2454,7 @@ dummy_func( | |
GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS); | ||
} | ||
|
||
// stack effect: ( -- ) | ||
inst(KW_NAMES) { | ||
inst(KW_NAMES, (--)) { | ||
assert(kwnames == NULL); | ||
assert(oparg < PyTuple_GET_SIZE(consts)); | ||
kwnames = GETITEM(consts, oparg); | ||
|
@@ -3252,8 +3236,7 @@ dummy_func( | |
PEEK(oparg) = top; | ||
} | ||
|
||
// stack effect: ( -- ) | ||
inst(EXTENDED_ARG) { | ||
inst(EXTENDED_ARG, (--)) { | ||
assert(oparg); | ||
assert(cframe.use_tracing == 0); | ||
opcode = _Py_OPCODE(*next_instr); | ||
|
@@ -3262,8 +3245,7 @@ dummy_func( | |
DISPATCH_GOTO(); | ||
} | ||
|
||
// stack effect: ( -- ) | ||
inst(CACHE) { | ||
inst(CACHE, (--)) { | ||
Py_UNREACHABLE(); | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 believe this leaks a reference to
mgr
. You can either insert anotherDECREF_INPUTS()
before this line, or just keep thegoto error
. I prefer the latter, we're not going to require usingDECREF_INPUTS()
everywhere (it mostly exists because it would be useful with the register conversion).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'm was just looking at this. I added DECREF_INPUTS in these two places and it is still leaking something.
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 pushed the change with goto, still looking for the other leak.