Kaydet (Commit) 3ab7b0aa authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Simplify example of PyErr_Fetch() use

üst 4ebc9295
...@@ -962,10 +962,9 @@ done. This can be done using the :c:func:`PyErr_Fetch` and ...@@ -962,10 +962,9 @@ done. This can be done using the :c:func:`PyErr_Fetch` and
if (self->my_callback != NULL) { if (self->my_callback != NULL) {
PyObject *err_type, *err_value, *err_traceback; PyObject *err_type, *err_value, *err_traceback;
int have_error = PyErr_Occurred() ? 1 : 0;
if (have_error) /* This saves the current exception state */
PyErr_Fetch(&err_type, &err_value, &err_traceback); PyErr_Fetch(&err_type, &err_value, &err_traceback);
cbresult = PyObject_CallObject(self->my_callback, NULL); cbresult = PyObject_CallObject(self->my_callback, NULL);
if (cbresult == NULL) if (cbresult == NULL)
...@@ -973,8 +972,8 @@ done. This can be done using the :c:func:`PyErr_Fetch` and ...@@ -973,8 +972,8 @@ done. This can be done using the :c:func:`PyErr_Fetch` and
else else
Py_DECREF(cbresult); Py_DECREF(cbresult);
if (have_error) /* This restores the saved exception state */
PyErr_Restore(err_type, err_value, err_traceback); PyErr_Restore(err_type, err_value, err_traceback);
Py_DECREF(self->my_callback); Py_DECREF(self->my_callback);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment