Source

pygame / src / rwobject.c

Diff from to

src/rwobject.c

     PyObject* seek;
     PyObject* tell;
     PyObject* close;
-#ifdef WITH_THREAD
-    PyThreadState* thread;
-#endif
 } RWHelper;
 
 /*static const char default_encoding[] = "unicode_escape";*/
 {
     SDL_RWops *rw;
     RWHelper *helper;
-    PyInterpreterState *interp;
-    PyThreadState *thread;
 
     if (obj == NULL) {
         return (SDL_RWops *)RAISE(PyExc_TypeError, "Invalid filetype object");
     rw->close = rw_close_th;
 
     PyEval_InitThreads();
-    thread = PyThreadState_Get();
-    interp = thread->interp;
-    helper->thread = PyThreadState_New(interp);
 
     return rw;
 #endif
     RWHelper* helper = (RWHelper*) context->hidden.unknown.data1;
     PyObject* result;
     int retval;
-    PyThreadState* oldstate;
+    PyGILState_STATE state;
+
 
     if (!helper->seek || !helper->tell)
         return -1;
 
-    PyEval_AcquireLock ();
-    oldstate = PyThreadState_Swap (helper->thread);
+    state = PyGILState_Ensure();
 
     if (!(offset == 0 && whence == SEEK_CUR)) /* being seek'd, not just tell'd */
     {
     Py_DECREF (result);
 
 end:
-    PyThreadState_Swap (oldstate);
-    PyEval_ReleaseLock ();
+    PyGILState_Release(state);
 
     return retval;
 }
     RWHelper* helper = (RWHelper*) context->hidden.unknown.data1;
     PyObject* result;
     int retval;
-    PyThreadState* oldstate;
+    PyGILState_STATE state;
 
     if (!helper->read)
         return -1;
 
-    PyEval_AcquireLock ();
-    oldstate = PyThreadState_Swap (helper->thread);
+    state = PyGILState_Ensure();
 
     result = PyObject_CallFunction (helper->read, "i", size * maxnum);
     if (!result)
     Py_DECREF (result);
 
 end:
-    PyThreadState_Swap (oldstate);
-    PyEval_ReleaseLock ();
+    PyGILState_Release(state);
 
     return retval;
 }
     RWHelper* helper = (RWHelper*) context->hidden.unknown.data1;
     PyObject* result;
     int retval;
-    PyThreadState* oldstate;
+    PyGILState_STATE state;
 
     if (!helper->write)
         return -1;
 
-    PyEval_AcquireLock ();
-    oldstate = PyThreadState_Swap (helper->thread);
+    state = PyGILState_Ensure();
 
     result = PyObject_CallFunction (helper->write, "s#", ptr, size * num);
     if (!result)
     retval = num;
 
 end:
-    PyThreadState_Swap (oldstate);
-    PyEval_ReleaseLock ();
+    PyGILState_Release(state);
 
     return retval;
 }
     RWHelper* helper = (RWHelper*) context->hidden.unknown.data1;
     PyObject* result;
     int retval = 0;
-    PyThreadState* oldstate;
+    PyGILState_STATE state;
 
-    PyEval_AcquireLock ();
-    oldstate = PyThreadState_Swap (helper->thread);
+    state = PyGILState_Ensure();
 
     if (helper->close)
     {
     Py_XDECREF (helper->read);
     Py_XDECREF (helper->close);
 
-    PyThreadState_Swap (oldstate);
-    PyThreadState_Clear (helper->thread);
-    PyThreadState_Delete (helper->thread);
-
     PyMem_Del (helper);
 
-    PyEval_ReleaseLock ();
+    PyGILState_Release(state);
 
     SDL_FreeRW (context);
     return retval;