Cleanup (#826)
* Update meson.build - add logic to loop over more lua names (in the future more names might be discovered) - disable warnings and errors on dependencies * adding missing includes and checks, correct data types, pointer mess […] - various functions from string.h were used but never defined - logic was done across multiple different data types with different signedness, got all of them up to snuff - give 0 sized array size of 1 (array of size 0 is illegal, but rewriting the code is out of the scope of this commit) - add preprocessor that marks possibly unused argument as such (does not mean they will get optimized out or anything) - correctly initialize structs with all data needed All these were found by generating the project using `meson -Dwarning_level=3 -Dwerror=true` * remove undefined behavior, correct data types * Comment manual bit manipulation to be investigated * check for more edge cases, replace multiple cleanups with goto * remove system specific includes
This commit is contained in:
+12
-8
@@ -45,7 +45,7 @@ struct HitTestInfo {
|
||||
};
|
||||
typedef struct HitTestInfo HitTestInfo;
|
||||
|
||||
static HitTestInfo window_hit_info[1] = {{0, 0}};
|
||||
static HitTestInfo window_hit_info[1] = {{0, 0, 0}};
|
||||
|
||||
#define RESIZE_FROM_TOP 0
|
||||
#define RESIZE_FROM_RIGHT 0
|
||||
@@ -705,13 +705,15 @@ static int f_set_window_opacity(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef void (*fptr)(void);
|
||||
|
||||
typedef struct lua_function_node {
|
||||
const char *symbol;
|
||||
void *address;
|
||||
fptr address;
|
||||
} lua_function_node;
|
||||
|
||||
#define P(FUNC) { "lua_" #FUNC, (void*)(lua_##FUNC) }
|
||||
#define U(FUNC) { "luaL_" #FUNC, (void*)(luaL_##FUNC) }
|
||||
#define P(FUNC) { "lua_" #FUNC, (fptr)(lua_##FUNC) }
|
||||
#define U(FUNC) { "luaL_" #FUNC, (fptr)(luaL_##FUNC) }
|
||||
static void* api_require(const char* symbol) {
|
||||
static lua_function_node nodes[] = {
|
||||
P(atpanic), P(checkstack),
|
||||
@@ -749,9 +751,9 @@ static void* api_require(const char* symbol) {
|
||||
#endif
|
||||
|
||||
};
|
||||
for (int i = 0; i < sizeof(nodes) / sizeof(lua_function_node); ++i) {
|
||||
for (size_t i = 0; i < sizeof(nodes) / sizeof(lua_function_node); ++i) {
|
||||
if (strcmp(nodes[i].symbol, symbol) == 0)
|
||||
return nodes[i].address;
|
||||
return *(void**)(&nodes[i].address);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -775,10 +777,12 @@ static int f_load_native_plugin(lua_State *L) {
|
||||
const char *basename = strrchr(name, '.');
|
||||
basename = !basename ? name : basename + 1;
|
||||
snprintf(entrypoint_name, sizeof(entrypoint_name), "luaopen_lite_xl_%s", basename);
|
||||
int (*ext_entrypoint) (lua_State *L, void*) = SDL_LoadFunction(library, entrypoint_name);
|
||||
int (*ext_entrypoint) (lua_State *L, void* (*)(const char*));
|
||||
*(void**)(&ext_entrypoint) = SDL_LoadFunction(library, entrypoint_name);
|
||||
if (!ext_entrypoint) {
|
||||
snprintf(entrypoint_name, sizeof(entrypoint_name), "luaopen_%s", basename);
|
||||
int (*entrypoint)(lua_State *L) = SDL_LoadFunction(library, entrypoint_name);
|
||||
int (*entrypoint)(lua_State *L);
|
||||
*(void**)(&entrypoint) = SDL_LoadFunction(library, entrypoint_name);
|
||||
if (!entrypoint)
|
||||
return luaL_error(L, "Unable to load %s: Can't find %s(lua_State *L, void *XL)", name, entrypoint_name);
|
||||
result = entrypoint(L);
|
||||
|
||||
Reference in New Issue
Block a user