@@ -95,7 +95,19 @@ static char *rcs_id = "$Id$";
9595#define MYDB_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS;
9696#define MYDB_END_ALLOW_THREADS Py_END_ALLOW_THREADS;
9797
98+ /* For 2.3, use the PyGILState_ calls */
99+ #if (PY_VERSION_HEX >= 0x02030000 )
100+ #define MYDB_USE_GILSTATE
101+ #endif
102+
98103/* and these are for calling C --> Python */
104+ #if defined(MYDB_USE_GILSTATE )
105+ #define MYDB_BEGIN_BLOCK_THREADS \
106+ PyGILState_STATE __savestate = PyGILState_Ensure();
107+ #define MYDB_END_BLOCK_THREADS \
108+ PyGILState_Release(__savestate);
109+ #else /* MYDB_USE_GILSTATE */
110+ /* Pre GILState API - do it the long old way */
99111static PyInterpreterState * _db_interpreterState = NULL ;
100112#define MYDB_BEGIN_BLOCK_THREADS { \
101113 PyThreadState* prevState; \
@@ -110,9 +122,10 @@ static PyInterpreterState* _db_interpreterState = NULL;
110122 PyEval_ReleaseLock(); \
111123 PyThreadState_Delete(newState); \
112124 }
125+ #endif /* MYDB_USE_GILSTATE */
113126
114127#else
115-
128+ /* Compiled without threads - avoid all this cruft */
116129#define MYDB_BEGIN_ALLOW_THREADS
117130#define MYDB_END_ALLOW_THREADS
118131#define MYDB_BEGIN_BLOCK_THREADS
@@ -4249,7 +4262,7 @@ DL_EXPORT(void) init_bsddb(void)
42494262 DBLock_Type .ob_type = & PyType_Type ;
42504263
42514264
4252- #ifdef WITH_THREAD
4265+ #if defined( WITH_THREAD ) && !defined( MYDB_USE_GILSTATE )
42534266 /* Save the current interpreter, so callbacks can do the right thing. */
42544267 _db_interpreterState = PyThreadState_Get ()-> interp ;
42554268#endif
0 commit comments