Skip to content

Commit

Permalink
Merge branch 'dev/init-failure'
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrazzo committed Aug 4, 2023
2 parents fb77bdc + 14e06d8 commit 4fe28d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Current release
What's new in psycopg 2.9.7 (unreleased)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fix propagation of exceptions raised during module initialization
(:ticket:`#1598`).
- Fix building when pg_config returns an empty string (:ticket:`#1599`).
- Wheel package compiled against OpenSSL 1.1.1v.

Expand Down
33 changes: 18 additions & 15 deletions psycopg/psycopgmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,32 +1001,35 @@ INIT_MODULE(_psycopg)(void)

/* initialize types and objects not exposed to the module */
Py_SET_TYPE(&typecastType, &PyType_Type);
if (0 > PyType_Ready(&typecastType)) { goto exit; }
if (0 > PyType_Ready(&typecastType)) { goto error; }

Py_SET_TYPE(&chunkType, &PyType_Type);
if (0 > PyType_Ready(&chunkType)) { goto exit; }
if (0 > PyType_Ready(&chunkType)) { goto error; }

Py_SET_TYPE(&errorType, &PyType_Type);
errorType.tp_base = (PyTypeObject *)PyExc_StandardError;
if (0 > PyType_Ready(&errorType)) { goto exit; }
if (0 > PyType_Ready(&errorType)) { goto error; }

if (!(psyco_null = Bytes_FromString("NULL"))) { goto exit; }
if (!(psyco_null = Bytes_FromString("NULL"))) { goto error; }

/* initialize the module */
module = PyModule_Create(&psycopgmodule);
if (!module) { goto exit; }
if (!module) { goto error; }

if (0 > add_module_constants(module)) { goto exit; }
if (0 > add_module_types(module)) { goto exit; }
if (0 > datetime_init()) { goto exit; }
if (0 > encodings_init(module)) { goto exit; }
if (0 > typecast_init(module)) { goto exit; }
if (0 > adapters_init(module)) { goto exit; }
if (0 > basic_errors_init(module)) { goto exit; }
if (0 > sqlstate_errors_init(module)) { goto exit; }
if (0 > add_module_constants(module)) { goto error; }
if (0 > add_module_types(module)) { goto error; }
if (0 > datetime_init()) { goto error; }
if (0 > encodings_init(module)) { goto error; }
if (0 > typecast_init(module)) { goto error; }
if (0 > adapters_init(module)) { goto error; }
if (0 > basic_errors_init(module)) { goto error; }
if (0 > sqlstate_errors_init(module)) { goto error; }

Dprintf("psycopgmodule: module initialization complete");

exit:
return module;

error:
if (module)
Py_DECREF(module);
return NULL;
}

0 comments on commit 4fe28d6

Please sign in to comment.