Skip to content

Commit e9253ee

Browse files
committed
Handle escapes in DECREF_INPUTS
1 parent 8fc5562 commit e9253ee

File tree

9 files changed

+2012
-757
lines changed

9 files changed

+2012
-757
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ PyAPI_FUNC(PyObject *) _PyEval_ImportName(PyThreadState *, _PyInterpreterFrame *
274274
PyAPI_FUNC(PyObject *)_PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs);
275275
PyAPI_FUNC(PyObject *)_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys);
276276
PyAPI_FUNC(void) _PyEval_MonitorRaise(PyThreadState *tstate, _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
277-
PyAPI_FUNC(int) _PyEval_UnpackIterableStackRef(PyThreadState *tstate, _PyStackRef v, int argcnt, int argcntafter, _PyStackRef *sp);
277+
PyAPI_FUNC(int) _PyEval_UnpackIterableStackRef(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, _PyStackRef *sp);
278278
PyAPI_FUNC(void) _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
279279
PyAPI_FUNC(PyObject **) _PyObjectArray_FromStackRefArray(_PyStackRef *input, Py_ssize_t nargs, PyObject **scratch);
280280

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_metadata.h

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

Python/bytecodes.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,16 +1378,16 @@ dummy_func(
13781378
}
13791379
}
13801380

1381-
tier1 inst(CLEANUP_THROW, (sub_iter_st, last_sent_val_st, exc_value_st -- none, value)) {
1381+
tier1 inst(CLEANUP_THROW, (sub_iter, last_sent_val, exc_value_st -- none, value)) {
13821382
PyObject *exc_value = PyStackRef_AsPyObjectBorrow(exc_value_st);
13831383
assert(throwflag);
13841384
assert(exc_value && PyExceptionInstance_Check(exc_value));
13851385

13861386
int matches = PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration);
13871387
if (matches) {
1388-
none = PyStackRef_None;
13891388
value = PyStackRef_FromPyObjectNew(((PyStopIterationObject *)exc_value)->value);
13901389
DECREF_INPUTS();
1390+
none = PyStackRef_None;
13911391
}
13921392
else {
13931393
_PyErr_SetRaisedException(tstate, Py_NewRef(exc_value));
@@ -1481,10 +1481,10 @@ dummy_func(
14811481
(void)counter;
14821482
}
14831483

1484-
op(_UNPACK_SEQUENCE, (seq -- output[oparg])) {
1485-
_PyStackRef *top = output + oparg;
1486-
int res = _PyEval_UnpackIterableStackRef(tstate, seq, oparg, -1, top);
1487-
DECREF_INPUTS();
1484+
op(_UNPACK_SEQUENCE, (seq -- output[oparg], top[0])) {
1485+
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
1486+
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg, -1, top);
1487+
Py_DECREF(seq_o);
14881488
ERROR_IF(res == 0, error);
14891489
}
14901490

@@ -1498,7 +1498,7 @@ dummy_func(
14981498
STAT_INC(UNPACK_SEQUENCE, hit);
14991499
val0 = PyStackRef_FromPyObjectNew(PyTuple_GET_ITEM(seq_o, 0));
15001500
val1 = PyStackRef_FromPyObjectNew(PyTuple_GET_ITEM(seq_o, 1));
1501-
DECREF_INPUTS();
1501+
PyStackRef_CLOSE(seq);
15021502
}
15031503

15041504
inst(UNPACK_SEQUENCE_TUPLE, (unused/1, seq -- values[oparg])) {
@@ -1530,10 +1530,10 @@ dummy_func(
15301530
DECREF_INPUTS();
15311531
}
15321532

1533-
inst(UNPACK_EX, (seq -- left[oparg & 0xFF], unused, right[oparg >> 8])) {
1534-
_PyStackRef *top = right + (oparg >> 8);
1535-
int res = _PyEval_UnpackIterableStackRef(tstate, seq, oparg & 0xFF, oparg >> 8, top);
1536-
DECREF_INPUTS();
1533+
inst(UNPACK_EX, (seq -- left[oparg & 0xFF], unused, right[oparg >> 8], top[0])) {
1534+
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
1535+
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg & 0xFF, oparg >> 8, top);
1536+
Py_DECREF(seq_o);
15371537
ERROR_IF(res == 0, error);
15381538
}
15391539

@@ -4809,9 +4809,11 @@ dummy_func(
48094809

48104810
assert(_PyEval_BinaryOps[oparg]);
48114811
PyObject *res_o = _PyEval_BinaryOps[oparg](lhs_o, rhs_o);
4812-
DECREF_INPUTS();
4813-
ERROR_IF(res_o == NULL, error);
4812+
if (res_o == NULL) {
4813+
ERROR_NO_POP();
4814+
}
48144815
res = PyStackRef_FromPyObjectSteal(res_o);
4816+
DECREF_INPUTS();
48154817
}
48164818

48174819
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP;

Python/ceval.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,16 +2017,14 @@ _PyEval_ExceptionGroupMatch(_PyInterpreterFrame *frame, PyObject* exc_value,
20172017
*/
20182018

20192019
int
2020-
_PyEval_UnpackIterableStackRef(PyThreadState *tstate, _PyStackRef v_stackref,
2020+
_PyEval_UnpackIterableStackRef(PyThreadState *tstate, PyObject *v,
20212021
int argcnt, int argcntafter, _PyStackRef *sp)
20222022
{
20232023
int i = 0, j = 0;
20242024
Py_ssize_t ll = 0;
20252025
PyObject *it; /* iter(v) */
20262026
PyObject *w;
20272027
PyObject *l = NULL; /* variable list */
2028-
2029-
PyObject *v = PyStackRef_AsPyObjectBorrow(v_stackref);
20302028
assert(v != NULL);
20312029

20322030
it = PyObject_GetIter(v);

0 commit comments

Comments
 (0)