Message125723
+ 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. |
|
Date |
User |
Action |
Args |
2011-01-07 22:40:42 | vstinner | set | recipients:
+ vstinner, amaury.forgeotdarc, ideasman42 |
2011-01-07 22:40:42 | vstinner | set | messageid: <1294440042.57.0.210635224485.issue6284@psf.upfronthosting.co.za> |
2011-01-07 22:40:37 | vstinner | link | issue6284 messages |
2011-01-07 22:40:37 | vstinner | create | |
|