comparison src/SDL.c @ 3647:c5925cd41955

First pass at Ryan's assertion code, minor tweaks to come.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 13 Jan 2010 06:47:17 +0000
parents 63d4517fc4ac
children bc50cd16bb07
comparison
equal deleted inserted replaced
3646:88235d40b135 3647:c5925cd41955
23 23
24 /* Initialization code for SDL */ 24 /* Initialization code for SDL */
25 25
26 #include "SDL.h" 26 #include "SDL.h"
27 #include "SDL_fatal.h" 27 #include "SDL_fatal.h"
28 #include "SDL_assert.h"
29
28 #if !SDL_VIDEO_DISABLED 30 #if !SDL_VIDEO_DISABLED
29 #include "video/SDL_leaks.h" 31 #include "video/SDL_leaks.h"
30 #endif 32 #endif
31 33
32 #if SDL_THREAD_PTH 34 #if SDL_THREAD_PTH
49 #endif 51 #endif
50 #if defined(__WIN32__) 52 #if defined(__WIN32__)
51 extern int SDL_HelperWindowCreate(void); 53 extern int SDL_HelperWindowCreate(void);
52 extern int SDL_HelperWindowDestroy(void); 54 extern int SDL_HelperWindowDestroy(void);
53 #endif 55 #endif
56
57 extern int SDL_AssertionsInit(void);
58 extern void SDL_AssertionsQuit(void);
54 59
55 /* The initialized subsystems */ 60 /* The initialized subsystems */
56 static Uint32 SDL_initialized = 0; 61 static Uint32 SDL_initialized = 0;
57 static Uint32 ticks_started = 0; 62 static Uint32 ticks_started = 0;
58 63
151 if (!pth_init()) { 156 if (!pth_init()) {
152 return -1; 157 return -1;
153 } 158 }
154 #endif 159 #endif
155 160
161 if (SDL_AssertionsInit() < 0) {
162 return -1;
163 }
164
156 /* Clear the error message */ 165 /* Clear the error message */
157 SDL_ClearError(); 166 SDL_ClearError();
158 167
159 #if defined(__WIN32__) 168 #if defined(__WIN32__)
160 if (SDL_HelperWindowCreate() < 0) { 169 if (SDL_HelperWindowCreate() < 0) {
169 178
170 /* Everything is initialized */ 179 /* Everything is initialized */
171 if (!(flags & SDL_INIT_NOPARACHUTE)) { 180 if (!(flags & SDL_INIT_NOPARACHUTE)) {
172 SDL_InstallParachute(); 181 SDL_InstallParachute();
173 } 182 }
183
184 /* brief sanity checks for the sanity checks. :) */
185 SDL_assert(1);
186 SDL_assert_release(1);
187 SDL_assert_paranoid(1);
188 SDL_assert(0 || 1);
189 SDL_assert_release(0 || 1);
190 SDL_assert_paranoid(0 || 1);
191
192 #if 0 /* enable this to test assertion failures. */
193 SDL_assert_release(1 == 2);
194 SDL_assert_release(5 < 4);
195 SDL_assert_release(0 && "This is a test");
196 #endif
197
174 return (0); 198 return (0);
175 } 199 }
176 200
177 void 201 void
178 SDL_QuitSubSystem(Uint32 flags) 202 SDL_QuitSubSystem(Uint32 flags)
237 #ifdef DEBUG_BUILD 261 #ifdef DEBUG_BUILD
238 printf("[SDL_Quit] : CHECK_LEAKS\n"); 262 printf("[SDL_Quit] : CHECK_LEAKS\n");
239 fflush(stdout); 263 fflush(stdout);
240 #endif 264 #endif
241 265
266 /* !!! FIXME: make this an assertion. */
242 /* Print the number of surfaces not freed */ 267 /* Print the number of surfaces not freed */
243 if (surfaces_allocated != 0) { 268 if (surfaces_allocated != 0) {
244 fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n", 269 fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n",
245 surfaces_allocated); 270 surfaces_allocated);
246 } 271 }
250 fflush(stdout); 275 fflush(stdout);
251 #endif 276 #endif
252 277
253 /* Uninstall any parachute signal handlers */ 278 /* Uninstall any parachute signal handlers */
254 SDL_UninstallParachute(); 279 SDL_UninstallParachute();
280
281 SDL_AssertionsQuit();
255 282
256 #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH 283 #if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
257 pth_kill(); 284 pth_kill();
258 #endif 285 #endif
259 #ifdef DEBUG_BUILD 286 #ifdef DEBUG_BUILD