mirror of
https://github.com/python/cpython.git
synced 2025-07-14 06:45:17 +00:00
gh-98831: rewrite CHECK_EG_MATCH opcode in the instruction definition DSL (#101269)
This commit is contained in:
parent
7589d713a1
commit
8c183cddd3
4 changed files with 27 additions and 58 deletions
|
@ -1894,44 +1894,24 @@ dummy_func(
|
|||
b = Py_NewRef((res^oparg) ? Py_True : Py_False);
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(CHECK_EG_MATCH) {
|
||||
PyObject *match_type = POP();
|
||||
inst(CHECK_EG_MATCH, (exc_value, match_type -- rest, match)) {
|
||||
if (check_except_star_type_valid(tstate, match_type) < 0) {
|
||||
Py_DECREF(match_type);
|
||||
goto error;
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(true, error);
|
||||
}
|
||||
|
||||
PyObject *exc_value = TOP();
|
||||
PyObject *match = NULL, *rest = NULL;
|
||||
match = NULL;
|
||||
rest = NULL;
|
||||
int res = exception_group_match(exc_value, match_type,
|
||||
&match, &rest);
|
||||
Py_DECREF(match_type);
|
||||
if (res < 0) {
|
||||
goto error;
|
||||
}
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0, error);
|
||||
|
||||
if (match == NULL || rest == NULL) {
|
||||
assert(match == NULL);
|
||||
assert(rest == NULL);
|
||||
goto error;
|
||||
}
|
||||
if (Py_IsNone(match)) {
|
||||
PUSH(match);
|
||||
Py_XDECREF(rest);
|
||||
}
|
||||
else {
|
||||
/* Total or partial match - update the stack from
|
||||
* [val]
|
||||
* to
|
||||
* [rest, match]
|
||||
* (rest can be Py_None)
|
||||
*/
|
||||
assert((match == NULL) == (rest == NULL));
|
||||
ERROR_IF(match == NULL, error);
|
||||
|
||||
SET_TOP(rest);
|
||||
PUSH(match);
|
||||
if (!Py_IsNone(match)) {
|
||||
PyErr_SetExcInfo(NULL, Py_NewRef(match), NULL);
|
||||
Py_DECREF(exc_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue