From 7be4fca62cd0e1f7a9ba820afd016f054922d447 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Mon, 15 Oct 2018 11:01:00 +0300 Subject: [PATCH] SDL_power.c: Adjust SDL_POWER_DISABLED ifdefs to avoid zero-size array Otherwise if SDL_POWER_DISABLED is disabled (eg with --disable-power): ... with clang -pedantic: src/power/SDL_power.c:48:50: warning: use of GNU empty initializer extension [-Wgnu-empty-initializer] static SDL_GetPowerInfo_Impl implementations[] = { ^ src/power/SDL_power.c:48:50: warning: zero size arrays are an extension [-Wzero-length-array] 2 warnings generated. ... with gcc -pedantic: src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic] src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic] static SDL_GetPowerInfo_Impl implementations[] = { ^ src/power/SDL_power.c:48:30: error: zero or negative size array ?implementations? static SDL_GetPowerInfo_Impl implementations[] = { ^~~~~~~~~~~~~~~ ... with Watcom: ./src/power/SDL_power.c(85): Error! E1112: Initializer list cannot be empty --- OWMakefile.os2 | 14 +++++--------- include/SDL_config_os2.h | 1 + src/power/SDL_power.c | 12 ++++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/OWMakefile.os2 b/OWMakefile.os2 index 1bba8c30b..e709835eb 100644 --- a/OWMakefile.os2 +++ b/OWMakefile.os2 @@ -19,15 +19,6 @@ CFLAGS+= $(INCPATH) # building SDL itself: CFLAGS+= -DBUILD_SDL -# this is so that build doesn't fail with E1112: -#CFLAGS+= -DSDL_POWER_DISABLED -CFLAGS+= -DSDL_POWER_HARDWIRED - -.extensions: -.extensions: .lib .dll .obj .c .asm - -.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test; - SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c @@ -58,6 +49,11 @@ SRCS+= SDL_dynapi.c OBJS = $(SRCS:.c=.obj) +.extensions: +.extensions: .lib .dll .obj .c .asm + +.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test; + all: $(DLLFILE) $(LIBFILE) .symbolic $(DLLFILE): $(OBJS) $(LNKFILE) diff --git a/include/SDL_config_os2.h b/include/SDL_config_os2.h index eb1d7d44d..d1e4bb24d 100644 --- a/include/SDL_config_os2.h +++ b/include/SDL_config_os2.h @@ -28,6 +28,7 @@ #define SDL_AUDIO_DRIVER_DUMMY 1 #define SDL_AUDIO_DRIVER_DISK 1 +#define SDL_POWER_DISABLED 1 #define SDL_JOYSTICK_DISABLED 1 #define SDL_HAPTIC_DISABLED 1 /*#undef SDL_JOYSTICK_HIDAPI */ diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c index e09e27ba2..de77c0951 100644 --- a/src/power/SDL_power.c +++ b/src/power/SDL_power.c @@ -42,11 +42,8 @@ SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent) return SDL_TRUE; } #endif -#endif - static SDL_GetPowerInfo_Impl implementations[] = { -#ifndef SDL_POWER_DISABLED #ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */ SDL_GetPowerInfo_Linux_org_freedesktop_upower, SDL_GetPowerInfo_Linux_sys_class_power_supply, @@ -81,31 +78,34 @@ static SDL_GetPowerInfo_Impl implementations[] = { #ifdef SDL_POWER_HARDWIRED SDL_GetPowerInfo_Hardwired, #endif -#endif }; +#endif SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent) { +#ifndef SDL_POWER_DISABLED const int total = sizeof(implementations) / sizeof(implementations[0]); - int _seconds, _percent; SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN; int i; +#endif + int _seconds, _percent; /* Make these never NULL for platform-specific implementations. */ if (seconds == NULL) { seconds = &_seconds; } - if (percent == NULL) { percent = &_percent; } +#ifndef SDL_POWER_DISABLED for (i = 0; i < total; i++) { if (implementations[i](&retval, seconds, percent)) { return retval; } } +#endif /* nothing was definitive. */ *seconds = -1;