mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
gh-98831: rewrite GET_LEN, GET_ITER, BEFORE_WITH and a few simple opcodes in the instruction definition DSL (#101443)
This commit is contained in:
parent
909a674693
commit
29a858b85f
3 changed files with 59 additions and 69 deletions
43
Python/generated_cases.c.h
generated
43
Python/generated_cases.c.h
generated
|
|
@ -2460,16 +2460,15 @@
|
|||
}
|
||||
|
||||
TARGET(GET_LEN) {
|
||||
PyObject *obj = PEEK(1);
|
||||
PyObject *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);
|
||||
if (len_i < 0) goto error;
|
||||
len_o = PyLong_FromSsize_t(len_i);
|
||||
if (len_o == NULL) goto error;
|
||||
STACK_GROW(1);
|
||||
POKE(1, len_o);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
|
@ -2532,13 +2531,13 @@
|
|||
}
|
||||
|
||||
TARGET(GET_ITER) {
|
||||
PyObject *iterable = PEEK(1);
|
||||
PyObject *iter;
|
||||
/* before: [obj]; after [getiter(obj)] */
|
||||
PyObject *iterable = TOP();
|
||||
PyObject *iter = PyObject_GetIter(iterable);
|
||||
iter = PyObject_GetIter(iterable);
|
||||
Py_DECREF(iterable);
|
||||
SET_TOP(iter);
|
||||
if (iter == NULL)
|
||||
goto error;
|
||||
if (iter == NULL) goto pop_1_error;
|
||||
POKE(1, iter);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
|
@ -2736,8 +2735,12 @@
|
|||
}
|
||||
|
||||
TARGET(BEFORE_WITH) {
|
||||
PyObject *mgr = TOP();
|
||||
PyObject *mgr = PEEK(1);
|
||||
PyObject *exit;
|
||||
PyObject *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)) {
|
||||
|
|
@ -2748,7 +2751,7 @@
|
|||
}
|
||||
goto 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,
|
||||
|
|
@ -2760,14 +2763,16 @@
|
|||
Py_DECREF(enter);
|
||||
goto error;
|
||||
}
|
||||
SET_TOP(exit);
|
||||
Py_DECREF(mgr);
|
||||
res = _PyObject_CallNoArgs(enter);
|
||||
Py_DECREF(enter);
|
||||
if (res == NULL) {
|
||||
goto error;
|
||||
Py_DECREF(exit);
|
||||
if (true) goto pop_1_error;
|
||||
}
|
||||
PUSH(res);
|
||||
STACK_GROW(1);
|
||||
POKE(1, res);
|
||||
POKE(2, exit);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue