From 6286135ca7c7b2c3eeabb8ed2033641481dfdddd Mon Sep 17 00:00:00 2001 From: vimiix Date: Tue, 7 Nov 2023 00:05:08 +0800 Subject: [PATCH 1/2] fix:support for python 3.11 --- psycopg/connection_int.c | 1 + psycopg/connection_type.c | 1 + psycopg/pqpath.c | 1 + psycopg/psycopgmodule.c | 2 ++ psycopg/replication_connection_type.c | 7 ++++++- psycopg/replication_cursor_type.c | 7 ++++++- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 34c6957..8365e04 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -33,6 +33,7 @@ #include "psycopg/green.h" #include "psycopg/notify.h" +#include #include /* String indexes match the ISOLATION_LEVEL_* consts */ diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 5155c68..c9057a7 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -35,6 +35,7 @@ #include "psycopg/green.h" #include "psycopg/xid.h" +#include #include #include diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index ec02067..83ab91f 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -47,6 +47,7 @@ #include "psycopg/libpq_support.h" #include "libpq-fe.h" +#include #ifdef _WIN32 /* select() */ #include diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 5ab6f5f..0d284f8 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -57,6 +57,8 @@ #include #include "psycopg/adapter_datetime.h" +#include + HIDDEN PyObject *psycoEncodings = NULL; HIDDEN PyObject *sqlstate_errors = NULL; diff --git a/psycopg/replication_connection_type.c b/psycopg/replication_connection_type.c index b8c1d2d..7e51904 100644 --- a/psycopg/replication_connection_type.c +++ b/psycopg/replication_connection_type.c @@ -129,6 +129,11 @@ replicationConnection_repr(replicationConnectionObject *self) self, self->conn.dsn, self->conn.closed); } +static int +replicationConnectionType_traverse(PyObject *self, visitproc visit, void *arg) +{ + return connectionType.tp_traverse(self, visit, arg); +} /* object calculated member list */ @@ -173,7 +178,7 @@ PyTypeObject replicationConnectionType = { Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ replicationConnectionType_doc, /*tp_doc*/ - 0, /*tp_traverse*/ + replicationConnectionType_traverse, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ diff --git a/psycopg/replication_cursor_type.c b/psycopg/replication_cursor_type.c index 689a131..ab3ad3c 100644 --- a/psycopg/replication_cursor_type.c +++ b/psycopg/replication_cursor_type.c @@ -346,6 +346,11 @@ replicationCursor_repr(replicationCursorObject *self) "", self, self->cur.closed); } +static int +replicationCursorType_traverse(PyObject *self, visitproc visit, void *arg) +{ + return cursorType.tp_traverse(self, visit, arg); +} /* object type */ @@ -374,7 +379,7 @@ PyTypeObject replicationCursorType = { Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ replicationCursorType_doc, /*tp_doc*/ - 0, /*tp_traverse*/ + replicationCursorType_traverse, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ -- Gitee From 303c19c6eef3e00835e1908727c646d884c5c155 Mon Sep 17 00:00:00 2001 From: vimiix Date: Tue, 7 Nov 2023 00:12:22 +0800 Subject: [PATCH 2/2] fix:propagation of exceptions raised during module initialization --- psycopg/psycopgmodule.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 0d284f8..d129e87 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -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; } -- Gitee