Commits

illume  committed ea7a6d4

patch from Forrest Voight for file-likes in music, thanks Brian and Forrest.

  • Participants
  • Parent commits 1c2e43f

Comments (0)

Files changed (2)

         return NULL;
 
     MIXER_INIT_CHECK ();
-/*
-    #if (MIX_MAJOR_VERSION*100*100 + MIX_MINOR_VERSION*100 + MIX_PATCHLEVEL) > 010207
-*/
-#if MIX_MAJOR_VERSION>=1 && MIX_MINOR_VERSION>=2 && MIX_PATCHLEVEL>8
 
-/* this is for loading music from file likes..
-*/
+    #if (MIX_MAJOR_VERSION*100*100 + MIX_MINOR_VERSION*100 + MIX_PATCHLEVEL) >= 10208
     if(!PyString_Check(file) && !PyUnicode_Check(file))
     {
         rw = RWopsFromPythonThreaded(file);
     if (!new_music)
         return RAISE (PyExc_SDLError, SDL_GetError ());
 
+    Py_BEGIN_ALLOW_THREADS
     if (current_music)
     {
         Mix_FreeMusic (current_music);
         Mix_FreeMusic (queue_music);
         queue_music = NULL;
     }
+    Py_END_ALLOW_THREADS
+
     current_music = new_music;
     Py_RETURN_NONE;
 }
 
     MIXER_INIT_CHECK ();
 
-    #if MIX_MAJOR_VERSION*100*100 + MIX_MINOR_VERSION*100 + MIX_PATCHLEVEL >= 010207
+    #if MIX_MAJOR_VERSION*100*100 + MIX_MINOR_VERSION*100 + MIX_PATCHLEVEL >= 10208
     if(!PyString_Check(file) && !PyUnicode_Check(file))
     {
         rw = RWopsFromPythonThreaded(file);
     if (!new_music)
         return RAISE (PyExc_SDLError, SDL_GetError ());
 
+    Py_BEGIN_ALLOW_THREADS
     if (queue_music)
     {
         Mix_FreeMusic (queue_music);
         queue_music = NULL;
     }
+    Py_END_ALLOW_THREADS
+
     queue_music = new_music;
     Py_RETURN_NONE;
 }

File src/rwobject.c

     PyEval_AcquireLock ();
     oldstate = PyThreadState_Swap (helper->thread);
 
-    if (!(offset == 0 && whence == SEEK_CUR)) /*being called only for 'tell'*/
+    if (!(offset == 0 && whence == SEEK_CUR)) /* being seek'd, not just tell'd */
     {
         result = PyObject_CallFunction (helper->seek, "ii", offset, whence);
         if(!result)
-            return -1;
+        {
+            PyErr_Print();
+            retval = -1;
+            goto end;
+        }
         Py_DECREF (result);
     }
 
     result = PyObject_CallFunction (helper->tell, NULL);
     if (!result)
-        return -1;
+    {
+        PyErr_Print();
+        retval = -1;
+        goto end;
+    }
 
     retval = PyInt_AsLong (result);
     Py_DECREF (result);
 
+end:
     PyThreadState_Swap (oldstate);
     PyEval_ReleaseLock ();
 
 
     result = PyObject_CallFunction (helper->read, "i", size * maxnum);
     if (!result)
-        return -1;
+    {
+        PyErr_Print();
+        retval = -1;
+        goto end;
+    }
 
     if (!PyString_Check (result))
     {
         Py_DECREF (result);
-        return -1;
+        PyErr_Print();
+        retval = -1;
+        goto end;
     }
 
     retval = PyString_GET_SIZE (result);
 
     Py_DECREF (result);
 
+end:
     PyThreadState_Swap (oldstate);
     PyEval_ReleaseLock ();
 
 {
     RWHelper* helper = (RWHelper*) context->hidden.unknown.data1;
     PyObject* result;
+    int retval;
     PyThreadState* oldstate;
 
     if (!helper->write)
 
     result = PyObject_CallFunction (helper->write, "s#", ptr, size * num);
     if (!result)
-        return -1;
+    {
+        PyErr_Print();
+        retval = -1;
+        goto end;
+    }
 
     Py_DECREF (result);
+    retval = num;
 
+end:
     PyThreadState_Swap (oldstate);
     PyEval_ReleaseLock ();
 
-    return num;
+    return retval;
 }
 
 static int
     if (helper->close)
     {
         result = PyObject_CallFunction (helper->close, NULL);
-        if (result)
+        if (!result)
+        {
+            PyErr_Print();
             retval = -1;
+        }
         Py_XDECREF (result);
     }