Skip to content

Commit 53c204e

Browse files
committed
GET_AITER (had to restructure it some)
The original had mysterious `SET_TOP(NULL)` before `goto error`. I assume those just account for `obj` having been decref'ed, so I got rid of them in favor of the cleanup implied by `ERROR_IF()`.
1 parent e2f376b commit 53c204e

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

Python/bytecodes.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ do { \
8282
static PyObject *value, *value1, *value2, *left, *right, *res, *sum, *prod, *sub;
8383
static PyObject *container, *start, *stop, *v, *lhs, *rhs;
8484
static PyObject *list, *tuple, *dict, *owner;
85-
static PyObject *exit_func, *lasti, *val, *retval;
85+
static PyObject *exit_func, *lasti, *val, *retval, *obj, *iter;
8686
static size_t jump;
8787
// Dummy variables for cache effects
8888
static _Py_CODEUNIT when_to_jump_mask, invert, counter, index, hint;
@@ -616,48 +616,37 @@ dummy_func(
616616
goto resume_frame;
617617
}
618618

619-
// stack effect: ( -- )
620-
inst(GET_AITER) {
619+
inst(GET_AITER, (obj -- iter)) {
621620
unaryfunc getter = NULL;
622-
PyObject *iter = NULL;
623-
PyObject *obj = TOP();
624621
PyTypeObject *type = Py_TYPE(obj);
625622

626623
if (type->tp_as_async != NULL) {
627624
getter = type->tp_as_async->am_aiter;
628625
}
629626

630-
if (getter != NULL) {
631-
iter = (*getter)(obj);
632-
Py_DECREF(obj);
633-
if (iter == NULL) {
634-
SET_TOP(NULL);
635-
goto error;
636-
}
637-
}
638-
else {
639-
SET_TOP(NULL);
627+
if (getter == NULL) {
640628
_PyErr_Format(tstate, PyExc_TypeError,
641629
"'async for' requires an object with "
642630
"__aiter__ method, got %.100s",
643631
type->tp_name);
644632
Py_DECREF(obj);
645-
goto error;
633+
ERROR_IF(1, error);
646634
}
647635

636+
iter = (*getter)(obj);
637+
Py_DECREF(obj);
638+
ERROR_IF(iter == NULL, error);
639+
648640
if (Py_TYPE(iter)->tp_as_async == NULL ||
649641
Py_TYPE(iter)->tp_as_async->am_anext == NULL) {
650642

651-
SET_TOP(NULL);
652643
_PyErr_Format(tstate, PyExc_TypeError,
653644
"'async for' received an object from __aiter__ "
654645
"that does not implement __anext__: %.100s",
655646
Py_TYPE(iter)->tp_name);
656647
Py_DECREF(iter);
657-
goto error;
648+
ERROR_IF(1, error);
658649
}
659-
660-
SET_TOP(iter);
661650
}
662651

663652
// stack effect: ( -- __0)

Python/generated_cases.c.h

Lines changed: 10 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)