[Python-checkins] python/dist/src/Modules _bsddb.c,1.11,1.12

mhammond@users.sourceforge.net mhammond@users.sourceforge.net
Tue, 22 Apr 2003 16:13:30 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv32672/Modules

Modified Files:
	_bsddb.c 
Log Message:
Update to the new PyGILState APIs to simplify and correct thread-state
management.  Old code still #ifdef'd out - I may remove this in a sec,
but for now, let's get it in and things passing the tests again!


Index: _bsddb.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_bsddb.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** _bsddb.c	31 Mar 2003 19:51:29 -0000	1.11
--- _bsddb.c	22 Apr 2003 23:13:27 -0000	1.12
***************
*** 96,100 ****
--- 96,112 ----
  #define MYDB_END_ALLOW_THREADS Py_END_ALLOW_THREADS;
  
+ /* For 2.3, use the PyGILState_ calls */
+ #if (PY_VERSION_HEX >= 0x02030000)
+ #define MYDB_USE_GILSTATE
+ #endif
+ 
  /* and these are for calling C --> Python */
+ #if defined(MYDB_USE_GILSTATE)
+ #define MYDB_BEGIN_BLOCK_THREADS \
+ 		PyGILState_STATE __savestate = PyGILState_Ensure();
+ #define MYDB_END_BLOCK_THREADS \
+ 		PyGILState_Release(__savestate);
+ #else /* MYDB_USE_GILSTATE */
+ /* Pre GILState API - do it the long old way */
  static PyInterpreterState* _db_interpreterState = NULL;
  #define MYDB_BEGIN_BLOCK_THREADS {                              \
***************
*** 111,117 ****
          PyThreadState_Delete(newState);                         \
          }
  
  #else
! 
  #define MYDB_BEGIN_ALLOW_THREADS
  #define MYDB_END_ALLOW_THREADS
--- 123,130 ----
          PyThreadState_Delete(newState);                         \
          }
+ #endif /* MYDB_USE_GILSTATE */
  
  #else
! /* Compiled without threads - avoid all this cruft */
  #define MYDB_BEGIN_ALLOW_THREADS
  #define MYDB_END_ALLOW_THREADS
***************
*** 4250,4254 ****
  
  
! #ifdef WITH_THREAD
      /* Save the current interpreter, so callbacks can do the right thing. */
      _db_interpreterState = PyThreadState_Get()->interp;
--- 4263,4267 ----
  
  
! #if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE)
      /* Save the current interpreter, so callbacks can do the right thing. */
      _db_interpreterState = PyThreadState_Get()->interp;