Lenard Lindstrom avatar Lenard Lindstrom committed 62ddfa7

[BUG] fix Bugzilla 54: movieplayer.py fails with Python 3.2

Comments (0)

Files changed (2)

 # BREAK = change breaks existing code
 # BUG    = fixed a bug that was (or could have been) crashing
 
+[SVN 2937] September 23, 2010
+    [BUG] Bugzilla 54: pygame.examples.movieplayer causes
+    "PyThreadState_Get: no current thread".
+    Movie module now works under Python 3.2.
+
 [SVN 2936] September 22, 2010
     Use capsule objects in preference to cobject objects.
     This allows Pygame to build an run from Python 3.2, which has to cobjects.
     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;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.