diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-01-22 13:54:06 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-01-23 09:46:18 +0000 |
commit | 65a2a18a1baee52da372c931230163fed407f81a (patch) | |
tree | 6ef511ffe62457643831fc5b934b6de884211eeb /psycopg/microprotocols.c | |
parent | 66d5c6da0728640b2312c5e55a642a5ebb4e72e2 (diff) | |
download | psycopg2-module-init-cleanup.tar.gz |
General cleanup of module init shenanigansmodule-init-cleanup
Pass around the module instead of its dict (getting the latter is fast
if needed), mark function raising with negative results, check all errors,
consistent names...
Diffstat (limited to 'psycopg/microprotocols.c')
-rw-r--r-- | psycopg/microprotocols.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/psycopg/microprotocols.c b/psycopg/microprotocols.c index 0e74cee..1139519 100644 --- a/psycopg/microprotocols.c +++ b/psycopg/microprotocols.c @@ -38,15 +38,19 @@ PyObject *psyco_adapters; /* microprotocols_init - initialize the adapters dictionary */ -int -microprotocols_init(PyObject *dict) +RAISES_NEG int +microprotocols_init(PyObject *module) { /* create adapters dictionary and put it in module namespace */ - if ((psyco_adapters = PyDict_New()) == NULL) { + if (!(psyco_adapters = PyDict_New())) { return -1; } - PyDict_SetItemString(dict, "adapters", psyco_adapters); + Py_INCREF(psyco_adapters); + if (0 > PyModule_AddObject(module, "adapters", psyco_adapters)) { + Py_DECREF(psyco_adapters); + return -1; + } return 0; } @@ -56,7 +60,7 @@ microprotocols_init(PyObject *dict) * * Return 0 on success, else -1 and set an exception. */ -int +RAISES_NEG int microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast) { PyObject *key = NULL; |