Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dfd7344

Browse files
committed
Merge revision 71222 from trunk: #5615: make it possible to configure --without-threads again.
1 parent 0c0daf0 commit dfd7344

4 files changed

Lines changed: 49 additions & 6 deletions

File tree

Modules/_io/bufferedio.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ typedef struct {
204204
isn't ready for writing. */
205205
Py_off_t write_end;
206206

207+
#ifdef WITH_THREAD
207208
PyThread_type_lock lock;
209+
#endif
208210

209211
Py_ssize_t buffer_size;
210212
Py_ssize_t buffer_mask;
@@ -239,13 +241,18 @@ typedef struct {
239241

240242
/* These macros protect the BufferedObject against concurrent operations. */
241243

244+
#ifdef WITH_THREAD
242245
#define ENTER_BUFFERED(self) \
243246
Py_BEGIN_ALLOW_THREADS \
244247
PyThread_acquire_lock(self->lock, 1); \
245248
Py_END_ALLOW_THREADS
246249

247250
#define LEAVE_BUFFERED(self) \
248251
PyThread_release_lock(self->lock);
252+
#else
253+
#define ENTER_BUFFERED(self)
254+
#define LEAVE_BUFFERED(self)
255+
#endif
249256

250257
#define CHECK_INITIALIZED(self) \
251258
if (self->ok <= 0) { \
@@ -305,10 +312,12 @@ BufferedObject_dealloc(BufferedObject *self)
305312
PyMem_Free(self->buffer);
306313
self->buffer = NULL;
307314
}
315+
#ifdef WITH_THREAD
308316
if (self->lock) {
309317
PyThread_free_lock(self->lock);
310318
self->lock = NULL;
311319
}
320+
#endif
312321
Py_CLEAR(self->dict);
313322
Py_TYPE(self)->tp_free((PyObject *)self);
314323
}
@@ -565,11 +574,13 @@ _Buffered_init(BufferedObject *self)
565574
PyErr_NoMemory();
566575
return -1;
567576
}
577+
#ifdef WITH_THREAD
568578
self->lock = PyThread_allocate_lock();
569579
if (self->lock == NULL) {
570580
PyErr_SetString(PyExc_RuntimeError, "can't allocate read lock");
571581
return -1;
572582
}
583+
#endif
573584
/* Find out whether buffer_size is a power of 2 */
574585
/* XXX is this optimization useful? */
575586
for (n = self->buffer_size - 1; n & 1; n >>= 1)

Modules/_sqlite/connection.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
124124
self->detect_types = detect_types;
125125
self->timeout = timeout;
126126
(void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));
127-
127+
#ifdef WITH_THREAD
128128
self->thread_ident = PyThread_get_thread_ident();
129+
#endif
129130
self->check_same_thread = check_same_thread;
130131

131132
self->function_pinboard = PyDict_New();
@@ -510,9 +511,11 @@ void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value**
510511
PyObject* py_func;
511512
PyObject* py_retval = NULL;
512513

514+
#ifdef WITH_THREAD
513515
PyGILState_STATE threadstate;
514516

515517
threadstate = PyGILState_Ensure();
518+
#endif
516519

517520
py_func = (PyObject*)sqlite3_user_data(context);
518521

@@ -534,7 +537,9 @@ void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value**
534537
_sqlite3_result_error(context, "user-defined function raised exception", -1);
535538
}
536539

540+
#ifdef WITH_THREAD
537541
PyGILState_Release(threadstate);
542+
#endif
538543
}
539544

540545
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_
545550
PyObject** aggregate_instance;
546551
PyObject* stepmethod = NULL;
547552

553+
#ifdef WITH_THREAD
548554
PyGILState_STATE threadstate;
549555

550556
threadstate = PyGILState_Ensure();
557+
#endif
551558

552559
aggregate_class = (PyObject*)sqlite3_user_data(context);
553560

@@ -594,7 +601,9 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_
594601
Py_XDECREF(stepmethod);
595602
Py_XDECREF(function_result);
596603

604+
#ifdef WITH_THREAD
597605
PyGILState_Release(threadstate);
606+
#endif
598607
}
599608

600609
void _pysqlite_final_callback(sqlite3_context* context)
@@ -603,9 +612,11 @@ void _pysqlite_final_callback(sqlite3_context* context)
603612
PyObject** aggregate_instance;
604613
PyObject* aggregate_class;
605614

615+
#ifdef WITH_THREAD
606616
PyGILState_STATE threadstate;
607617

608618
threadstate = PyGILState_Ensure();
619+
#endif
609620

610621
aggregate_class = (PyObject*)sqlite3_user_data(context);
611622

@@ -633,7 +644,9 @@ void _pysqlite_final_callback(sqlite3_context* context)
633644
Py_XDECREF(*aggregate_instance);
634645
Py_XDECREF(function_result);
635646

647+
#ifdef WITH_THREAD
636648
PyGILState_Release(threadstate);
649+
#endif
637650
}
638651

639652
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
728741
{
729742
PyObject *ret;
730743
int rc;
744+
#ifdef WITH_THREAD
731745
PyGILState_STATE gilstate;
732746

733747
gilstate = PyGILState_Ensure();
748+
#endif
734749
ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
735750

736751
if (!ret) {
@@ -750,17 +765,21 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
750765
Py_DECREF(ret);
751766
}
752767

768+
#ifdef WITH_THREAD
753769
PyGILState_Release(gilstate);
770+
#endif
754771
return rc;
755772
}
756773

757774
static int _progress_handler(void* user_arg)
758775
{
759776
int rc;
760777
PyObject *ret;
778+
#ifdef WITH_THREAD
761779
PyGILState_STATE gilstate;
762780

763781
gilstate = PyGILState_Ensure();
782+
#endif
764783
ret = PyObject_CallFunction((PyObject*)user_arg, "");
765784

766785
if (!ret) {
@@ -777,7 +796,9 @@ static int _progress_handler(void* user_arg)
777796
Py_DECREF(ret);
778797
}
779798

799+
#ifdef WITH_THREAD
780800
PyGILState_Release(gilstate);
801+
#endif
781802
return rc;
782803
}
783804

@@ -832,6 +853,7 @@ PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, Py
832853

833854
int pysqlite_check_thread(pysqlite_Connection* self)
834855
{
856+
#ifdef WITH_THREAD
835857
if (self->check_same_thread) {
836858
if (PyThread_get_thread_ident() != self->thread_ident) {
837859
PyErr_Format(pysqlite_ProgrammingError,
@@ -842,7 +864,7 @@ int pysqlite_check_thread(pysqlite_Connection* self)
842864
}
843865

844866
}
845-
867+
#endif
846868
return 1;
847869
}
848870

@@ -1067,12 +1089,14 @@ pysqlite_collation_callback(
10671089
PyObject* callback = (PyObject*)context;
10681090
PyObject* string1 = 0;
10691091
PyObject* string2 = 0;
1092+
#ifdef WITH_THREAD
10701093
PyGILState_STATE gilstate;
1071-
1094+
#endif
10721095
PyObject* retval = NULL;
10731096
int result = 0;
1074-
1097+
#ifdef WITH_THREAD
10751098
gilstate = PyGILState_Ensure();
1099+
#endif
10761100

10771101
if (PyErr_Occurred()) {
10781102
goto finally;
@@ -1101,9 +1125,9 @@ pysqlite_collation_callback(
11011125
Py_XDECREF(string1);
11021126
Py_XDECREF(string2);
11031127
Py_XDECREF(retval);
1104-
1128+
#ifdef WITH_THREAD
11051129
PyGILState_Release(gilstate);
1106-
1130+
#endif
11071131
return result;
11081132
}
11091133

Modules/_sqlite/module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
459459
* threads have already been initialized.
460460
* (see pybsddb-users mailing list post on 2002-08-07)
461461
*/
462+
#ifdef WITH_THREAD
462463
PyEval_InitThreads();
464+
#endif
463465

464466
error:
465467
if (PyErr_Occurred())

Objects/object.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,17 @@ _PyObject_Dump(PyObject* op)
349349
if (op == NULL)
350350
fprintf(stderr, "NULL\n");
351351
else {
352+
#ifdef WITH_THREAD
352353
PyGILState_STATE gil;
354+
#endif
353355
fprintf(stderr, "object : ");
356+
#ifdef WITH_THREAD
354357
gil = PyGILState_Ensure();
358+
#endif
355359
(void)PyObject_Print(op, stderr, 0);
360+
#ifdef WITH_THREAD
356361
PyGILState_Release(gil);
362+
#endif
357363
/* XXX(twouters) cast refcount to long until %zd is
358364
universally available */
359365
fprintf(stderr, "\n"

0 commit comments

Comments
 (0)