Mercurial > sdl-ios-xcode
annotate test/torturethread.c @ 1211:304d8dd6a989
To: sdl@libsdl.org
From: Christian Walther <cwalther@gmx.ch>
Date: Wed, 28 Dec 2005 12:13:20 +0100
Subject: [SDL] Fix for opening documents on Mac OS X < 10.4
The current code in SDLMain.m that transforms documents opened from the
Finder into command-line arguments (introduced in revision 1.14,
2005-08-11) uses the methods -[NSString lengthOfBytesUsingEncoding:] and
-[NSString getCString:maxLength:encoding:], which are only available in
Mac OS X 10.4.
Compiling this code on 10.3 produces warnings, and running it (i.e.
starting an SDL application by opening a document) leads to weird
behavior which I didn't investigate in detail ("*** -[NSCFString
lengthOfBytesUsingEncoding:]: selector not recognized" is printed to the
console log, and the SDL window never opens).
The attached patch removes the offending calls and uses -[NSString
UTF8String] instead, which is available everywhere. Tested on 10.3.9,
and I see no reason why it shouldn't also work on 10.2 and 10.4.
Two further comments:
* The comment above the -[SDLMain application: openFile:] implementation
says "You need to have a CFBundleDocumentsType section in your
Info.plist to get this message, apparently." This is not the case in my
experience - it worked just fine with a hand-built bare-bones
application consisting only of Test.app/Contents/MacOS/test, without any
Info.plist (although you have to press the option and command keys for
such an application to accept a dragged file).
* I took the liberty of cleaning up another area of SDLMain.m: I changed
"CustomApplicationMain (argc, argv)" to "CustomApplicationMain (int
argc, char **argv)". This avoids the "type of `argv' defaults to `int'"
warnings, and I'm not sure if leaving out the types could cause problems
on platforms where an int and a char** aren't of the same size.
-Christian
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 01 Jan 2006 23:45:52 +0000 |
parents | d93862a3d821 |
children | 1dd8bf30a109 |
rev | line source |
---|---|
0 | 1 |
2 /* Simple test of the SDL threading code */ | |
3 | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <signal.h> | |
7 #include <string.h> | |
8 | |
9 #include "SDL.h" | |
10 #include "SDL_thread.h" | |
11 | |
12 #define NUMTHREADS 10 | |
13 | |
14 static char volatile time_for_threads_to_die[NUMTHREADS]; | |
15 | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
16 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
17 static void quit(int rc) |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
18 { |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
19 SDL_Quit(); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
20 exit(rc); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
21 } |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
22 |
0 | 23 int SubThreadFunc(void *data) { |
24 while(! *(int volatile *)data) { | |
1154
d93862a3d821
Fixed compiler warnings in Watcom C.
Ryan C. Gordon <icculus@icculus.org>
parents:
1151
diff
changeset
|
25 ; /*SDL_Delay(10);*/ /* do nothing */ |
0 | 26 } |
27 return 0; | |
28 } | |
29 | |
30 int ThreadFunc(void *data) { | |
31 SDL_Thread *sub_threads[NUMTHREADS]; | |
32 int flags[NUMTHREADS]; | |
33 int i; | |
34 int tid = (int ) data; | |
35 | |
36 fprintf(stderr, "Creating Thread %d\n", tid); | |
37 | |
38 for(i = 0; i < NUMTHREADS; i++) { | |
39 flags[i] = 0; | |
40 sub_threads[i] = SDL_CreateThread(SubThreadFunc, &flags[i]); | |
41 } | |
42 | |
43 printf("Thread '%d' waiting for signal\n", tid); | |
44 while(time_for_threads_to_die[tid] != 1) { | |
45 ; /* do nothing */ | |
46 } | |
47 | |
48 printf("Thread '%d' sending signals to subthreads\n", tid); | |
49 for(i = 0; i < NUMTHREADS; i++) { | |
50 flags[i] = 1; | |
51 SDL_WaitThread(sub_threads[i], NULL); | |
52 } | |
53 | |
54 printf("Thread '%d' exiting!\n", tid); | |
55 | |
56 return 0; | |
57 } | |
58 | |
59 int main(int argc, char *argv[]) | |
60 { | |
61 SDL_Thread *threads[NUMTHREADS]; | |
62 int i; | |
63 | |
64 /* Load the SDL library */ | |
65 if ( SDL_Init(0) < 0 ) { | |
66 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
67 return(1); |
0 | 68 } |
69 | |
70 signal(SIGSEGV, SIG_DFL); | |
71 for(i = 0; i < NUMTHREADS; i++) { | |
72 time_for_threads_to_die[i] = 0; | |
73 threads[i] = SDL_CreateThread(ThreadFunc, (void *) i); | |
74 | |
75 if ( threads[i] == NULL ) { | |
76 fprintf(stderr, | |
77 "Couldn't create thread: %s\n", SDL_GetError()); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
78 quit(1); |
0 | 79 } |
80 } | |
81 | |
82 for(i = 0; i < NUMTHREADS; i++) { | |
83 time_for_threads_to_die[i] = 1; | |
84 } | |
85 | |
86 for(i = NUMTHREADS-1; i >= 0; --i) { | |
87 SDL_WaitThread(threads[i], NULL); | |
88 } | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
89 SDL_Quit(); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
90 return(0); |
0 | 91 } |