Merge revision 71222 from trunk: #5615: make it possible to configure --without-threads again.
This commit is contained in:
parent
0c0daf059b
commit
dfd734429e
|
@ -204,7 +204,9 @@ typedef struct {
|
||||||
isn't ready for writing. */
|
isn't ready for writing. */
|
||||||
Py_off_t write_end;
|
Py_off_t write_end;
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyThread_type_lock lock;
|
PyThread_type_lock lock;
|
||||||
|
#endif
|
||||||
|
|
||||||
Py_ssize_t buffer_size;
|
Py_ssize_t buffer_size;
|
||||||
Py_ssize_t buffer_mask;
|
Py_ssize_t buffer_mask;
|
||||||
|
@ -239,6 +241,7 @@ typedef struct {
|
||||||
|
|
||||||
/* These macros protect the BufferedObject against concurrent operations. */
|
/* These macros protect the BufferedObject against concurrent operations. */
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
#define ENTER_BUFFERED(self) \
|
#define ENTER_BUFFERED(self) \
|
||||||
Py_BEGIN_ALLOW_THREADS \
|
Py_BEGIN_ALLOW_THREADS \
|
||||||
PyThread_acquire_lock(self->lock, 1); \
|
PyThread_acquire_lock(self->lock, 1); \
|
||||||
|
@ -246,6 +249,10 @@ typedef struct {
|
||||||
|
|
||||||
#define LEAVE_BUFFERED(self) \
|
#define LEAVE_BUFFERED(self) \
|
||||||
PyThread_release_lock(self->lock);
|
PyThread_release_lock(self->lock);
|
||||||
|
#else
|
||||||
|
#define ENTER_BUFFERED(self)
|
||||||
|
#define LEAVE_BUFFERED(self)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CHECK_INITIALIZED(self) \
|
#define CHECK_INITIALIZED(self) \
|
||||||
if (self->ok <= 0) { \
|
if (self->ok <= 0) { \
|
||||||
|
@ -305,10 +312,12 @@ BufferedObject_dealloc(BufferedObject *self)
|
||||||
PyMem_Free(self->buffer);
|
PyMem_Free(self->buffer);
|
||||||
self->buffer = NULL;
|
self->buffer = NULL;
|
||||||
}
|
}
|
||||||
|
#ifdef WITH_THREAD
|
||||||
if (self->lock) {
|
if (self->lock) {
|
||||||
PyThread_free_lock(self->lock);
|
PyThread_free_lock(self->lock);
|
||||||
self->lock = NULL;
|
self->lock = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Py_CLEAR(self->dict);
|
Py_CLEAR(self->dict);
|
||||||
Py_TYPE(self)->tp_free((PyObject *)self);
|
Py_TYPE(self)->tp_free((PyObject *)self);
|
||||||
}
|
}
|
||||||
|
@ -565,11 +574,13 @@ _Buffered_init(BufferedObject *self)
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#ifdef WITH_THREAD
|
||||||
self->lock = PyThread_allocate_lock();
|
self->lock = PyThread_allocate_lock();
|
||||||
if (self->lock == NULL) {
|
if (self->lock == NULL) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "can't allocate read lock");
|
PyErr_SetString(PyExc_RuntimeError, "can't allocate read lock");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Find out whether buffer_size is a power of 2 */
|
/* Find out whether buffer_size is a power of 2 */
|
||||||
/* XXX is this optimization useful? */
|
/* XXX is this optimization useful? */
|
||||||
for (n = self->buffer_size - 1; n & 1; n >>= 1)
|
for (n = self->buffer_size - 1; n & 1; n >>= 1)
|
||||||
|
|
|
@ -124,8 +124,9 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
|
||||||
self->detect_types = detect_types;
|
self->detect_types = detect_types;
|
||||||
self->timeout = timeout;
|
self->timeout = timeout;
|
||||||
(void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));
|
(void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));
|
||||||
|
#ifdef WITH_THREAD
|
||||||
self->thread_ident = PyThread_get_thread_ident();
|
self->thread_ident = PyThread_get_thread_ident();
|
||||||
|
#endif
|
||||||
self->check_same_thread = check_same_thread;
|
self->check_same_thread = check_same_thread;
|
||||||
|
|
||||||
self->function_pinboard = PyDict_New();
|
self->function_pinboard = PyDict_New();
|
||||||
|
@ -510,9 +511,11 @@ void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value**
|
||||||
PyObject* py_func;
|
PyObject* py_func;
|
||||||
PyObject* py_retval = NULL;
|
PyObject* py_retval = NULL;
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_STATE threadstate;
|
PyGILState_STATE threadstate;
|
||||||
|
|
||||||
threadstate = PyGILState_Ensure();
|
threadstate = PyGILState_Ensure();
|
||||||
|
#endif
|
||||||
|
|
||||||
py_func = (PyObject*)sqlite3_user_data(context);
|
py_func = (PyObject*)sqlite3_user_data(context);
|
||||||
|
|
||||||
|
@ -534,7 +537,9 @@ void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value**
|
||||||
_sqlite3_result_error(context, "user-defined function raised exception", -1);
|
_sqlite3_result_error(context, "user-defined function raised exception", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_Release(threadstate);
|
PyGILState_Release(threadstate);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
|
static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
|
||||||
|
@ -545,9 +550,11 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_
|
||||||
PyObject** aggregate_instance;
|
PyObject** aggregate_instance;
|
||||||
PyObject* stepmethod = NULL;
|
PyObject* stepmethod = NULL;
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_STATE threadstate;
|
PyGILState_STATE threadstate;
|
||||||
|
|
||||||
threadstate = PyGILState_Ensure();
|
threadstate = PyGILState_Ensure();
|
||||||
|
#endif
|
||||||
|
|
||||||
aggregate_class = (PyObject*)sqlite3_user_data(context);
|
aggregate_class = (PyObject*)sqlite3_user_data(context);
|
||||||
|
|
||||||
|
@ -594,7 +601,9 @@ error:
|
||||||
Py_XDECREF(stepmethod);
|
Py_XDECREF(stepmethod);
|
||||||
Py_XDECREF(function_result);
|
Py_XDECREF(function_result);
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_Release(threadstate);
|
PyGILState_Release(threadstate);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void _pysqlite_final_callback(sqlite3_context* context)
|
void _pysqlite_final_callback(sqlite3_context* context)
|
||||||
|
@ -603,9 +612,11 @@ void _pysqlite_final_callback(sqlite3_context* context)
|
||||||
PyObject** aggregate_instance;
|
PyObject** aggregate_instance;
|
||||||
PyObject* aggregate_class;
|
PyObject* aggregate_class;
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_STATE threadstate;
|
PyGILState_STATE threadstate;
|
||||||
|
|
||||||
threadstate = PyGILState_Ensure();
|
threadstate = PyGILState_Ensure();
|
||||||
|
#endif
|
||||||
|
|
||||||
aggregate_class = (PyObject*)sqlite3_user_data(context);
|
aggregate_class = (PyObject*)sqlite3_user_data(context);
|
||||||
|
|
||||||
|
@ -633,7 +644,9 @@ error:
|
||||||
Py_XDECREF(*aggregate_instance);
|
Py_XDECREF(*aggregate_instance);
|
||||||
Py_XDECREF(function_result);
|
Py_XDECREF(function_result);
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_Release(threadstate);
|
PyGILState_Release(threadstate);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self)
|
void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self)
|
||||||
|
@ -728,9 +741,11 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
|
||||||
{
|
{
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
int rc;
|
int rc;
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_STATE gilstate;
|
PyGILState_STATE gilstate;
|
||||||
|
|
||||||
gilstate = PyGILState_Ensure();
|
gilstate = PyGILState_Ensure();
|
||||||
|
#endif
|
||||||
ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
|
ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
@ -750,7 +765,9 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
|
||||||
Py_DECREF(ret);
|
Py_DECREF(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_Release(gilstate);
|
PyGILState_Release(gilstate);
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,9 +775,11 @@ static int _progress_handler(void* user_arg)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_STATE gilstate;
|
PyGILState_STATE gilstate;
|
||||||
|
|
||||||
gilstate = PyGILState_Ensure();
|
gilstate = PyGILState_Ensure();
|
||||||
|
#endif
|
||||||
ret = PyObject_CallFunction((PyObject*)user_arg, "");
|
ret = PyObject_CallFunction((PyObject*)user_arg, "");
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
@ -777,7 +796,9 @@ static int _progress_handler(void* user_arg)
|
||||||
Py_DECREF(ret);
|
Py_DECREF(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_Release(gilstate);
|
PyGILState_Release(gilstate);
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,6 +853,7 @@ PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, Py
|
||||||
|
|
||||||
int pysqlite_check_thread(pysqlite_Connection* self)
|
int pysqlite_check_thread(pysqlite_Connection* self)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_THREAD
|
||||||
if (self->check_same_thread) {
|
if (self->check_same_thread) {
|
||||||
if (PyThread_get_thread_ident() != self->thread_ident) {
|
if (PyThread_get_thread_ident() != self->thread_ident) {
|
||||||
PyErr_Format(pysqlite_ProgrammingError,
|
PyErr_Format(pysqlite_ProgrammingError,
|
||||||
|
@ -842,7 +864,7 @@ int pysqlite_check_thread(pysqlite_Connection* self)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,12 +1089,14 @@ pysqlite_collation_callback(
|
||||||
PyObject* callback = (PyObject*)context;
|
PyObject* callback = (PyObject*)context;
|
||||||
PyObject* string1 = 0;
|
PyObject* string1 = 0;
|
||||||
PyObject* string2 = 0;
|
PyObject* string2 = 0;
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_STATE gilstate;
|
PyGILState_STATE gilstate;
|
||||||
|
#endif
|
||||||
PyObject* retval = NULL;
|
PyObject* retval = NULL;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
#ifdef WITH_THREAD
|
||||||
gilstate = PyGILState_Ensure();
|
gilstate = PyGILState_Ensure();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
goto finally;
|
goto finally;
|
||||||
|
@ -1101,9 +1125,9 @@ finally:
|
||||||
Py_XDECREF(string1);
|
Py_XDECREF(string1);
|
||||||
Py_XDECREF(string2);
|
Py_XDECREF(string2);
|
||||||
Py_XDECREF(retval);
|
Py_XDECREF(retval);
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_Release(gilstate);
|
PyGILState_Release(gilstate);
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -459,7 +459,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
|
||||||
* threads have already been initialized.
|
* threads have already been initialized.
|
||||||
* (see pybsddb-users mailing list post on 2002-08-07)
|
* (see pybsddb-users mailing list post on 2002-08-07)
|
||||||
*/
|
*/
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyEval_InitThreads();
|
PyEval_InitThreads();
|
||||||
|
#endif
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
|
|
|
@ -349,11 +349,17 @@ _PyObject_Dump(PyObject* op)
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
fprintf(stderr, "NULL\n");
|
fprintf(stderr, "NULL\n");
|
||||||
else {
|
else {
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_STATE gil;
|
PyGILState_STATE gil;
|
||||||
|
#endif
|
||||||
fprintf(stderr, "object : ");
|
fprintf(stderr, "object : ");
|
||||||
|
#ifdef WITH_THREAD
|
||||||
gil = PyGILState_Ensure();
|
gil = PyGILState_Ensure();
|
||||||
|
#endif
|
||||||
(void)PyObject_Print(op, stderr, 0);
|
(void)PyObject_Print(op, stderr, 0);
|
||||||
|
#ifdef WITH_THREAD
|
||||||
PyGILState_Release(gil);
|
PyGILState_Release(gil);
|
||||||
|
#endif
|
||||||
/* XXX(twouters) cast refcount to long until %zd is
|
/* XXX(twouters) cast refcount to long until %zd is
|
||||||
universally available */
|
universally available */
|
||||||
fprintf(stderr, "\n"
|
fprintf(stderr, "\n"
|
||||||
|
|
Loading…
Reference in New Issue