Skip to content

Commit dddef02

Browse files
committed
Wrap PyIter_Send to return a struct for MSVC tailcall support
1 parent 5c0999c commit dddef02

5 files changed

Lines changed: 28 additions & 15 deletions

File tree

Include/internal/pycore_abstract.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ PyAPI_FUNC(int) _Py_convert_optional_to_non_negative_ssize_t(PyObject *, void *)
5959
// Export for 'math' shared extension.
6060
PyAPI_FUNC(PyObject*) _PyNumber_Index(PyObject *o);
6161

62+
typedef struct {
63+
PyObject *object;
64+
PySendResult kind;
65+
} PySendResultPair;
66+
67+
// Same as PyIter_Send but returns a struct for MSVC tailcall support
68+
PyAPI_FUNC(PySendResultPair) _PyIter_Send(PyObject *iter, PyObject *arg);
69+
6270
#ifdef __cplusplus
6371
}
6472
#endif

Modules/_testinternalcapi/test_cases.c.h

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

Objects/abstract.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,3 +2951,11 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
29512951
}
29522952
return PYGEN_ERROR;
29532953
}
2954+
2955+
PySendResultPair
2956+
_PyIter_Send(PyObject *iter, PyObject *arg)
2957+
{
2958+
PySendResultPair pair;
2959+
pair.kind = PyIter_Send(iter, arg, &pair.object);
2960+
return pair;
2961+
}

Python/bytecodes.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,15 +1705,14 @@ dummy_func(
17051705
DEAD(v);
17061706
}
17071707
else {
1708-
PyObject *retval_o;
17091708
PyObject *v_o = PyStackRef_AsPyObjectBorrow(v);
1710-
PySendResult what = PyIter_Send(receiver_o, v_o, &retval_o);
1711-
if (what == PYGEN_ERROR) {
1709+
PySendResultPair res = _PyIter_Send(receiver_o, v_o);
1710+
if (res.kind == PYGEN_ERROR) {
17121711
ERROR_NO_POP();
17131712
}
17141713
PyStackRef_CLOSE(v);
1715-
retval = PyStackRef_FromPyObjectSteal(retval_o);
1716-
if (what == PYGEN_RETURN) {
1714+
retval = PyStackRef_FromPyObjectSteal(res.object);
1715+
if (res.kind == PYGEN_RETURN) {
17171716
JUMPBY(oparg);
17181717
}
17191718
}

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)