Skip to content

Commit

Permalink
Cleaned up symbol loading macro salsa a bit more.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 13, 2019
1 parent 5dfa5ad commit 0b40e3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 3 additions & 12 deletions src/SDL12_compat.c
Expand Up @@ -114,14 +114,8 @@
#define SDL20_SYM(rc,fn,params,args,ret) \
typedef rc (SDLCALL *SDL20_##fn##_t) params; \
static SDL20_##fn##_t SDL20_##fn = NULL;
#define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) \
SDL20_SYM(rc,fn,params,args,ret)
#include "SDL20_syms.h"

/* this doesn't get handled in SDL20_syms.h because it uses varargs. */
typedef int (SDLCALL *SDL20_SetError_t)(const char *fmt, ...);
static SDL20_SetError_t SDL20_SetError = NULL;

/* Things that _should_ be binary compatible pass right through... */
#define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) \
DECLSPEC rc SDLCALL SDL_##fn params { ret SDL20_##fn args; }
Expand Down Expand Up @@ -491,8 +485,9 @@ LoadSDL20Symbol(const char *fn, int *okay)
if (*okay) /* only bother trying if we haven't previously failed. */
{
retval = LookupSDL20Sym(fn);
if (retval == NULL)
*okay = 0;
if (!retval) { fprintf(stderr, "WARNING: LOAD FAILED: %s\n", fn); }
// if (retval == NULL)
// *okay = 0;
}
return retval;
}
Expand All @@ -501,9 +496,7 @@ static void
UnloadSDL20(void)
{
#define SDL20_SYM(rc,fn,params,args,ret) SDL20_##fn = NULL;
#define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) SDL20_SYM(rc,fn,params,args,ret)
#include "SDL20_syms.h"
SDL20_SetError = NULL;
CloseSDL20Library();
}

Expand All @@ -515,9 +508,7 @@ LoadSDL20(void)
{
okay = LoadSDL20Library();
#define SDL20_SYM(rc,fn,params,args,ret) SDL20_##fn = (SDL20_##fn##_t) LoadSDL20Symbol("SDL_" #fn, &okay);
#define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) SDL20_SYM(rc,fn,params,args,ret)
#include "SDL20_syms.h"
SDL20_SetError = (SDL20_SetError_t) LoadSDL20Symbol("SDL_SetError", &okay);
if (!okay)
UnloadSDL20();
}
Expand Down
13 changes: 10 additions & 3 deletions src/SDL20_syms.h
Expand Up @@ -26,13 +26,19 @@
#endif

#ifndef SDL20_SYM_PASSTHROUGH
#define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret)
#define SDL20_SYM_PASSTHROUGH(rc,fn,params,args,ret) SDL20_SYM(rc,fn,params,args,ret)
#endif

#ifndef SDL20_SYM_VARARGS
#define SDL20_SYM_VARARGS(rc,fn,params) SDL20_SYM(rc,fn,params,unused,unused)
#endif

SDL20_SYM(int,Init,(Uint32 a),(a),return)
SDL20_SYM(int,InitSubSystem,(Uint32 a),(a),return)
SDL20_SYM(Uint32,WasInit,(Uint32 a),(a),return)
SDL20_SYM(char*,GetError,(void),(),return)
SDL20_SYM_VARARGS(int,SetError,(const char *fmt, ...))

SDL20_SYM_PASSTHROUGH(int,Error,(SDL_errorcode a),(a),return)
SDL20_SYM_PASSTHROUGH(void,ClearError,(void),(),)
SDL20_SYM(void,Quit,(void),(),)
Expand Down Expand Up @@ -222,8 +228,8 @@ SDL20_SYM_PASSTHROUGH(int,strcmp,(const char *a, const char *b),(a,b),return)
SDL20_SYM_PASSTHROUGH(int,strncmp,(const char *a, const char *b, size_t c),(a,b,c),return)
SDL20_SYM_PASSTHROUGH(int,strcasecmp,(const char *a, const char *b),(a,b),return)
SDL20_SYM_PASSTHROUGH(int,strncasecmp,(const char *a, const char *b, size_t c),(a,b,c),return)
//SDL20_SYM_PASSTHROUGH(int,sscanf,(const char *text, const char *fmt, ...);
//SDL20_SYM_PASSTHROUGH(int,snprintf,(char *text, size_t maxlen, const char *fmt, ...);
SDL20_SYM_VARARGS(int,sscanf,(const char *text, const char *fmt, ...))
SDL20_SYM_VARARGS(int,snprintf,(char *text, size_t maxlen, const char *fmt, ...))
SDL20_SYM_PASSTHROUGH(int,vsnprintf,(char *a, size_t b, const char *c, va_list d),(a,b,c,d),return)
SDL20_SYM_PASSTHROUGH(SDL_iconv_t,iconv_open,(const char *a, const char *b),(a,b),return)
SDL20_SYM_PASSTHROUGH(int,iconv_close,(SDL_iconv_t a),(a),return)
Expand All @@ -234,6 +240,7 @@ SDL20_SYM(int,atoi,(const char *a),(a),return)

#undef SDL20_SYM
#undef SDL20_SYM_PASSTHROUGH
#undef SDL20_SYM_VARARGS

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 0b40e3e

Please sign in to comment.