From 5a3e07a6103e61f0724b3f0d17039765898e28fb Mon Sep 17 00:00:00 2001 From: Jason Erickson Date: Sun, 4 Oct 2009 14:28:27 -0600 Subject: [PATCH] Rearranged code to fix recent MSVC errors Rearranged code to fix recent MSVC errors, such as mutex locking in conn_setup to after the delcarations of variables. --- psycopg/connection_int.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 8e9d7b05..402a075a 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -65,6 +65,8 @@ void conn_notice_process(connectionObject *self) { struct connectionObject_notice *notice; + PyObject *msg; + Py_BEGIN_ALLOW_THREADS; pthread_mutex_lock(&self->lock); @@ -73,7 +75,7 @@ conn_notice_process(connectionObject *self) while (notice != NULL) { Py_BLOCK_THREADS; - PyObject *msg = PyString_FromString(notice->message); + msg = PyString_FromString(notice->message); Dprintf("conn_notice_process: %s", notice->message); @@ -122,10 +124,6 @@ conn_notice_clean(connectionObject *self) int conn_setup(connectionObject *self, PGconn *pgconn) { - Py_BEGIN_ALLOW_THREADS; - pthread_mutex_lock(&self->lock); - Py_BLOCK_THREADS; - PGresult *pgres; const char *data, *tmp; const char *scs; /* standard-conforming strings */ @@ -142,6 +140,10 @@ conn_setup(connectionObject *self, PGconn *pgconn) static const char lvl2a[] = "repeatable read"; static const char lvl2b[] = "serializable"; + Py_BEGIN_ALLOW_THREADS; + pthread_mutex_lock(&self->lock); + Py_BLOCK_THREADS; + if (self->encoding) free(self->encoding); self->equote = 0; self->isolation_level = 0;