summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-07-03 21:48:31 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-07-03 21:48:31 (GMT)
commit878802435d5839f54b49f1537eeca6dce330569c (patch)
tree03f30113b403595b5e91e22c590e424cb5b445ca /Python
parent536feac7f863c64f32c3bba492b79ddf03323373 (diff)
downloadcpython-878802435d5839f54b49f1537eeca6dce330569c.zip
cpython-878802435d5839f54b49f1537eeca6dce330569c.tar.gz
cpython-878802435d5839f54b49f1537eeca6dce330569c.tar.bz2
convert generator exc state functions into static functions
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c116
1 files changed, 62 insertions, 54 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 1dd0d49..5a5e23c5 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -749,6 +749,9 @@ enum why_code {
WHY_SILENCED = 0x0080 /* Exception silenced by 'with' */
};
+static void save_exc_state(PyThreadState *, PyFrameObject *);
+static void swap_exc_state(PyThreadState *, PyFrameObject *);
+static void restore_and_clear_exc_state(PyThreadState *, PyFrameObject *);
static enum why_code do_raise(PyObject *, PyObject *);
static int unpack_iterable(PyObject *, int, int, PyObject **);
@@ -1110,54 +1113,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
Py_XDECREF(traceback); \
}
-#define SAVE_EXC_STATE() \
- { \
- PyObject *type, *value, *traceback; \
- Py_XINCREF(tstate->exc_type); \
- Py_XINCREF(tstate->exc_value); \
- Py_XINCREF(tstate->exc_traceback); \
- type = f->f_exc_type; \
- value = f->f_exc_value; \
- traceback = f->f_exc_traceback; \
- f->f_exc_type = tstate->exc_type; \
- f->f_exc_value = tstate->exc_value; \
- f->f_exc_traceback = tstate->exc_traceback; \
- Py_XDECREF(type); \
- Py_XDECREF(value); \
- Py_XDECREF(traceback); \
- }
-
-#define SWAP_EXC_STATE() \
- { \
- PyObject *tmp; \
- tmp = tstate->exc_type; \
- tstate->exc_type = f->f_exc_type; \
- f->f_exc_type = tmp; \
- tmp = tstate->exc_value; \
- tstate->exc_value = f->f_exc_value; \
- f->f_exc_value = tmp; \
- tmp = tstate->exc_traceback; \
- tstate->exc_traceback = f->f_exc_traceback; \
- f->f_exc_traceback = tmp; \
- }
-
-#define RESTORE_AND_CLEAR_EXC_STATE() \
- { \
- PyObject *type, *value, *tb; \
- type = tstate->exc_type; \
- value = tstate->exc_value; \
- tb = tstate->exc_traceback; \
- tstate->exc_type = f->f_exc_type; \
- tstate->exc_value = f->f_exc_value; \
- tstate->exc_traceback = f->f_exc_traceback; \
- f->f_exc_type = NULL; \
- f->f_exc_value = NULL; \
- f->f_exc_traceback = NULL; \
- Py_XDECREF(type); \
- Py_XDECREF(value); \
- Py_XDECREF(tb); \
- }
-
/* Start of code */
if (f == NULL)
@@ -1236,11 +1191,10 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
/* We were in an except handler when we left,
restore the exception state which was put aside
(see YIELD_VALUE). */
- SWAP_EXC_STATE();
- }
- else {
- SAVE_EXC_STATE();
+ swap_exc_state(tstate, f);
}
+ else
+ save_exc_state(tstate, f);
}
#ifdef LLTRACE
@@ -3033,9 +2987,9 @@ fast_yield:
break;
if (i == f->f_iblock)
/* We did not create this exception. */
- RESTORE_AND_CLEAR_EXC_STATE()
+ restore_and_clear_exc_state(tstate, f);
else
- SWAP_EXC_STATE()
+ swap_exc_state(tstate, f);
}
if (tstate->use_tracing) {
@@ -3453,6 +3407,60 @@ special_lookup(PyObject *o, char *meth, PyObject **cache)
}
+/* These 3 functions deal with the exception state of generators. */
+
+static void
+save_exc_state(PyThreadState *tstate, PyFrameObject *f)
+{
+ PyObject *type, *value, *traceback;
+ Py_XINCREF(tstate->exc_type);
+ Py_XINCREF(tstate->exc_value);
+ Py_XINCREF(tstate->exc_traceback);
+ type = f->f_exc_type;
+ value = f->f_exc_value;
+ traceback = f->f_exc_traceback;
+ f->f_exc_type = tstate->exc_type;
+ f->f_exc_value = tstate->exc_value;
+ f->f_exc_traceback = tstate->exc_traceback;
+ Py_XDECREF(type);
+ Py_XDECREF(value);
+ Py_XDECREF(traceback);
+}
+
+static void
+swap_exc_state(PyThreadState *tstate, PyFrameObject *f)
+{
+ PyObject *tmp;
+ tmp = tstate->exc_type;
+ tstate->exc_type = f->f_exc_type;
+ f->f_exc_type = tmp;
+ tmp = tstate->exc_value;
+ tstate->exc_value = f->f_exc_value;
+ f->f_exc_value = tmp;
+ tmp = tstate->exc_traceback;
+ tstate->exc_traceback = f->f_exc_traceback;
+ f->f_exc_traceback = tmp;
+}
+
+static void
+restore_and_clear_exc_state(PyThreadState *tstate, PyFrameObject *f)
+{
+ PyObject *type, *value, *tb;
+ type = tstate->exc_type;
+ value = tstate->exc_value;
+ tb = tstate->exc_traceback;
+ tstate->exc_type = f->f_exc_type;
+ tstate->exc_value = f->f_exc_value;
+ tstate->exc_traceback = f->f_exc_traceback;
+ f->f_exc_type = NULL;
+ f->f_exc_value = NULL;
+ f->f_exc_traceback = NULL;
+ Py_XDECREF(type);
+ Py_XDECREF(value);
+ Py_XDECREF(tb);
+}
+
+
/* Logic for the raise statement (too complicated for inlining).
This *consumes* a reference count to each of its arguments. */
static enum why_code