Dropped hardcoded list of exceptions in init functions

Use the already available exctable array.

This stops the gcc-python-plugin complaining about access to potentially
uninitialized memory.
This commit is contained in:
Daniele Varrazzo 2012-02-23 20:09:28 +00:00
parent 09be4dc5d1
commit 3b36100ec1

View File

@ -565,41 +565,35 @@ exit:
void void
psyco_errors_fill(PyObject *dict) psyco_errors_fill(PyObject *dict)
{ {
PyDict_SetItemString(dict, "Error", Error); int i;
PyDict_SetItemString(dict, "Warning", Warning); char *name;
PyDict_SetItemString(dict, "InterfaceError", InterfaceError);
PyDict_SetItemString(dict, "DatabaseError", DatabaseError); for (i = 0; exctable[i].name; i++) {
PyDict_SetItemString(dict, "InternalError", InternalError); if (NULL == exctable[i].exc) { continue; }
PyDict_SetItemString(dict, "OperationalError", OperationalError);
PyDict_SetItemString(dict, "ProgrammingError", ProgrammingError); /* the name is the part after the last dot */
PyDict_SetItemString(dict, "IntegrityError", IntegrityError); name = strrchr(exctable[i].name, '.');
PyDict_SetItemString(dict, "DataError", DataError); name = name ? name + 1 : exctable[i].name;
PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
#ifdef PSYCOPG_EXTENSIONS PyDict_SetItemString(dict, name, *exctable[i].exc);
PyDict_SetItemString(dict, "QueryCanceledError", QueryCanceledError); }
PyDict_SetItemString(dict, "TransactionRollbackError",
TransactionRollbackError);
#endif
} }
void void
psyco_errors_set(PyObject *type) psyco_errors_set(PyObject *type)
{ {
PyObject_SetAttrString(type, "Error", Error); int i;
PyObject_SetAttrString(type, "Warning", Warning); char *name;
PyObject_SetAttrString(type, "InterfaceError", InterfaceError);
PyObject_SetAttrString(type, "DatabaseError", DatabaseError); for (i = 0; exctable[i].name; i++) {
PyObject_SetAttrString(type, "InternalError", InternalError); if (NULL == exctable[i].exc) { continue; }
PyObject_SetAttrString(type, "OperationalError", OperationalError);
PyObject_SetAttrString(type, "ProgrammingError", ProgrammingError); /* the name is the part after the last dot */
PyObject_SetAttrString(type, "IntegrityError", IntegrityError); name = strrchr(exctable[i].name, '.');
PyObject_SetAttrString(type, "DataError", DataError); name = name ? name + 1 : exctable[i].name;
PyObject_SetAttrString(type, "NotSupportedError", NotSupportedError);
#ifdef PSYCOPG_EXTENSIONS PyObject_SetAttrString(type, name, *exctable[i].exc);
PyObject_SetAttrString(type, "QueryCanceledError", QueryCanceledError); }
PyObject_SetAttrString(type, "TransactionRollbackError",
TransactionRollbackError);
#endif
} }
/* psyco_error_new /* psyco_error_new