mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-07-10 16:22:33 +03:00
Check errors when populating encodings map
This commit is contained in:
parent
dca6cffd6e
commit
026899e0c1
|
@ -326,15 +326,27 @@ static encodingPair encodings[] = {
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void psyco_encodings_fill(PyObject *dict)
|
/* Initialize the encodings table.
|
||||||
|
*
|
||||||
|
* Return 0 on success, else -1 and set an exception.
|
||||||
|
*/
|
||||||
|
static int psyco_encodings_fill(PyObject *dict)
|
||||||
{
|
{
|
||||||
|
PyObject *value = NULL;
|
||||||
encodingPair *enc;
|
encodingPair *enc;
|
||||||
|
int rv = -1;
|
||||||
|
|
||||||
for (enc = encodings; enc->pgenc != NULL; enc++) {
|
for (enc = encodings; enc->pgenc != NULL; enc++) {
|
||||||
PyObject *value = Text_FromUTF8(enc->pyenc);
|
if (!(value = Text_FromUTF8(enc->pyenc))) { goto exit; }
|
||||||
PyDict_SetItemString(dict, enc->pgenc, value);
|
if (0 != PyDict_SetItemString(dict, enc->pgenc, value)) { goto exit; }
|
||||||
Py_DECREF(value);
|
Py_CLEAR(value);
|
||||||
}
|
}
|
||||||
|
rv = 0;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
Py_XDECREF(value);
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* psyco_errors_init, psyco_errors_fill (callable from C)
|
/* psyco_errors_init, psyco_errors_fill (callable from C)
|
||||||
|
@ -905,8 +917,8 @@ INIT_MODULE(_psycopg)(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* other mixed initializations of module-level variables */
|
/* other mixed initializations of module-level variables */
|
||||||
psycoEncodings = PyDict_New();
|
if (!(psycoEncodings = PyDict_New())) { goto exit; }
|
||||||
psyco_encodings_fill(psycoEncodings);
|
if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
|
||||||
psyco_null = Bytes_FromString("NULL");
|
psyco_null = Bytes_FromString("NULL");
|
||||||
psyco_DescriptionType = psyco_make_description_type();
|
psyco_DescriptionType = psyco_make_description_type();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user