Fix gcc warnings;

This commit is contained in:
bjorn 2021-02-19 23:10:24 -07:00
parent 5d5c79b5b1
commit fb1447503b
22 changed files with 52 additions and 63 deletions

View File

@ -16,6 +16,11 @@ CFLAGS += -I$(ROOT)/src/lib/stdatomic
CFLAGS += -fvisibility=hidden
CFLAGS += -Wall -Wextra
CFLAGS += -Wno-unused-parameter
CFLAGS_glad.c += -Wno-pedantic
CFLAGS_os_android.c += -Wno-format-pedantic
CFLAGS_headset_openvr.c += -Wno-unused-variable -Wno-typedef-redefinition -Wno-pedantic
CFLAGS_headset_vrapi.c += -Wno-c11-extensions -Wno-gnu-empty-initializer -Wno-pedantic
CFLAGS_miniaudio.c += -Wno-unused-function
CFLAGS_@(STRICT) += -Werror
FLAGS_@(DEBUG) += -g
FLAGS_@(OPTIMIZE) += -Oz
@ -247,7 +252,7 @@ CFLAGS += $(FLAGS) $(FLAGS_y) $(DISABLE_n) $(CFLAGS_y) @(EXTRA_CFLAGS)
LDFLAGS += $(FLAGS) $(FLAGS_y) $(LDFLAGS_y) $(LDFLAGS_y_y) @(EXTRA_LDFLAGS)
## Macros
!cc = |> ^o CC %b^ $(CC) $(CFLAGS) -o %o -c %f |>
!cc = |> ^o CC %b^ $(CC) $(CFLAGS) $(CFLAGS_%b) -o %o -c %f |>
!ld = |> ^ LD %o^ $(CC) -o %o %f $(LDFLAGS) |>
!xd = |> ^ XD %f^ xxd -i %f > %o |>
!cp = |> ^ CP %b^ cp %f %o |>

View File

@ -10,8 +10,9 @@ typedef void destructorFn(void*);
// Object names are lightuserdata because Variants need a non-Lua string due to threads.
static int luax_meta__tostring(lua_State* L) {
lua_getfield(L, -1, "__name");
lua_pushstring(L, (const char*) lua_touserdata(L, -1));
lua_getfield(L, -1, "__info");
TypeInfo* info = lua_touserdata(L, -1);
lua_pushstring(L, info->name);
return 1;
}
@ -19,10 +20,10 @@ static int luax_meta__gc(lua_State* L) {
Proxy* p = lua_touserdata(L, 1);
if (p) {
lua_getmetatable(L, 1);
lua_getfield(L, -1, "__destructor");
destructorFn* destructor = (destructorFn*) lua_tocfunction(L, -1);
if (destructor) {
lovrRelease(p->object, destructor);
lua_getfield(L, -1, "__info");
TypeInfo* info = lua_touserdata(L, -1);
if (info->destructor) {
lovrRelease(p->object, info->destructor);
p->object = NULL;
}
}
@ -50,18 +51,16 @@ void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* function
lua_pushvalue(L, -1);
lua_setfield(L, -1, "__index");
// m.__info = info
TypeInfo* info = lua_newuserdata(L, sizeof(TypeInfo));
info->name = name;
info->destructor = destructor;
lua_setfield(L, -2, "__info");
// m.__gc = gc
lua_pushcfunction(L, luax_meta__gc);
lua_setfield(L, -2, "__gc");
// m.__destructor = destructor (used to release reference)
lua_pushcfunction(L, (lua_CFunction) destructor);
lua_setfield(L, -2, "__destructor");
// m.__name = name
lua_pushlightuserdata(L, (void*) name);
lua_setfield(L, -2, "__name");
// m.__tostring
lua_pushcfunction(L, luax_meta__tostring);
lua_setfield(L, -2, "__tostring");

View File

@ -110,6 +110,11 @@ extern StringEntry lovrWrapMode[];
// General helpers
typedef struct {
const char* name;
void (*destructor)(void*);
} TypeInfo;
typedef struct {
uint64_t hash;
void* object;

View File

@ -111,7 +111,7 @@ static int l_lovrSoundGetFrames(lua_State* L) {
case LUA_TNONE:
lua_settop(L, index - 1);
lua_createtable(L, count * lovrSoundGetChannelCount(sound), 0);
// fallthrough;
// fallthrough
case LUA_TTABLE:
dstOffset = luaL_optinteger(L, index + 1, 1);
lua_settop(L, index);
@ -162,7 +162,7 @@ static int l_lovrSoundGetFrames(lua_State* L) {
lua_pushinteger(L, frames);
return 2;
}
// fallthrough;
// fallthrough
default:
return luax_typeerror(L, index, "nil, table, Blob, or Sound");
}

View File

@ -150,14 +150,11 @@ void luax_checkvariant(lua_State* L, int index, Variant* variant) {
Proxy* proxy = lua_touserdata(L, index);
lua_getmetatable(L, index);
lua_pushliteral(L, "__name");
lua_pushliteral(L, "__info");
lua_rawget(L, -2);
variant->value.object.type = (const char*) lua_touserdata(L, -1);
lua_pop(L, 1);
lua_pushliteral(L, "__destructor");
lua_rawget(L, -2);
variant->value.object.destructor = (void (*)(void*)) lua_tocfunction(L, -1);
TypeInfo* info = lua_touserdata(L, -1);
variant->value.object.type = info->name;
variant->value.object.destructor = info->destructor;
lua_pop(L, 1);
variant->value.object.pointer = proxy->object;

View File

@ -66,7 +66,7 @@ static int l_lovrCurveGetPointCount(lua_State* L) {
static int l_lovrCurveGetPoint(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
size_t index = luaL_checkinteger(L, 2) - 1;
lovrAssert(index >= 0 && index < lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
lovrAssert(index < lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
float point[4];
lovrCurveGetPoint(curve, index, point);
lua_pushnumber(L, point[0]);
@ -78,7 +78,7 @@ static int l_lovrCurveGetPoint(lua_State* L) {
static int l_lovrCurveSetPoint(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
size_t index = luaL_checkinteger(L, 2) - 1;
lovrAssert(index >= 0 && index < lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
lovrAssert(index < lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
float point[4];
luax_readvec3(L, 3, point, NULL);
lovrCurveSetPoint(curve, index, point);
@ -89,8 +89,8 @@ static int l_lovrCurveAddPoint(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
float point[4];
int i = luax_readvec3(L, 2, point, NULL);
size_t index = lua_isnoneornil(L, i) ? lovrCurveGetPointCount(curve) : luaL_checkinteger(L, i) - 1;
lovrAssert(index >= 0 && index <= lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
size_t index = lua_isnoneornil(L, i) ? lovrCurveGetPointCount(curve) : (size_t) luaL_checkinteger(L, i) - 1;
lovrAssert(index <= lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
lovrCurveAddPoint(curve, point, index);
return 0;
}
@ -98,7 +98,7 @@ static int l_lovrCurveAddPoint(lua_State* L) {
static int l_lovrCurveRemovePoint(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
size_t index = luaL_checkinteger(L, 2) - 1;
lovrAssert(index >= 0 && index < lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
lovrAssert(index < lovrCurveGetPointCount(curve), "Invalid Curve point index: %d", index + 1);
lovrCurveRemovePoint(curve, index);
return 0;
}

View File

@ -133,6 +133,7 @@ typedef enum {
AUDIO_CAPTURE_PERMISSION
} Permission;
typedef void (*os_proc)(void);
typedef void (*quitCallback)(void);
typedef void (*windowFocusCallback)(bool focused);
typedef void (*windowResizeCallback)(int width, int height);
@ -160,7 +161,7 @@ void lovrPlatformGetWindowSize(int* width, int* height);
void lovrPlatformGetFramebufferSize(int* width, int* height);
void lovrPlatformSetSwapInterval(int interval);
void lovrPlatformSwapBuffers(void);
void* lovrPlatformGetProcAddress(const char* function);
os_proc lovrPlatformGetProcAddress(const char* function);
void lovrPlatformOnQuitRequest(quitCallback callback);
void lovrPlatformOnWindowFocus(windowFocusCallback callback);
void lovrPlatformOnWindowResize(windowResizeCallback callback);

View File

@ -7,10 +7,7 @@
#include <EGL/eglext.h>
// This is probably bad, but makes things easier to build
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-pedantic"
#include <android_native_app_glue.c>
#pragma clang diagnostic pop
static struct {
struct android_app* app;

View File

@ -305,8 +305,8 @@ void lovrPlatformSwapBuffers() {
glfwSwapBuffers(glfwState.window);
}
void* lovrPlatformGetProcAddress(const char* function) {
return (void*) glfwGetProcAddress(function);
os_proc lovrPlatformGetProcAddress(const char* function) {
return (os_proc) glfwGetProcAddress(function);
}
void lovrPlatformOnQuitRequest(quitCallback callback) {

View File

@ -44,7 +44,7 @@ void lovrLog(int level, const char* tag, const char* format, ...) {
// Refcounting
#if ATOMIC_INT_LOCK_FREE != 2
#error "Lock-free integer atomics are not supported on this platform, but are required for refcounting
#error "Lock-free integer atomics are not supported on this platform, but are required for refcounting"
#endif
void lovrRetain(void* object) {

View File

@ -73,12 +73,12 @@ void* zip_load(zip_state* zip, size_t offset, bool* compressed) {
return NULL;
}
uint16_t compression;
*compressed = compression = readu16(p + 8);
uint16_t compression = readu16(p + 8);
if (compression != 0 && compression != 8) {
return false;
}
*compressed = (compression == 8);
uint32_t skip = readu16(p + 26) + readu16(p + 28);
return p + 30 + skip;
}

View File

@ -10,7 +10,4 @@
#ifdef ANDROID
#define MA_NO_RUNTIME_LINKING
#endif
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#include "miniaudio.h"
#pragma clang diagnostic pop

View File

@ -4,8 +4,4 @@
#define STBI_ONLY_PNG
#define STBI_ONLY_HDR
#define STBI_ASSERT(x)
#define STBI_FAILURE_USERMSG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-compare"
#include "stb_image.h"
#pragma clang diagnostic pop

View File

@ -4120,7 +4120,7 @@ static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z)
if (s >= 16) return -1; // invalid code!
// code size is s, so:
b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s];
if (b >= sizeof (z->size)) return -1; // some data was corrupt somewhere!
if (b >= (int) sizeof (z->size)) return -1; // some data was corrupt somewhere!
if (z->size[b] != s) return -1; // was originally an assert, but report failure instead.
a->code_buffer >>= s;
a->num_bits -= s;

View File

@ -528,7 +528,7 @@ Image* lovrImageCreateFromBlob(Blob* blob, bool flip) {
}
if (!image->blob->data) {
lovrThrow("Could not load image from '%s': %s", blob->name, stbi_failure_reason());
lovrThrow("Could not load image from '%s'", blob->name);
lovrRelease(image->blob, lovrBlobDestroy);
free(image);
return NULL;

View File

@ -39,7 +39,7 @@ static void parseMtl(char* path, char* base, ModelDataIO* io, arr_image_t* image
if (*data == '#') goto next;
char line[1024];
size_t length = newline ? newline - data : size;
size_t length = newline ? (size_t) (newline - data) : size;
while (length > 0 && (data[length - 1] == '\r' || data[length - 1] == '\t' || data[length - 1] == ' ')) length--;
lovrAssert(length < sizeof(line), "OBJ MTL line length is too long (max is %d)", sizeof(line) - 1);
memcpy(line, data, length);
@ -135,7 +135,7 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source, ModelDataIO* io)
if (*data == '#') goto next;
char line[1024];
size_t length = newline ? newline - data : size;
size_t length = newline ? (size_t) (newline - data) : size;
while (length > 0 && (data[length - 1] == '\r' || data[length - 1] == '\t' || data[length - 1] == ' ')) length--;
lovrAssert(length < sizeof(line), "OBJ line length is too long (max is %d)", sizeof(line) - 1);
memcpy(line, data, length);
@ -218,7 +218,7 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source, ModelDataIO* io)
parseMtl(path, base, io, &images, &materials, &materialMap);
} else if (STARTS_WITH(line, "usemtl ")) {
uint64_t index = map_get(&materialMap, hash64(line + 7, length - 7));
int material = index == MAP_NIL ? -1 : index;
uint32_t material = index == MAP_NIL ? ~0u : index;
objGroup* group = &groups.data[groups.length - 1];
if (group->count > 0) {
objGroup next = { .material = material, .start = group->start + group->count };

View File

@ -168,8 +168,8 @@ Sound* lovrSoundCreateFromFile(struct Blob* blob, bool decode) {
char guid[16];
} wavHeader;
char guidi16[16] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 };
char guidf32[16] = { 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 };
uint8_t guidi16[16] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 };
uint8_t guidf32[16] = { 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 };
wavHeader* wav = blob->data;
lovrAssert(wav->size == blob->size - 8, "Invalid WAV");

View File

@ -213,7 +213,7 @@ typedef struct {
uint32_t instances;
} DrawCommand;
void lovrGpuInit(void* (*getProcAddress)(const char*), bool debug);
void lovrGpuInit(void (*getProcAddress(const char*))(void), bool debug);
void lovrGpuDestroy(void);
void lovrGpuClear(struct Canvas* canvas, Color* color, float* depth, int* stencil);
void lovrGpuCompute(struct Shader* shader, int x, int y, int z);

View File

@ -274,7 +274,7 @@ void lovrModelAnimate(Model* model, uint32_t animationIndex, float time, float a
float* (*lerp)(float* a, float* b, float t) = rotate ? quat_slerp : vec3_lerp;
if (keyframe == 0 || keyframe >= channel->keyframeCount) {
size_t index = CLAMP(keyframe, 0, channel->keyframeCount - 1);
size_t index = MIN(keyframe, channel->keyframeCount - 1);
// For cubic interpolation, each keyframe has 3 parts, and the actual data is in the middle (*3, +1)
if (channel->smoothing == SMOOTH_CUBIC) {

View File

@ -1245,7 +1245,7 @@ static void GLAPIENTRY onMessage(GLenum source, GLenum type, GLuint id, GLenum s
}
#endif
void lovrGpuInit(void* (*getProcAddress)(const char*), bool debug) {
void lovrGpuInit(void (*getProcAddress(const char*))(void), bool debug) {
#ifdef LOVR_GL
gladLoadGLLoader((GLADloadproc) getProcAddress);
#elif defined(LOVR_GLES)

View File

@ -30,10 +30,7 @@
#include <stdlib.h>
#include <stdint.h>
#undef EXTERN_C
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtypedef-redefinition"
#include <openvr_capi.h>
#pragma clang diagnostic pop
// From openvr_capi.h
extern intptr_t VR_InitInternal(EVRInitError *peError, EVRApplicationType eType);

View File

@ -12,14 +12,9 @@
#include <string.h>
#include <EGL/egl.h>
#include <android_native_app_glue.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc11-extensions"
#pragma clang diagnostic ignored "-Wgnu-empty-initializer"
#pragma clang diagnostic ignored "-Wpedantic"
#include <VrApi.h>
#include <VrApi_Helpers.h>
#include <VrApi_Input.h>
#pragma clang diagnostic pop
#define GL_SRGB8_ALPHA8 0x8C43
#define VRAPI_DEVICE_TYPE_OCULUSGO 64