diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-01-21 19:30:14 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-01-21 20:18:53 +0000 |
commit | 111a71ccee31df3892de6b46c66beb4a65362110 (patch) | |
tree | b09673fb26e5270c3a102a6cac018a7baa63e2fa | |
parent | 1839806c3cf972be3358263c3c4f33aed1f3f093 (diff) | |
download | psycopg2-111a71ccee31df3892de6b46c66beb4a65362110.tar.gz |
Dropped psyco_errors_fill()
Just use psyco_errors_init() for complete errors initialization
-rw-r--r-- | psycopg/psycopgmodule.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index a760f44..1a2cccf 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -657,7 +657,7 @@ static struct { static int -psyco_errors_init(void) +psyco_errors_init(PyObject *module) { /* the names of the exceptions here reflect the organization of the psycopg2 module and not the fact the the original error objects @@ -678,7 +678,7 @@ psyco_errors_init(void) if (exctable[i].docstr) { if (!(str = Text_FromUTF8(exctable[i].docstr))) { goto exit; } - if (0 != PyDict_SetItemString(dict, "__doc__", str)) { goto exit; } + if (0 > PyDict_SetItemString(dict, "__doc__", str)) { goto exit; } Py_CLEAR(str); } @@ -693,31 +693,29 @@ psyco_errors_init(void) Py_CLEAR(dict); } - rv = 0; - -exit: - Py_XDECREF(str); - Py_XDECREF(dict); - return rv; -} - -void -psyco_errors_fill(PyObject *dict) -{ - int i; - char *name; - for (i = 0; exctable[i].name; i++) { + char *name; if (NULL == exctable[i].exc) { continue; } /* the name is the part after the last dot */ name = strrchr(exctable[i].name, '.'); name = name ? name + 1 : exctable[i].name; - PyDict_SetItemString(dict, name, *exctable[i].exc); + Py_INCREF(*exctable[i].exc); + if (0 > PyModule_AddObject(module, name, *exctable[i].exc)) { + goto exit; + } } + + rv = 0; + +exit: + Py_XDECREF(str); + Py_XDECREF(dict); + return rv; } + RAISES_NEG static int add_module_constants(PyObject *module) @@ -983,8 +981,7 @@ INIT_MODULE(_psycopg)(void) if (0 != psyco_adapters_init(dict)) { goto exit; } /* create a standard set of exceptions and add them to the module's dict */ - if (0 != psyco_errors_init()) { goto exit; } - psyco_errors_fill(dict); + if (0 != psyco_errors_init(module)) { goto exit; } Dprintf("psycopgmodule: module initialization complete"); |