Add -pedantic for shits 'n giggles.

Fix portability issues with void* -> void (*)(void) casts.
Use a more ... bizarre technique ;)
This commit is contained in:
Themaister 2011-05-31 15:03:59 +02:00
parent 9c9eee5d01
commit 44c52ca4f8
11 changed files with 88 additions and 57 deletions

View File

@ -77,10 +77,6 @@ else
endif endif
endif endif
ifeq ($(HAVE_FBO), 1)
DEFINES += -DHAVE_FBO
endif
ifeq ($(HAVE_XVIDEO), 1) ifeq ($(HAVE_XVIDEO), 1)
OBJ += gfx/xvideo.o input/x11_input.o OBJ += gfx/xvideo.o input/x11_input.o
LIBS += -lXv -lX11 LIBS += -lXv -lX11
@ -133,7 +129,7 @@ ifneq ($(V),1)
Q := @ Q := @
endif endif
CFLAGS += -Wall -O3 -g -I. CFLAGS += -Wall -O3 -g -I. -pedantic
ifneq ($(findstring icc,$(CC)),) ifneq ($(findstring icc,$(CC)),)
CFLAGS += -std=c99 CFLAGS += -std=c99
else else

View File

@ -64,7 +64,7 @@ static void* audio_ext_init(const char *device, unsigned rate, unsigned latency)
goto error; goto error;
} }
const ssnes_audio_driver_t* (*plugin_load)(void) = dylib_proc(ext->lib, "ssnes_audio_driver_init"); const ssnes_audio_driver_t* (*plugin_load)(void) = (const ssnes_audio_driver_t* (*)(void))dylib_proc(ext->lib, "ssnes_audio_driver_init");
if (!plugin_load) if (!plugin_load)
{ {

View File

@ -161,7 +161,8 @@ static void init_dsp_plugin(void)
return; return;
} }
const ssnes_dsp_plugin_t* (*SSNES_API_CALLTYPE plugin_init)(void) = dylib_proc(g_extern.audio_data.dsp_lib, "ssnes_dsp_plugin_init"); const ssnes_dsp_plugin_t* (*SSNES_API_CALLTYPE plugin_init)(void) =
(const ssnes_dsp_plugin_t *(*)(void))dylib_proc(g_extern.audio_data.dsp_lib, "ssnes_dsp_plugin_init");
if (!plugin_init) if (!plugin_init)
{ {
SSNES_ERR("Failed to find symbol \"ssnes_dsp_plugin_init\" in DSP plugin.\n"); SSNES_ERR("Failed to find symbol \"ssnes_dsp_plugin_init\" in DSP plugin.\n");
@ -310,8 +311,12 @@ static void init_filter(void)
return; return;
} }
g_extern.filter.psize = dylib_proc(g_extern.filter.lib, "filter_size"); g_extern.filter.psize =
g_extern.filter.prender = dylib_proc(g_extern.filter.lib, "filter_render"); (void (*)(unsigned*, unsigned*))dylib_proc(g_extern.filter.lib, "filter_size");
g_extern.filter.prender =
(void (*)(uint32_t*, uint32_t*,
unsigned, const uint16_t*,
unsigned, unsigned, unsigned))dylib_proc(g_extern.filter.lib, "filter_render");
if (!g_extern.filter.psize || !g_extern.filter.prender) if (!g_extern.filter.psize || !g_extern.filter.prender)
{ {
SSNES_ERR("Failed to find functions in filter...\n"); SSNES_ERR("Failed to find functions in filter...\n");

View File

@ -18,6 +18,7 @@
#include "dynamic.h" #include "dynamic.h"
#include "general.h" #include "general.h"
#include <string.h> #include <string.h>
#include <assert.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -34,13 +35,13 @@
#ifdef HAVE_DYNAMIC #ifdef HAVE_DYNAMIC
#define DLSYM(lib, x) dylib_proc(lib, #x) #define DLSYM(lib, x) dylib_proc(lib, #x)
#define SYM(x) do { \ #define SYM(type, x) do { \
p##x = DLSYM(lib_handle, x); \ p##x = (type)DLSYM(lib_handle, x); \
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \ if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
} while(0) } while(0)
#define OPT_SYM(x) do { \ #define OPT_SYM(type, x) do { \
p##x = DLSYM(lib_handle, x); \ p##x = (type)DLSYM(lib_handle, x); \
} while(0) } while(0)
static dylib_t lib_handle = NULL; static dylib_t lib_handle = NULL;
@ -106,33 +107,38 @@ static void load_dynamic(void)
exit(1); exit(1);
} }
SYM(snes_init); SYM(void (*)(void), snes_init);
SYM(snes_set_video_refresh); SYM(void (*)(snes_video_refresh_t), snes_set_video_refresh);
SYM(snes_set_audio_sample); SYM(void (*)(snes_audio_sample_t), snes_set_audio_sample);
SYM(snes_set_input_poll); SYM(void (*)(snes_input_poll_t), snes_set_input_poll);
SYM(snes_set_input_state); SYM(void (*)(snes_input_state_t), snes_set_input_state);
OPT_SYM(snes_library_id); OPT_SYM(const char *(*)(void), snes_library_id);
SYM(snes_library_revision_minor); SYM(unsigned (*)(void), snes_library_revision_minor);
SYM(snes_library_revision_major); SYM(unsigned (*)(void), snes_library_revision_major);
SYM(snes_cheat_reset); SYM(void (*)(void), snes_cheat_reset);
SYM(snes_cheat_set); SYM(void (*)(unsigned, bool, const char*), snes_cheat_set);
SYM(snes_reset); SYM(void (*)(void), snes_reset);
SYM(snes_run); SYM(void (*)(void), snes_run);
SYM(snes_get_region); SYM(bool (*)(void), snes_get_region);
SYM(snes_load_cartridge_normal); SYM(bool (*)(const char*, const uint8_t*, unsigned), snes_load_cartridge_normal);
SYM(snes_load_cartridge_super_game_boy); SYM(bool (*)(const char*, const uint8_t*, unsigned,
SYM(snes_load_cartridge_bsx); const char*, const uint8_t*, unsigned), snes_load_cartridge_super_game_boy);
SYM(snes_load_cartridge_bsx_slotted); SYM(bool (*)(const char*, const uint8_t*, unsigned,
SYM(snes_load_cartridge_sufami_turbo); const char*, const uint8_t*, unsigned), snes_load_cartridge_bsx);
SYM(snes_set_controller_port_device); SYM(bool (*)(const char*, const uint8_t*, unsigned,
SYM(snes_serialize_size); const char*, const uint8_t*, unsigned), snes_load_cartridge_bsx_slotted);
SYM(snes_serialize); SYM(bool (*)(const char*, const uint8_t*, unsigned,
SYM(snes_unserialize); const char*, const uint8_t*, unsigned,
SYM(snes_set_cartridge_basename); const char*, const uint8_t*, unsigned), snes_load_cartridge_sufami_turbo);
SYM(snes_get_memory_data); SYM(void (*)(bool, unsigned), snes_set_controller_port_device);
SYM(snes_get_memory_size); SYM(unsigned (*)(void), snes_serialize_size);
SYM(snes_unload_cartridge); SYM(bool (*)(uint8_t*, unsigned), snes_serialize);
SYM(snes_term); SYM(bool (*)(const uint8_t*, unsigned), snes_unserialize);
SYM(void (*)(const char*), snes_set_cartridge_basename);
SYM(uint8_t *(*)(unsigned), snes_get_memory_data);
SYM(unsigned (*)(unsigned), snes_get_memory_size);
SYM(void (*)(void), snes_unload_cartridge);
SYM(void (*)(void), snes_term);
} }
#endif #endif
@ -174,6 +180,9 @@ static void set_statics(void)
void init_dlsym(void) void init_dlsym(void)
{ {
// Guarantee that we can do "dirty" casting. Every OS that this program supports should pass this ...
assert(sizeof(void*) == sizeof(void (*)(void)));
#ifdef HAVE_DYNAMIC #ifdef HAVE_DYNAMIC
if (strlen(g_settings.libsnes) > 0) if (strlen(g_settings.libsnes) > 0)
load_dynamic(); load_dynamic();
@ -205,12 +214,15 @@ dylib_t dylib_load(const char *path)
#endif #endif
} }
void* dylib_proc(dylib_t lib, const char *proc) function_t dylib_proc(dylib_t lib, const char *proc)
{ {
#ifdef _WIN32 #ifdef _WIN32
void *sym = (void*)GetProcAddress(lib, proc); function_t sym = (function_t)GetProcAddress(lib, proc);
#else #else
void *sym = dlsym(lib, proc); // Dirty hack to workaround the non-legality of void* -> fn-pointer casts.
void *ptr_sym = dlsym(lib, proc);
function_t sym;
memcpy(&sym, &ptr_sym, sizeof(void*));
#endif #endif
if (!sym) if (!sym)

View File

@ -25,10 +25,11 @@ void init_dlsym(void);
void uninit_dlsym(void); void uninit_dlsym(void);
typedef void *dylib_t; typedef void *dylib_t;
typedef void (*function_t)(void);
dylib_t dylib_load(const char *path); dylib_t dylib_load(const char *path);
void dylib_close(dylib_t lib); void dylib_close(dylib_t lib);
void* dylib_proc(dylib_t lib, const char *proc); function_t dylib_proc(dylib_t lib, const char *proc);
extern void (*psnes_init)(void); extern void (*psnes_init)(void);

View File

@ -274,19 +274,19 @@ void parse_config(void);
extern struct settings g_settings; extern struct settings g_settings;
extern struct global g_extern; extern struct global g_extern;
#define SSNES_LOG(msg, args...) do { \ #define SSNES_LOG(...) do { \
if (g_extern.verbose) \ if (g_extern.verbose) \
fprintf(stderr, "SSNES: " msg, ##args); \ fprintf(stderr, "SSNES: " __VA_ARGS__); \
fflush(stderr); \ fflush(stderr); \
} while(0) } while(0)
#define SSNES_ERR(msg, args...) do { \ #define SSNES_ERR(...) do { \
fprintf(stderr, "SSNES [ERROR] :: " msg, ##args); \ fprintf(stderr, "SSNES [ERROR] :: " __VA_ARGS__); \
fflush(stderr); \ fflush(stderr); \
} while(0) } while(0)
#define SSNES_WARN(msg, args...) do { \ #define SSNES_WARN(...) do { \
fprintf(stderr, "SSNES [WARN] :: " msg, ##args); \ fprintf(stderr, "SSNES [WARN] :: " __VA_ARGS__); \
fflush(stderr); \ fflush(stderr); \
} while(0) } while(0)

View File

@ -273,7 +273,8 @@ static void* video_ext_init(const video_info_t *video, const input_driver_t **in
goto error; goto error;
} }
const ssnes_video_driver_t* (*video_init)(void) = dylib_proc(g_lib, "ssnes_video_init"); const ssnes_video_driver_t* (*video_init)(void) =
(const ssnes_video_driver_t *(*)(void))dylib_proc(g_lib, "ssnes_video_init");
if (!video_init) if (!video_init)
{ {
SSNES_ERR("Couldn't find function ssnes_video_init in library ...\n"); SSNES_ERR("Couldn't find function ssnes_video_init in library ...\n");

View File

@ -81,7 +81,7 @@ static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D = NULL;
static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus = NULL; static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus = NULL;
static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers = NULL; static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers = NULL;
#define LOAD_SYM(sym) if (!p##sym) p##sym = ((void*)SDL_GL_GetProcAddress(#sym)) #define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) }
static bool load_fbo_proc(void) static bool load_fbo_proc(void)
{ {
LOAD_SYM(glGenFramebuffers); LOAD_SYM(glGenFramebuffers);
@ -942,12 +942,21 @@ static void gl_set_nonblock_state(void *data, bool state)
SSNES_LOG("GL VSync => %s\n", state ? "off" : "on"); SSNES_LOG("GL VSync => %s\n", state ? "off" : "on");
#ifdef _WIN32 #ifdef _WIN32
static BOOL (APIENTRY *wgl_swap_interval)(int) = NULL; static BOOL (APIENTRY *wgl_swap_interval)(int) = NULL;
if (!wgl_swap_interval) wgl_swap_interval = (BOOL (APIENTRY*)(int)) SDL_GL_GetProcAddress("wglSwapIntervalEXT"); if (!wgl_swap_interval)
{
SDL_SYM_WRAP(wgl_swap_interval, "wglSwapIntervalEXT");
}
if (wgl_swap_interval) wgl_swap_interval(state ? 0 : 1); if (wgl_swap_interval) wgl_swap_interval(state ? 0 : 1);
#else #else
static int (*glx_swap_interval)(int) = NULL; static int (*glx_swap_interval)(int) = NULL;
if (!glx_swap_interval) glx_swap_interval = (int (*)(int))SDL_GL_GetProcAddress("glXSwapIntervalSGI"); if (!glx_swap_interval)
if (!glx_swap_interval) glx_swap_interval = (int (*)(int))SDL_GL_GetProcAddress("glXSwapIntervalMESA"); {
SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalSGI");
}
if (!glx_swap_interval)
{
SDL_SYM_WRAP(glx_swap_interval, "glxSwapIntervalMESA");
}
if (glx_swap_interval) glx_swap_interval(state ? 0 : 1); if (glx_swap_interval) glx_swap_interval(state ? 0 : 1);
#endif #endif
} }

View File

@ -106,6 +106,13 @@ struct gl_tex_info
float coord[8]; float coord[8];
}; };
// Not legal to cast void* to fn-pointer. Need dirty hack to be compilant.
// sizeof(void*) == sizeof(void (*)(void)) is asserted earlier.
#define SDL_SYM_WRAP(sym, symbol) { \
void *sym__ = SDL_GL_GetProcAddress(symbol); \
memcpy(&(sym), &sym__, sizeof(void*)); \
}
// Windows ... <_< // Windows ... <_<
#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) #if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32)
extern PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture; extern PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture;

View File

@ -321,7 +321,7 @@ static bool load_plain(const char *path)
return true; return true;
} }
#define print_buf(buf, args...) snprintf(buf, sizeof(buf), ##args) #define print_buf(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__)
#ifdef HAVE_CONFIGFILE #ifdef HAVE_CONFIGFILE
static bool load_textures(const char *dir_path, config_file_t *conf) static bool load_textures(const char *dir_path, config_file_t *conf)

View File

@ -706,7 +706,7 @@ static bool compile_programs(GLuint *gl_prog, struct shader_program *progs, size
return true; return true;
} }
#define LOAD_GL_SYM(SYM) if (!(pgl##SYM)) pgl##SYM = SDL_GL_GetProcAddress("gl" #SYM) #define LOAD_GL_SYM(SYM) if (!pgl##SYM) { SDL_SYM_WRAP(pgl##SYM, "gl" #SYM) }
bool gl_glsl_init(const char *path) bool gl_glsl_init(const char *path)
{ {