test/testerror.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 09 May 2006 07:26:58 +0000
changeset 1790 828a17e05192
parent 1769 290b5baf2fca
child 1662 782fd950bd46
child 1895 c121d94672cb
permissions -rw-r--r--
Date: Mon, 8 May 2006 14:19:30 -0700
From: Bob Ippolito
Subject: SDL trunk (r2346) and Mac OS X

The current state of the trunk doesn't quite compile on Mac OS X,
I've attached a series of patches that gets it to compile and kills a
few warnings.

sdl-trunk-r2346-dlcompat-warnings.diff:
The dlcompat thing is just loaded with incorrect type signatures ..
some of them have changed since 10.2 and others are just flat wrong.
This puts it in sync with the latest headers. People on 10.2 will get
the warnings instead of people with new kits.
     1 
     2 /* Simple test of the SDL threading code and error handling */
     3 
     4 #include <stdio.h>
     5 #include <stdlib.h>
     6 #include <signal.h>
     7 
     8 #include "SDL.h"
     9 #include "SDL_thread.h"
    10 
    11 static int alive = 0;
    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 }
    19 
    20 int SDLCALL ThreadFunc(void *data)
    21 {
    22 	/* Set the child thread error string */
    23 	SDL_SetError("Thread %s (%d) had a problem: %s",
    24 			(char *)data, SDL_ThreadID(), "nevermind");
    25 	while ( alive ) {
    26 		printf("Thread '%s' is alive!\n", (char *)data);
    27 		SDL_Delay(1*1000);
    28 	}
    29 	printf("Child thread error string: %s\n", SDL_GetError());
    30 	return(0);
    31 }
    32 
    33 int main(int argc, char *argv[])
    34 {
    35 	SDL_Thread *thread;
    36 
    37 	/* Load the SDL library */
    38 	if ( SDL_Init(0) < 0 ) {
    39 		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    40 		return(1);
    41 	}
    42 
    43 	/* Set the error value for the main thread */
    44 	SDL_SetError("No worries");
    45 
    46 	alive = 1;
    47 	thread = SDL_CreateThread(ThreadFunc, "#1");
    48 	if ( thread == NULL ) {
    49 		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    50 		quit(1);
    51 	}
    52 	SDL_Delay(5*1000);
    53 	printf("Waiting for thread #1\n");
    54 	alive = 0;
    55 	SDL_WaitThread(thread, NULL);
    56 
    57 	printf("Main thread error string: %s\n", SDL_GetError());
    58 
    59 	SDL_Quit();
    60 	return(0);
    61 }