Skip to content

Commit

Permalink
Issue python#117: Code cleanup: simplify the anti-link-optimiser code…
Browse files Browse the repository at this point in the history
… in slp_eval_frame_*()

This change simplifies the code, that prevents the link optimiser to optimise away the identical functions slp_eval_frame_*(). The new code is simpler, faster and makes the overall reference counting less hard to understand.
(grafted from 72d9447daf24f9441289784714c307f4e1d5e79f)
  • Loading branch information
Anselm Kruis committed Feb 13, 2017
1 parent 0d3af5e commit d5696be
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
return NULL;
}

/* a global write only dummy variable */
char _dont_optimise_away_slp_eval_frame_functions;

PyObject *
slp_eval_frame_noval(PyFrameObject *f, int throwflag, PyObject *retval)
{
Expand All @@ -1232,9 +1235,8 @@ slp_eval_frame_noval(PyFrameObject *f, int throwflag, PyObject *retval)
* it serves as a marker whether we expect a value or
* not, and it makes debugging a little easier.
*/
Py_XINCREF(f); /* fool the link optimizer */
_dont_optimise_away_slp_eval_frame_functions = 1;
r = slp_eval_frame_value(f, throwflag, retval);
Py_XDECREF(f);
return r;
}

Expand All @@ -1248,9 +1250,8 @@ slp_eval_frame_iter(PyFrameObject *f, int throwflag, PyObject *retval)
* for_iter operation. In this case we need to handle
* null without error as valid result.
*/
Py_XINCREF(retval); /* fool the link optimizer */
_dont_optimise_away_slp_eval_frame_functions = 2;
r = slp_eval_frame_value(f, throwflag, retval);
Py_XDECREF(retval);
return r;
}

Expand All @@ -1264,11 +1265,8 @@ slp_eval_frame_setup_with(PyFrameObject *f, int throwflag, PyObject *retval)
* SETUP_WITH operation.
* NOTE / XXX: see above.
*/
Py_XINCREF(f); /* fool the link optimizer */
Py_XINCREF(retval); /* fool the link optimizer */
_dont_optimise_away_slp_eval_frame_functions = 3;
r = slp_eval_frame_value(f, throwflag, retval);
Py_XDECREF(retval);
Py_XDECREF(f);
return r;
}

Expand All @@ -1282,11 +1280,8 @@ slp_eval_frame_with_cleanup(PyFrameObject *f, int throwflag, PyObject *retval)
* WITH_CLEANUP operation.
* NOTE / XXX: see above.
*/
Py_XINCREF(f); /* fool the link optimizer */
Py_XINCREF(f); /* fool the link optimizer */
_dont_optimise_away_slp_eval_frame_functions = 4;
r = slp_eval_frame_value(f, throwflag, retval);
Py_XDECREF(f);
Py_XDECREF(f);
return r;
}

Expand Down

0 comments on commit d5696be

Please sign in to comment.