annotate test/testloadso.c @ 2915:deb377097225

Fixed CPU feature detection on x86_64 platform (registers were being corrupted, causing crashes)
author Sam Lantinga <slouken@libsdl.org>
date Wed, 24 Dec 2008 13:13:38 +0000
parents 2c835d58faad
children 9de326b3099c
rev   line source
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 /* Test program to test dynamic loading with the loadso subsystem.
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 */
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 #include <stdio.h>
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 #include <stdlib.h>
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 #include "SDL.h"
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
10 typedef int (*fntype) (const char *);
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
12 int
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
13 main(int argc, char *argv[])
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 {
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
15 int retval = 0;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
16 int hello = 0;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
17 const char *libname = NULL;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
18 const char *symname = NULL;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
19 void *lib = NULL;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
20 fntype fn = NULL;
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
22 if (argc != 3) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
23 const char *app = argv[0];
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
24 fprintf(stderr, "USAGE: %s <library> <functionname>\n", app);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
25 fprintf(stderr, " %s --hello <lib with puts()>\n", app);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
26 return 1;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
27 }
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
29 /* Initialize SDL */
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
30 if (SDL_Init(0) < 0) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
31 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
32 return 2;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
33 }
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
35 if (strcmp(argv[1], "--hello") == 0) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
36 hello = 1;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
37 libname = argv[2];
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
38 symname = "puts";
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
39 } else {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
40 libname = argv[1];
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
41 symname = argv[2];
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
42 }
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
44 lib = SDL_LoadObject(libname);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
45 if (lib == NULL) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
46 fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n",
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
47 libname, SDL_GetError());
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
48 retval = 3;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
49 } else {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
50 fn = (fntype) SDL_LoadFunction(lib, symname);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
51 if (fn == NULL) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
52 fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n",
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
53 symname, SDL_GetError());
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
54 retval = 4;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
55 } else {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
56 printf("Found %s in %s at %p\n", symname, libname, fn);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
57 if (hello) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
58 printf("Calling function...\n");
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
59 fflush(stdout);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
60 fn(" HELLO, WORLD!\n");
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
61 printf("...apparently, we survived. :)\n");
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
62 printf("Unloading library...\n");
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
63 fflush(stdout);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
64 }
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
65 }
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
66 SDL_UnloadObject(lib);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
67 }
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
68 SDL_Quit();
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
69 return (0);
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 }