Skip to content

Commit 25fc2e5

Browse files
authored
Cleanups warnings (#2292)
* Rename `premake_test_file` to `premake_locate_file`. * Cleanup Windows platform detection. * Fix warning for Cosmopolitan in `premake_locate_executable`. * Fix warning in `os_getpass`. * Update copyright year. * Preprocessor defines and whitespace cleanup. * Fix compile warning in `lundunmp.c`. * Fix compile warning in `mime.c`. * Fix compile warning in `curl_utils.c`. * Change `do_path_has_deferred_join` to static.
1 parent 43fa514 commit 25fc2e5

File tree

8 files changed

+32
-34
lines changed

8 files changed

+32
-34
lines changed

binmodules/luasocket/src/mime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ static size_t dot(int c, size_t state, luaL_Buffer *buffer)
689689
case '.':
690690
if (state == 2)
691691
luaL_addchar(buffer, '.');
692+
/* Falls through. */
692693
default:
693694
return 0;
694695
}

contrib/lua/src/lundump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static void fchecksize (LoadState *S, size_t size, const char *tname) {
234234
#define checksize(S,t) fchecksize(S,sizeof(t),#t)
235235

236236
static void checkHeader (LoadState *S) {
237-
checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */
237+
checkliteral(S, &LUA_SIGNATURE[1], "not a"); /* 1st char already checked */
238238
if (LoadByte(S) != LUAC_VERSION)
239239
error(S, "version mismatch in");
240240
if (LoadByte(S) != LUAC_FORMAT)

src/host/curl_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ int curlProgressCallback(curl_state* state, double dltotal, double dlnow, double
3636
}
3737

3838

39-
size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, curl_state* state)
39+
size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, void* state)
4040
{
4141
size_t length = size * nmemb;
42-
premake_buffer_puts(&state->S, ptr, length);
42+
premake_buffer_puts(&((curl_state*)state)->S, ptr, length);
4343
return length;
4444
}
4545

src/host/curl_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int curlProgressCallback(curl_state* state, curl_off_t dltotal, curl_off_t dlnow
3030
#else
3131
int curlProgressCallback(curl_state* state, double dltotal, double dlnow, double ultotal, double ulnow);
3232
#endif
33-
size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, curl_state* state);
33+
size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, void* state);
3434

3535
CURL* curlRequest(lua_State* L, curl_state* state, int optionsIndex, int progressFnIndex, int headersIndex);
3636
void curlCleanup(CURL* curl, curl_state* state);

src/host/os_getpass.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int os_getpass(lua_State* L)
3232
lua_pushstring(L, buffer);
3333
return 1;
3434
#elif PLATFORM_COSMO
35+
(void)prompt;
3536
luaL_error(L, "Not supported by this platform");
3637
return 0;
3738
#elif PLATFORM_POSIX

src/host/path_join.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int path_deferred_join(lua_State* L)
138138
}
139139

140140

141-
int do_path_has_deferred_join(const char* path)
141+
static int do_path_has_deferred_join(const char* path)
142142
{
143143
return (strchr(path, DEFERRED_JOIN_DELIMITER) != NULL);
144144
}

src/host/premake.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ int premake_locate_executable(lua_State* L, const char* argv0)
404404
}
405405
#endif
406406

407+
(void)buffer;
408+
407409
/* As a fallback, search the PATH with argv[0] */
408410
if (!path)
409411
{
@@ -451,9 +453,9 @@ int premake_locate_executable(lua_State* L, const char* argv0)
451453
* specified file. If found, returns the discovered path to the script on
452454
* the top of the Lua stack.
453455
*/
454-
int premake_test_file(lua_State* L, const char* filename, int searchMask)
456+
int premake_locate_file(lua_State* L, const char* filename, int searchMask)
455457
{
456-
if (searchMask & TEST_LOCAL) {
458+
if (searchMask & SEARCH_LOCAL) {
457459
if (do_isfile(L, filename)) {
458460
lua_pushcfunction(L, path_getabsolute);
459461
lua_pushstring(L, filename);
@@ -462,17 +464,17 @@ int premake_test_file(lua_State* L, const char* filename, int searchMask)
462464
}
463465
}
464466

465-
if (scripts_path && (searchMask & TEST_SCRIPTS)) {
467+
if (scripts_path && (searchMask & SEARCH_SCRIPTS)) {
466468
if (do_locate(L, filename, scripts_path)) return OKAY;
467469
}
468470

469-
if (searchMask & TEST_PATH) {
471+
if (searchMask & SEARCH_PATH) {
470472
const char* path = getenv("PREMAKE_PATH");
471473
if (path && do_locate(L, filename, path)) return OKAY;
472474
}
473475

474476
#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
475-
if ((searchMask & TEST_EMBEDDED) != 0) {
477+
if ((searchMask & SEARCH_EMBEDDED) != 0) {
476478
/* Try to locate a record matching the filename */
477479
if (premake_find_embedded_script(filename) != NULL) {
478480
lua_pushstring(L, "$/");
@@ -614,18 +616,18 @@ static int run_premake_main(lua_State* L, const char* script)
614616
* argument allowed as an override. Debug builds will look at the
615617
* local file system first, then fall back to embedded. */
616618
#if defined(NDEBUG)
617-
int z = premake_test_file(L, script,
618-
TEST_SCRIPTS | TEST_EMBEDDED);
619+
int z = premake_locate_file(L, script,
620+
SEARCH_SCRIPTS | SEARCH_EMBEDDED);
619621
#else
620-
int z = premake_test_file(L, script,
621-
TEST_LOCAL | TEST_SCRIPTS | TEST_PATH | TEST_EMBEDDED);
622+
int z = premake_locate_file(L, script,
623+
SEARCH_LOCAL | SEARCH_SCRIPTS | SEARCH_PATH | SEARCH_EMBEDDED);
622624
#endif
623625

624626
/* If no embedded script can be found, release builds will then
625627
* try to fall back to the local file system, just in case */
626628
#if defined(NDEBUG)
627629
if (z != OKAY) {
628-
z = premake_test_file(L, script, TEST_LOCAL | TEST_PATH);
630+
z = premake_locate_file(L, script, SEARCH_LOCAL | SEARCH_PATH);
629631
}
630632
#endif
631633

src/host/premake.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
#include "lauxlib.h"
1010
#include "lualib.h"
1111

12+
#include <stdint.h>
1213
#include <stdlib.h>
1314

1415
#define PREMAKE_VERSION "5.0.0-dev"
1516
#define PREMAKE_COPYRIGHT "Copyright (C) 2002-2021 Jess Perkins and the Premake Project"
1617
#define PREMAKE_PROJECT_URL "https://github.com/premake/premake-core/wiki"
1718

18-
/* Identify the current platform I'm not sure how to reliably detect
19-
* Windows but since it is the most common I use it as the default */
2019
#if defined(__linux__)
2120
#define PLATFORM_LINUX (1)
2221
#define PLATFORM_OS "linux"
@@ -41,9 +40,11 @@
4140
#elif defined (__COSMOPOLITAN__)
4241
#define PLATFORM_COSMO (1)
4342
#define PLATFORM_OS "cosmopolitan"
44-
#else
43+
#elif defined(_WIN32) || defined(_WIN64)
4544
#define PLATFORM_WINDOWS (1)
4645
#define PLATFORM_OS "windows"
46+
#else
47+
#error Unknown platform detected
4748
#endif
4849

4950
#define PLATFORM_POSIX (PLATFORM_LINUX || PLATFORM_BSD || PLATFORM_MACOSX || PLATFORM_SOLARIS || PLATFORM_HAIKU || PLATFORM_COSMO)
@@ -68,7 +69,6 @@
6869
#else
6970
#include <unistd.h>
7071
#endif
71-
#include <stdint.h>
7272

7373
/* not all platforms define this */
7474
#ifndef FALSE
@@ -83,22 +83,21 @@
8383
#define PATH_MAX (4096)
8484
#endif
8585

86-
8786
/* A success return code */
8887
#define OKAY (0)
8988

90-
9189
/* Bitmasks for the different script file search locations */
92-
#define TEST_LOCAL (0x01)
93-
#define TEST_SCRIPTS (0x02)
94-
#define TEST_PATH (0x04)
95-
#define TEST_EMBEDDED (0x08)
96-
90+
enum FileSearchMask
91+
{
92+
SEARCH_LOCAL = 0x01,
93+
SEARCH_SCRIPTS = 0x02,
94+
SEARCH_PATH = 0x04,
95+
SEARCH_EMBEDDED = 0x08
96+
};
9797

9898
/* If a /scripts argument is present, its value */
9999
extern const char* scripts_path;
100100

101-
102101
/* Bootstrapping helper functions */
103102
int do_chdir(lua_State* L, const char* path);
104103
uint32_t do_hash(const char* str, int seed);
@@ -189,12 +188,6 @@ int http_download(lua_State* L);
189188
int zip_extract(lua_State* L);
190189
#endif
191190

192-
#ifdef _MSC_VER
193-
#ifndef snprintf
194-
#define snprintf _snprintf
195-
#endif
196-
#endif
197-
198191
/* Engine interface */
199192

200193
typedef struct
@@ -210,9 +203,10 @@ extern void registerModules(lua_State* L);
210203
int premake_init(lua_State* L);
211204
int premake_pcall(lua_State* L, int nargs, int nresults);
212205
int premake_execute(lua_State* L, int argc, const char** argv, const char* script);
206+
213207
int premake_load_embedded_script(lua_State* L, const char* filename);
214208
const buildin_mapping* premake_find_embedded_script(const char* filename);
215209

216210
int premake_locate_executable(lua_State* L, const char* argv0);
217-
int premake_test_file(lua_State* L, const char* filename, int searchMask);
211+
int premake_locate_file(lua_State* L, const char* filename, int searchMask);
218212
void premake_handle_lua_error(lua_State* L);

0 commit comments

Comments
 (0)