1. pygame
  2. Untitled project
  3. pygame

Commits

marcus  committed 3785000

Fixed creating Sound instances from file objects, which I previously messed up.

  • Participants
  • Parent commits 09620b6
  • Branches default

Comments (0)

Files changed (1)

File src/mixer.c

View file
  • Ignore whitespace
         const void *buf;
         Py_ssize_t buflen;
 
-        if (PyObject_AsReadBuffer (file, &buf, &buflen) == -1)
-            return -1;
-        chunk = malloc (sizeof (Mix_Chunk));
-        if (!chunk)
+        if (PyObject_AsReadBuffer (file, &buf, &buflen) == 0)
         {
-            RAISE (PyExc_MemoryError, "cannot allocate chunk");
-            return -1;
+            chunk = malloc (sizeof (Mix_Chunk));
+            if (!chunk)
+            {
+                RAISE (PyExc_MemoryError, "cannot allocate chunk");
+                return -1;
+            }
+            chunk->alen = buflen;
+            chunk->abuf = malloc (buflen);
+            if (!chunk->abuf)
+            {
+                free (chunk);
+                RAISE (PyExc_MemoryError, "cannot allocate chunk");
+                return -1;
+            }
+            chunk->allocated = 1;
+            chunk->volume = 128;
+            memcpy (chunk->abuf, buf, buflen);
         }
-        chunk->alen = buflen;
-        chunk->abuf = malloc (buflen);
-        if (!chunk->abuf)
-        {
-            free (chunk);
-            RAISE (PyExc_MemoryError, "cannot allocate chunk");
-            return -1;
-        }
-        chunk->allocated = 1;
-        chunk->volume = 128;
-        memcpy (chunk->abuf, buf, buflen);
     }
     
     if (!chunk)