summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-01-21 19:13:05 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-01-21 20:18:53 +0000
commit1839806c3cf972be3358263c3c4f33aed1f3f093 (patch)
treee349ac961353afea14dfd1f5bfdeee041df5249f
parent8f17ccf784abe5ae79468c8f72e9a799551f9fc5 (diff)
downloadpsycopg2-1839806c3cf972be3358263c3c4f33aed1f3f093.tar.gz
Dropped project wide type to define encodings table
-rw-r--r--psycopg/psycopg.h5
-rw-r--r--psycopg/psycopgmodule.c35
2 files changed, 21 insertions, 19 deletions
diff --git a/psycopg/psycopg.h b/psycopg/psycopg.h
index c7591c9..365a57c 100644
--- a/psycopg/psycopg.h
+++ b/psycopg/psycopg.h
@@ -59,11 +59,6 @@ extern HIDDEN PyObject *psycoEncodings;
/* SQL NULL */
extern HIDDEN PyObject *psyco_null;
-typedef struct {
- char *pgenc;
- char *pyenc;
-} encodingPair;
-
/* Exceptions docstrings */
#define Error_doc \
"Base class for error exceptions."
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 565adeb..a760f44 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -503,11 +503,11 @@ exit:
}
-/* psyco_encodings_fill
-
- Fill the module's postgresql<->python encoding table */
-
-static encodingPair encodings[] = {
+/* Fill the module's postgresql<->python encoding table */
+static struct {
+ char *pgenc;
+ char *pyenc;
+} enctable[] = {
{"ABC", "cp1258"},
{"ALT", "cp866"},
{"BIG5", "big5"},
@@ -589,15 +589,25 @@ static encodingPair encodings[] = {
*
* Return 0 on success, else -1 and set an exception.
*/
-static int psyco_encodings_fill(PyObject *dict)
+RAISES_NEG static int
+encodings_init(PyObject *module)
{
PyObject *value = NULL;
- encodingPair *enc;
+ int i;
int rv = -1;
- for (enc = encodings; enc->pgenc != NULL; enc++) {
- if (!(value = Text_FromUTF8(enc->pyenc))) { goto exit; }
- if (0 != PyDict_SetItemString(dict, enc->pgenc, value)) { goto exit; }
+ Dprintf("psycopgmodule: initializing encodings table");
+
+ if (!(psycoEncodings = PyDict_New())) { goto exit; }
+ Py_INCREF(psycoEncodings);
+ PyModule_AddObject(module, "encodings", psycoEncodings);
+
+ for (i = 0; enctable[i].pgenc != NULL; i++) {
+ if (!(value = Text_FromUTF8(enctable[i].pyenc))) { goto exit; }
+ if (0 > PyDict_SetItemString(
+ psycoEncodings, enctable[i].pgenc, value)) {
+ goto exit;
+ }
Py_CLEAR(value);
}
rv = 0;
@@ -945,16 +955,13 @@ INIT_MODULE(_psycopg)(void)
if (!module) { goto exit; }
/* other mixed initializations of module-level variables */
- if (!(psycoEncodings = PyDict_New())) { goto exit; }
- if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
if (!(psyco_null = Bytes_FromString("NULL"))) { goto exit; }
if (0 > add_module_constants(module)) { goto exit; }
if (0 > add_module_types(module)) { goto exit; }
/* encodings dictionary in module dictionary */
- Py_INCREF(psycoEncodings);
- PyModule_AddObject(module, "encodings", psycoEncodings);
+ if (0 > encodings_init(module)) { goto exit; }
dict = PyModule_GetDict(module);