Anonymous avatar Anonymous committed e5128eb

rwop cleanups

Comments (0)

Files changed (6)

 # BREAK = change breaks existing code
 # BUG   = fixed a bug that was crashing
 
+Apr 30, 2001
+	loading Sounds from python objects now works [BUG]
+	loading anything from python objects now thread safe [BUG]
+
 Apr 19, 2001
 	applied Niki Spahiev's memory leak in event.c
 	removed minor memleak from each module's init
 
 		if(!(rw = RWopsFromPython(file)))
 			return NULL;
-		Py_BEGIN_ALLOW_THREADS
-		surf = IMG_LoadTyped_RW(rw, 1, find_extension(name));
-		Py_END_ALLOW_THREADS
+		if(RWopsCheckPython(rw))
+			surf = IMG_LoadTyped_RW(rw, 1, find_extension(name));
+		else
+		{
+			Py_BEGIN_ALLOW_THREADS
+			surf = IMG_LoadTyped_RW(rw, 1, find_extension(name));
+			Py_END_ALLOW_THREADS
+		}
 	}
 	if(!surf)
 		return RAISE(PyExc_SDLError, IMG_GetError());
 		return NULL;
 
 	MIXER_INIT_CHECK();
-
 	if(PyString_Check(file))
 	{
 		name = PyString_AsString(file);
 	{
 		if(!(rw = RWopsFromPython(file)))
 			return NULL;
-		Py_BEGIN_ALLOW_THREADS
-		chunk = Mix_LoadWAV_RW(rw, 1);
-		Py_END_ALLOW_THREADS
+		if(RWopsCheckPython(rw))
+			chunk = Mix_LoadWAV_RW(rw, 1);
+		else
+		{
+			Py_BEGIN_ALLOW_THREADS
+			chunk = Mix_LoadWAV_RW(rw, 1);
+			Py_END_ALLOW_THREADS
+		}
 	}
 
 	if(!chunk)
 	final = PySound_New(chunk);
 	if(!final)
 		Mix_FreeChunk(chunk);
+
 	return final;
 }
 
 
 	/*imported needed apis*/
 	import_pygame_base();
+	import_pygame_rwobject();
 
 	music = PyImport_ImportModule("pygame.mixer_music");
 	if(music) 
 /* RWOBJECT */
 /*the rwobject are only needed for C side work, not accessable from python*/
 #define PYGAMEAPI_RWOBJECT_FIRSTSLOT 53
-#define PYGAMEAPI_RWOBJECT_NUMSLOTS 1
+#define PYGAMEAPI_RWOBJECT_NUMSLOTS 2
 #ifndef PYGAMEAPI_RWOBJECT_INTERNAL
 #define RWopsFromPython (*(SDL_RWops*(*)(PyObject*))PyGAME_C_API[PYGAMEAPI_RWOBJECT_FIRSTSLOT + 0])
+#define RWopsCheckPython (*(int(*)(SDL_RWops*))PyGAME_C_API[PYGAMEAPI_RWOBJECT_FIRSTSLOT + 1])
 #define import_pygame_rwobject() { \
 	PyObject *module = PyImport_ImportModule("pygame.rwobject"); \
 	if (module != NULL) { \
 
 
 
+
 static SDL_RWops* RWopsFromPython(PyObject* obj)
 {
 	SDL_RWops* rw;
 }
 
 
+static int RWopsCheckPython(SDL_RWops* rw)
+{
+	if(rw->close)
+		return rw->close == rw_close;
+	if(rw->read)
+		return rw->read == rw_read;
+	if(rw->write)
+		return rw->write == rw_write;
+	if(rw->seek)
+		return rw->seek == rw_seek;
+	return 0;
+}
+
 
 static int rw_seek(SDL_RWops* context, int offset, int whence)
 {
 
 	/* export the c api */
 	c_api[0] = RWopsFromPython;
+	c_api[1] = RWopsCheckPython;
 	apiobj = PyCObject_FromVoidPtr(c_api, NULL);
 	PyDict_SetItemString(dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
 	Py_DECREF(apiobj);
 	{
 		if(!(rw = RWopsFromPython(file)))
 			return NULL;
-		Py_BEGIN_ALLOW_THREADS
 		PySurface_Prep(self);
 		result = SDL_SaveBMP_RW(surf, rw, 1);
 		PySurface_Unprep(self);
-		Py_END_ALLOW_THREADS
 	}
 
 	if(result == -1)
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.