From 8238b56f36710edb5b5080526195bfad27f977ea Mon Sep 17 00:00:00 2001 From: zhangting Date: Mon, 9 Dec 2024 15:01:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A9=B1=E5=8A=A8=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8eventlet=E7=9A=84sqlalchemy=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=95=B0=E6=8D=AE=E5=BA=93=E6=97=B6=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- psycopg/connection_type.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 287e7d3..2b3af4d 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -1320,7 +1320,7 @@ static struct PyGetSetDef connectionObject_getsets[] = { /* register the uint typecasters */ static int -register_type_uint(connectionObject *self, PyThreadState **tstate) +register_type_uint(connectionObject *self) { int rv = -1; typecastObject *obj = NULL; @@ -1332,10 +1332,13 @@ register_type_uint(connectionObject *self, PyThreadState **tstate) long int* _typecast_INTEGER_types; _typecast_INTEGER_types = (long int*)malloc((size+1)*sizeof(long int)); + Py_BEGIN_ALLOW_THREADS; for (int i=0; i< size; i++) { - unsigned int uint_val = pq_get_pg_catalog_custom_type_oid(self, uint_arr[i], tstate); + unsigned int uint_val = pq_get_pg_catalog_custom_type_oid(self, uint_arr[i], &_save); _typecast_INTEGER_types[i] = (long int)uint_val; } + Py_END_ALLOW_THREADS; + typecastObject_initlist _typecast_builtins[] = { {"INTEGER", _typecast_INTEGER_types, typecast_INTEGER_cast, NULL}, }; @@ -1429,22 +1432,16 @@ connection_setup(connectionObject *self, const char *dsn, long int async) Dprintf("connection_setup: good connection object at %p, refcnt = " FORMAT_CODE_PY_SSIZE_T, self, Py_REFCNT(self)); - PyThreadState *tstate = (PyThreadState *)malloc(sizeof(PyThreadState)); Py_BEGIN_ALLOW_THREADS; pthread_mutex_lock(&self->lock); sql_compatibility_value = pq_get_guc_locked(self, "sql_compatibility", &_save); set_sql_compatibility(self, sql_compatibility_value); - memcpy(tstate, _save, sizeof(_save)); pthread_mutex_unlock(&self->lock); Py_END_ALLOW_THREADS; pthread_mutex_lock(&self->lock); - register_type_uint(self, &tstate); - if (tstate) { - free(tstate); - tstate = NULL; - } + register_type_uint(self); pthread_mutex_unlock(&self->lock); exit: -- Gitee