comparison test/checkkeys.c @ 1151:be9c9c8f6d53

Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe if SDL is built with a non-cdecl calling convention, and it's just generally bad practice anyhow. Now programs explicitly call SDL_Quit() where appropriate, wrap SDL_Quit() in a cdecl function where it can't be avoided, and rely on the parachute where a crash might have hit the atexit() before (these ARE test programs, after all!).
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 28 Sep 2005 11:36:20 +0000
parents 806fcbde0af3
children 7c7ddaf195bf
comparison
equal deleted inserted replaced
1150:7d8e1925f35b 1151:be9c9c8f6d53
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "SDL.h" 11 #include "SDL.h"
12
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void quit(int rc)
15 {
16 SDL_Quit();
17 exit(rc);
18 }
12 19
13 static void print_modifiers(void) 20 static void print_modifiers(void)
14 { 21 {
15 int mod; 22 int mod;
16 printf(" modifiers:"); 23 printf(" modifiers:");
80 Uint32 videoflags; 87 Uint32 videoflags;
81 88
82 /* Initialize SDL */ 89 /* Initialize SDL */
83 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { 90 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
84 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 91 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
85 exit(1); 92 return(1);
86 } 93 }
87 atexit(SDL_Quit);
88 94
89 videoflags = SDL_SWSURFACE; 95 videoflags = SDL_SWSURFACE;
90 while( argc > 1 ) { 96 while( argc > 1 ) {
91 --argc; 97 --argc;
92 if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) { 98 if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) {
93 videoflags |= SDL_FULLSCREEN; 99 videoflags |= SDL_FULLSCREEN;
94 } else { 100 } else {
95 fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]); 101 fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
96 exit(1); 102 quit(1);
97 } 103 }
98 } 104 }
99 105
100 /* Set 640x480 video mode */ 106 /* Set 640x480 video mode */
101 if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) { 107 if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) {
102 fprintf(stderr, "Couldn't set 640x480 video mode: %s\n", 108 fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
103 SDL_GetError()); 109 SDL_GetError());
104 exit(2); 110 quit(2);
105 } 111 }
106 112
107 /* Enable UNICODE translation for keyboard input */ 113 /* Enable UNICODE translation for keyboard input */
108 SDL_EnableUNICODE(1); 114 SDL_EnableUNICODE(1);
109 115
130 break; 136 break;
131 default: 137 default:
132 break; 138 break;
133 } 139 }
134 } 140 }
141
142 SDL_Quit();
135 return(0); 143 return(0);
136 } 144 }