mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-30 23:37:29 +03:00 
			
		
		
		
	Applied win32 patch from Jason Erickson.
This commit is contained in:
		
							parent
							
								
									4910f53b7e
								
							
						
					
					
						commit
						d31b4add22
					
				|  | @ -66,8 +66,8 @@ static void Dprintf(const char *fmt, ...) {} | ||||||
| #include <winsock2.h> | #include <winsock2.h> | ||||||
| #define pthread_mutex_t HANDLE | #define pthread_mutex_t HANDLE | ||||||
| #define pthread_condvar_t HANDLE | #define pthread_condvar_t HANDLE | ||||||
| #define pthread_mutex_lock(object) WaitForSingleObject(object, INFINITE) | #define pthread_mutex_lock(object) WaitForSingleObject(*(object), INFINITE) | ||||||
| #define pthread_mutex_unlock(object) ReleaseMutex(object) | #define pthread_mutex_unlock(object) ReleaseMutex(*(object)) | ||||||
| #define pthread_mutex_destroy(ref) (CloseHandle(*(ref))) | #define pthread_mutex_destroy(ref) (CloseHandle(*(ref))) | ||||||
| /* convert pthread mutex to native mutex */ | /* convert pthread mutex to native mutex */ | ||||||
| static int pthread_mutex_init(pthread_mutex_t *mutex, void* fake) | static int pthread_mutex_init(pthread_mutex_t *mutex, void* fake) | ||||||
|  |  | ||||||
|  | @ -308,15 +308,18 @@ _psyco_curs_execute(cursorObject *self, | ||||||
|     int res = 0; |     int res = 0; | ||||||
|     PyObject *fquery, *cvt = NULL; |     PyObject *fquery, *cvt = NULL; | ||||||
| 
 | 
 | ||||||
|  |     Py_BEGIN_ALLOW_THREADS; | ||||||
|     pthread_mutex_lock(&(self->conn->lock)); |     pthread_mutex_lock(&(self->conn->lock)); | ||||||
|     if (self->conn->async_cursor != NULL |     if (self->conn->async_cursor != NULL | ||||||
|         && self->conn->async_cursor != (PyObject*)self) { |         && self->conn->async_cursor != (PyObject*)self) { | ||||||
|         pthread_mutex_unlock(&(self->conn->lock)); |         pthread_mutex_unlock(&(self->conn->lock)); | ||||||
|  |         Py_BLOCK_THREADS; | ||||||
|         psyco_set_error(ProgrammingError, (PyObject*)self, |         psyco_set_error(ProgrammingError, (PyObject*)self, | ||||||
|                          "asynchronous query already in execution", NULL, NULL); |                          "asynchronous query already in execution", NULL, NULL); | ||||||
|         return 0; |         return 0; | ||||||
|     } |     } | ||||||
|     pthread_mutex_unlock(&(self->conn->lock)); |     pthread_mutex_unlock(&(self->conn->lock)); | ||||||
|  |     Py_END_ALLOW_THREADS; | ||||||
| 
 | 
 | ||||||
|     operation = _psyco_curs_validate_sql_basic(self, operation); |     operation = _psyco_curs_validate_sql_basic(self, operation); | ||||||
| 
 | 
 | ||||||
|  | @ -641,15 +644,18 @@ _psyco_curs_prefetch(cursorObject *self) | ||||||
| 
 | 
 | ||||||
|     /* check if the fetching cursor is the one that did the asynchronous query
 |     /* check if the fetching cursor is the one that did the asynchronous query
 | ||||||
|        and raise an exception if not */ |        and raise an exception if not */ | ||||||
|  |     Py_BEGIN_ALLOW_THREADS; | ||||||
|     pthread_mutex_lock(&(self->conn->lock)); |     pthread_mutex_lock(&(self->conn->lock)); | ||||||
|     if (self->conn->async_cursor != NULL |     if (self->conn->async_cursor != NULL | ||||||
|         && self->conn->async_cursor != (PyObject*)self) { |         && self->conn->async_cursor != (PyObject*)self) { | ||||||
|         pthread_mutex_unlock(&(self->conn->lock)); |         pthread_mutex_unlock(&(self->conn->lock)); | ||||||
|  |         Py_BLOCK_THREADS; | ||||||
|         psyco_set_error(ProgrammingError, (PyObject*)self, |         psyco_set_error(ProgrammingError, (PyObject*)self, | ||||||
|                          "asynchronous fetch by wrong cursor", NULL, NULL); |                          "asynchronous fetch by wrong cursor", NULL, NULL); | ||||||
|         return -2; |         return -2; | ||||||
|     } |     } | ||||||
|     pthread_mutex_unlock(&(self->conn->lock)); |     pthread_mutex_unlock(&(self->conn->lock)); | ||||||
|  |     Py_END_ALLOW_THREADS; | ||||||
| 
 | 
 | ||||||
|     if (self->pgres == NULL || self->needsfetch) { |     if (self->pgres == NULL || self->needsfetch) { | ||||||
|         self->needsfetch = 0; |         self->needsfetch = 0; | ||||||
|  | @ -1382,12 +1388,12 @@ psyco_curs_fileno(cursorObject *self, PyObject *args) | ||||||
| 
 | 
 | ||||||
|     /* note how we call PQflush() to make sure the user will use
 |     /* note how we call PQflush() to make sure the user will use
 | ||||||
|        select() in the safe way! */ |        select() in the safe way! */ | ||||||
|     pthread_mutex_lock(&(self->conn->lock)); |  | ||||||
|     Py_BEGIN_ALLOW_THREADS; |     Py_BEGIN_ALLOW_THREADS; | ||||||
|  |     pthread_mutex_lock(&(self->conn->lock)); | ||||||
|     PQflush(self->conn->pgconn); |     PQflush(self->conn->pgconn); | ||||||
|     socket = (long int)PQsocket(self->conn->pgconn); |     socket = (long int)PQsocket(self->conn->pgconn); | ||||||
|     Py_END_ALLOW_THREADS; |  | ||||||
|     pthread_mutex_unlock(&(self->conn->lock)); |     pthread_mutex_unlock(&(self->conn->lock)); | ||||||
|  |     Py_END_ALLOW_THREADS; | ||||||
| 
 | 
 | ||||||
|     return PyInt_FromLong(socket); |     return PyInt_FromLong(socket); | ||||||
| } | } | ||||||
|  | @ -1413,10 +1419,12 @@ psyco_curs_isready(cursorObject *self, PyObject *args) | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         IFCLEARPGRES(self->pgres); |         IFCLEARPGRES(self->pgres); | ||||||
|  |         Py_BEGIN_ALLOW_THREADS; | ||||||
|         pthread_mutex_lock(&(self->conn->lock)); |         pthread_mutex_lock(&(self->conn->lock)); | ||||||
|         self->pgres = PQgetResult(self->conn->pgconn); |         self->pgres = PQgetResult(self->conn->pgconn); | ||||||
|         self->conn->async_cursor = NULL; |         self->conn->async_cursor = NULL; | ||||||
|         pthread_mutex_unlock(&(self->conn->lock)); |         pthread_mutex_unlock(&(self->conn->lock)); | ||||||
|  |         Py_END_ALLOW_THREADS; | ||||||
|         self->needsfetch = 1; |         self->needsfetch = 1; | ||||||
|         Py_INCREF(Py_True); |         Py_INCREF(Py_True); | ||||||
|         return Py_True; |         return Py_True; | ||||||
|  |  | ||||||
|  | @ -564,11 +564,12 @@ _pq_fetch_tuples(cursorObject *curs) | ||||||
|         int fsize = PQfsize(curs->pgres, i); |         int fsize = PQfsize(curs->pgres, i); | ||||||
|         int fmod =  PQfmod(curs->pgres, i); |         int fmod =  PQfmod(curs->pgres, i); | ||||||
| 
 | 
 | ||||||
|         Py_BLOCK_THREADS; |  | ||||||
|         PyObject *dtitem = PyTuple_New(7); |         PyObject *dtitem = PyTuple_New(7); | ||||||
|         PyObject *type = PyInt_FromLong(ftype); |         PyObject *type = PyInt_FromLong(ftype); | ||||||
|         PyObject *cast = NULL; |         PyObject *cast = NULL; | ||||||
| 
 | 
 | ||||||
|  |         Py_BLOCK_THREADS; | ||||||
|  | 
 | ||||||
|         PyTuple_SET_ITEM(curs->description, i, dtitem); |         PyTuple_SET_ITEM(curs->description, i, dtitem); | ||||||
| 
 | 
 | ||||||
|         /* fill the right cast function by accessing three different dictionaries:
 |         /* fill the right cast function by accessing three different dictionaries:
 | ||||||
|  |  | ||||||
|  | @ -593,6 +593,7 @@ psyco_GetDecimalType(void) | ||||||
|     static PyObject *cachedType = NULL; |     static PyObject *cachedType = NULL; | ||||||
| 
 | 
 | ||||||
| #ifdef HAVE_DECIMAL | #ifdef HAVE_DECIMAL | ||||||
|  |     PyObject *decimal = PyImport_ImportModule("decimal"); | ||||||
| 
 | 
 | ||||||
|     /* Use the cached object if running from the main interpreter. */ |     /* Use the cached object if running from the main interpreter. */ | ||||||
|     int can_cache = psyco_is_main_interp(); |     int can_cache = psyco_is_main_interp(); | ||||||
|  | @ -602,7 +603,6 @@ psyco_GetDecimalType(void) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* Get a new reference to the Decimal type. */ |     /* Get a new reference to the Decimal type. */ | ||||||
|     PyObject *decimal = PyImport_ImportModule("decimal"); |  | ||||||
|     if (decimal) { |     if (decimal) { | ||||||
|         decimalType = PyObject_GetAttrString(decimal, "Decimal"); |         decimalType = PyObject_GetAttrString(decimal, "Decimal"); | ||||||
|         Py_DECREF(decimal); |         Py_DECREF(decimal); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user