STINNER Victor <victor.stin...@haypocalc.com> added the comment: + PyErr_Fetch(&error_type, &error_value, &error_traceback); + + PyErr_Clear();
I think that the call to PyErr_Clear() is useless, PyErr_Fetch() already cleared the exception. + /* clear the error */ + PyErr_Restore(error_type, error_value, error_traceback); + PyErr_Clear(); Why do you restore the error if you clear it directly? I think that at this position, there is no current exception. So it may be simplified as: Py_DECREF(error_type); Py_DECREF(error_value); Py_DECREF(error_traceback); I suppose here that all these 3 variables are not NULL. + if(! (string_io_mod= PyImport_ImportModule("io")) ) { + PyErr_Clear(); + return NULL; + } + else if (! (string_io= PyObject_CallMethod(string_io_mod, "StringIO", NULL))) { + PyErr_Clear(); + Py_DECREF(string_io_mod); + return NULL; + } + else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) { + PyErr_Clear(); + Py_DECREF(string_io_mod); + Py_DECREF(string_io); + return NULL; + } Minor style remark: you can remove the "else" keywords here. You should factorize the error handling at the end using "goto error;" with a error handler looking like: ------------ ... goto finally; error: PyErr_Clear(); Py_CLEAR(stringio_buf); finally: Py_XDECREF(string_io_mod); Py_XDECREF(string_io); Py_XDECREF(string_io_getvalue); return NULL; ------------ In my opinion, it's easier to maintain it, and more readable. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6284> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com