Commits

pygame  committed 5337d68

init cleanup

  • Participants
  • Parent commits 935c139

Comments (0)

Files changed (7)

 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+February 10, 2002
+        pygame.init() not required for proper cleanup [BUG]
+
 February 8, 2002
 	Rect and Surface subclassable types
 
     Pete Shinners
     pete@shinners.org
 */
-
+#define NO_PYGAME_C_API
 #define PYGAMEAPI_BASE_INTERNAL
 #include "pygame.h"
 #include <signal.h>
 
 static PyObject* init(PyObject* self,PyObject* args)
 {
-	static int initialized_once = 0;
 	PyObject *allmodules, *moduleslist, *dict, *func, *result, *mod;
 	int loop, num;
 	int success=0, fail=0;
 		return NULL;
 
 
-/* let SDL do some basic initialization */
-	if(!initialized_once)
-	{
-		initialized_once = 1;
-#ifdef MS_WIN32
-		SDL_RegisterApp("pygame", 0, GetModuleHandle(NULL));
-#endif
-#if defined(macintosh)
-#if(!defined(__MWERKS__) && !TARGET_API_MAC_CARBON)
-		SDL_InitQuickDraw(&qd);
-#endif
-#endif
-#if defined(darwin)
-                StartTheDamnApplication();
-#endif
-		/*nice to initialize timer, so startup time will be correct before init call*/
-		SDL_Init(SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE);
-		Py_AtExit(atexit_quit);
-		install_parachute();
-	}
+        /*nice to initialize timer, so startup time will reflec init() time*/
+        SDL_Init(SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE);
 
 
 /* initialize all pygame modules */
 #ifdef DO_CRASH_TRACEBACK
 	PyThreadState* thread;
 	PyInterpreterState *interp;
+        int thread_id;
 #endif	  
     
 	signal(sig, SIG_DFL);
 			signaltype = "(pygame parachute) Unknown Signal"; break;
 	}
 
+        
 #ifdef DO_CRASH_TRACEBACK
-printf("DOING TRACEBACK, experimental...\n");
+        printf("Pygame Parachute Traceback:\n");
 	interp = PyInterpreterState_Head();
-	for(thread=PyInterpreterState_ThreadHead(interp); thread; thread = PyThreadState_Next(thread))
+        thread=PyInterpreterState_ThreadHead(interp);
+        if(PyThreadState_Next(thread)) /*multithreaded*/
+            thread_id = 0;
+        else
+            thread_id = -1; /*no threads, don't print thread info*/
+	for(; thread; thread = PyThreadState_Next(thread))
 	{
+            if(thread_id >= 0)
+            {
+                printf("Thread-%p\n", thread);
+                thread_id++;
+            }
 	    PyTraceBack_Here(thread->frame);
 	    Py_INCREF(thread->curexc_traceback);
 	    print_traceback(thread->curexc_traceback);
 	}
 #else
-printf("  (No Traceback Without Python2.2)\n");
+        printf("  (No Traceback Without Python2.2)\n");
 #endif
 	
 	atexit_quit();
 	0 /*end of list*/
 };
 
+static int parachute_installed = 0;
 static void install_parachute(void)
 {
 	int i;
 	void (*ohandler)(int);
 
-#if 1
+        if(parachute_installed)
+            return;
+        parachute_installed = 1;
+
 	/* Set a handler for any fatal signal not already handled */
 	for ( i=0; fatal_signals[i]; ++i )
 	{
 			sigaction(SIGALRM, &oaction, NULL);
 	}
 #endif
-#endif
 	return;
 }
 
 	int i;
 	void (*ohandler)(int);
 
+        if(!parachute_installed)
+            return;
+        parachute_installed = 0;
+
 	/* Remove a handler for any fatal signal handled */
 	for ( i=0; fatal_signals[i]; ++i ) {
 		ohandler = signal(fatal_signals[i], SIG_DFL);
 	PyDict_SetItemString(dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
 	Py_DECREF(apiobj);
 
-
-	/*touch PyGAME_C_API to keep compiler from warning*/
-	PyGAME_C_API[0] = PyGAME_C_API[0];
+        /*some intiialization*/
+        Py_AtExit(atexit_quit);
+        install_parachute();
+#ifdef MS_WIN32
+        SDL_RegisterApp("pygame", 0, GetModuleHandle(NULL));
+#endif
+#if defined(macintosh)
+#if(!defined(__MWERKS__) && !TARGET_API_MAC_CARBON)
+        SDL_InitQuickDraw(&qd);
+#endif
+#endif
+#if defined(darwin)
+        StartTheDamnApplication();
+#endif
 }
 
 

File src/constants.c

     Pete Shinners
     pete@shinners.org
 */
-
+#define NO_PYGAME_C_API
 #include "pygame.h"
 
 
 {
 	PyObject* module;
 
-	PyGAME_C_API[0] = PyGAME_C_API[0]; /*this cleans up compiler warning*/
-
-
 	module = Py_InitModule3("constants", builtins, doc_pygame_constants_MODULE);
 
 	DEC_CONST(SWSURFACE);

File src/pygame.h

 
 
 
-
+#ifndef NO_PYGAME_C_API
 #define PYGAMEAPI_TOTALSLOTS 60
 static void* PyGAME_C_API[PYGAMEAPI_TOTALSLOTS] = {NULL};
+#endif
 
 
 /*last platform compiler stuff*/
 	PyObject *module, *dict, *apiobj;
 	static void* c_api[PYGAMEAPI_RECT_NUMSLOTS];
 	
-	PyGAME_C_API[0] = PyGAME_C_API[0]; /*this cleans a compiler warning*/
-
 	/* Create the module and add the functions */
 	PyType_Init(PyRect_Type);
 

File src/rotozoom.c

 
 */
 
+#define NO_PYGAME_C_API
 #include "pygame.h"
+
+
 typedef struct tColorRGBA {
 	Uint8 r; Uint8 g; Uint8 b; Uint8 a;
 } tColorRGBA;

File src/rwobject.c

 /*
  *  SDL_RWops support for python objects
  */
+#define NO_PYGAME_C_API
 #define PYGAMEAPI_RWOBJECT_INTERNAL
 #include "pygame.h"
 
 	PyObject *module, *dict, *apiobj;
 	static void* c_api[PYGAMEAPI_RWOBJECT_NUMSLOTS];
 
-	PyGAME_C_API[0] = PyGAME_C_API[0]; /*this cleans a compiler warning*/
-
 	/* Create the module and add the functions */
 	module = Py_InitModule3("rwobject", rwobject__builtins__, "SDL_RWops support");
 	dict = PyModule_GetDict(module);