Skip to content

Commit f84d339

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 97a5fed commit f84d339

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;
@@ -611,48 +611,37 @@ dummy_func(
611611
goto resume_frame;
612612
}
613613

614-
// stack effect: ( -- )
615-
inst(GET_AITER) {
614+
inst(GET_AITER, (obj -- iter)) {
616615
unaryfunc getter = NULL;
617-
PyObject *iter = NULL;
618-
PyObject *obj = TOP();
619616
PyTypeObject *type = Py_TYPE(obj);
620617

621618
if (type->tp_as_async != NULL) {
622619
getter = type->tp_as_async->am_aiter;
623620
}
624621

625-
if (getter != NULL) {
626-
iter = (*getter)(obj);
627-
Py_DECREF(obj);
628-
if (iter == NULL) {
629-
SET_TOP(NULL);
630-
goto error;
631-
}
632-
}
633-
else {
634-
SET_TOP(NULL);
622+
if (getter == NULL) {
635623
_PyErr_Format(tstate, PyExc_TypeError,
636624
"'async for' requires an object with "
637625
"__aiter__ method, got %.100s",
638626
type->tp_name);
639627
Py_DECREF(obj);
640-
goto error;
628+
ERROR_IF(1, error);
641629
}
642630

631+
iter = (*getter)(obj);
632+
Py_DECREF(obj);
633+
ERROR_IF(iter == NULL, error);
634+
643635
if (Py_TYPE(iter)->tp_as_async == NULL ||
644636
Py_TYPE(iter)->tp_as_async->am_anext == NULL) {
645637

646-
SET_TOP(NULL);
647638
_PyErr_Format(tstate, PyExc_TypeError,
648639
"'async for' received an object from __aiter__ "
649640
"that does not implement __anext__: %.100s",
650641
Py_TYPE(iter)->tp_name);
651642
Py_DECREF(iter);
652-
goto error;
643+
ERROR_IF(1, error);
653644
}
654-
655-
SET_TOP(iter);
656645
}
657646

658647
// 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)