From 2510c7f36a530412cd511a4d8f4bcf4acfd1e33d Mon Sep 17 00:00:00 2001 From: Max Regan Date: Tue, 22 Nov 2022 21:11:06 -0500 Subject: [PATCH] Enable more pedantic compiler flags --- SConstruct | 2 +- src/arena.c | 6 +++--- src/builtins.c | 2 +- src/lisp.h | 10 ++++++---- src/memory.c | 16 ++++++++-------- src/parse.c | 11 ++++++++++- src/special.c | 4 ++-- src/utility.c | 7 +++++-- test/test_arena.c | 7 +++---- 9 files changed, 39 insertions(+), 26 deletions(-) diff --git a/SConstruct b/SConstruct index d6cc910..2c6e8d4 100644 --- a/SConstruct +++ b/SConstruct @@ -142,7 +142,7 @@ class BuildVariant: self.env.Alias(self.variant_name, self.variant_dir) -base_ccflags = ["-Werror", "-Wall", "-Wextra", "-Wno-unused-parameter"] +base_ccflags = ["-Werror", "-Wall", "-Wextra", "-Wpedantic"] debug_ccflags = ["-ggdb", "-O0"] release_ccflags = [ "-Oz", diff --git a/src/arena.c b/src/arena.c index ed1d91b..2899aca 100644 --- a/src/arena.c +++ b/src/arena.c @@ -42,7 +42,7 @@ void ucl_arena_map(struct ucl_arena *arena, void (*map_function)(struct ucl_aren while (map) { int bit_index = __builtin_ffs(map) - 1; int index = bit_index + INT_BITS * i; - void *obj = arena->objects + (index * arena->object_size); + void *obj = (char *) arena->objects + (index * arena->object_size); map_function(arena, obj); map &= ~(1 << bit_index); } @@ -68,7 +68,7 @@ void *ucl_arena_get(struct ucl_arena *arena) { } arena->used_map[i] |= 1 << bit_index; total_arena_gets++; - return arena->objects + (index * arena->object_size); + return (char *) arena->objects + (index * arena->object_size); } return NULL; @@ -82,7 +82,7 @@ void ucl_arena_put(struct ucl_arena *arena, void *object) { return; } - ptrdiff_t offset = object - arena->objects; + ptrdiff_t offset = (char *) object - (char *) arena->objects; unsigned int index = offset / arena->object_size; unsigned int int_index = index / INT_BITS; unsigned int bit_index = index % INT_BITS; diff --git a/src/builtins.c b/src/builtins.c index b31b447..64ca283 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -177,7 +177,7 @@ LISP_FUNC_1(ucl_builtin_printl, state, scope, arg0) { return ucl_nil_create(state); } -struct ucl_object *ucl_builtin_list(struct ucl *state, struct ucl_scope *scope, struct ucl_object *args) { +struct ucl_object *ucl_builtin_list(struct ucl *state, UNUSED struct ucl_scope *scope, struct ucl_object *args) { struct ucl_object *head = ucl_nil_create(state); FOREACH_LIST(args, iter, item) { ucl_list_append(state, head, item); diff --git a/src/lisp.h b/src/lisp.h index a977338..1bcacf3 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3,6 +3,8 @@ #include "common.h" +#define UNUSED __attribute__((unused)) + #define LISP_FUNC_0(func_name, ucl_name, scope_name) \ static struct ucl_object *func_name##_impl(struct ucl* ucl, struct ucl_scope *scope); \ struct ucl_object *func_name(struct ucl* ucl, struct ucl_scope *scope, struct ucl_object *args) { \ @@ -11,7 +13,7 @@ } \ return func_name##_impl(ucl, scope); \ } \ - static struct ucl_object *func_name##_impl(struct ucl *ucl_name, struct ucl_scope *scope) + static struct ucl_object *func_name##_impl(UNUSED struct ucl *ucl_name, UNUSED struct ucl_scope *scope) #define LISP_FUNC_1(func_name, ucl_name, scope_name, arg0_name) \ static struct ucl_object *func_name##_impl(struct ucl* ucl, struct ucl_scope *scope, struct ucl_object *arg0_name); \ @@ -26,7 +28,7 @@ struct ucl_object *arg0 = ucl_car(ucl, args); \ return func_name##_impl(ucl, scope_name, arg0); \ } \ - static struct ucl_object *func_name##_impl(struct ucl* ucl_name, struct ucl_scope *scope, struct ucl_object *arg0_name) + static struct ucl_object *func_name##_impl(UNUSED struct ucl* ucl_name, UNUSED struct ucl_scope *scope_name, struct ucl_object *arg0_name) // TODO: Unroll the args more efficiently, this is O(n^2) #define LISP_FUNC_2(func_name, ucl_name, scope_name, arg0_name, arg1_name) \ @@ -43,7 +45,7 @@ struct ucl_object *arg1 = ucl_list_nth(ucl, args, 1); \ return func_name##_impl(ucl, scope, arg0, arg1); \ } \ - static struct ucl_object *func_name##_impl(struct ucl *ucl_name, struct ucl_scope *scope, struct ucl_object *arg0_name, struct ucl_object *arg1_name) + static struct ucl_object *func_name##_impl(UNUSED struct ucl *ucl_name, UNUSED struct ucl_scope *scope, struct ucl_object *arg0_name, struct ucl_object *arg1_name) // TODO: Unroll the args more efficiently, this is O(n^2) #define LISP_FUNC_3(func_name, ucl_name, scope_name, arg0_name, arg1_name, arg2_name) \ @@ -61,7 +63,7 @@ struct ucl_object *arg2 = ucl_list_nth(ucl, args, 2); \ return func_name##_impl(ucl, scope, arg0, arg1, arg2); \ } \ - static struct ucl_object *func_name##_impl(struct ucl* ucl_name, struct ucl_scope *scope_name, struct ucl_object *arg0_name, struct ucl_object *arg1_name, struct ucl_object *arg2_name) + static struct ucl_object *func_name##_impl(UNUSED struct ucl* ucl_name, UNUSED struct ucl_scope *scope_name, struct ucl_object *arg0_name, struct ucl_object *arg1_name, struct ucl_object *arg2_name) #endif diff --git a/src/memory.c b/src/memory.c index 03db337..2cc6ca9 100644 --- a/src/memory.c +++ b/src/memory.c @@ -19,11 +19,11 @@ #define UCL_OBJECT_ARENA_SIZE (1 << 14) #endif -static struct ucl_object *ucl_object_alloc(); +static struct ucl_object *ucl_object_alloc(struct ucl *ucl); struct ucl_object *ucl_cell_create(struct ucl *ucl, struct ucl_object *car, struct ucl_object *cdr) { - struct ucl_object* obj = ucl_object_alloc(); + struct ucl_object* obj = ucl_object_alloc(ucl); obj->type = UCL_TYPE_CELL; obj->cell.car = car; obj->cell.cdr = cdr; @@ -32,7 +32,7 @@ struct ucl_object *ucl_cell_create(struct ucl *ucl, struct ucl_object *car, stru struct ucl_object *ucl_int_create(struct ucl *ucl, int integer) { - struct ucl_object* obj = ucl_object_alloc(); + struct ucl_object* obj = ucl_object_alloc(ucl); obj->type = UCL_TYPE_INT; obj->integer = integer; return obj; @@ -40,7 +40,7 @@ struct ucl_object *ucl_int_create(struct ucl *ucl, int integer) struct ucl_object *ucl_symbol_create(struct ucl* ucl, const char *symbol) { - struct ucl_object* obj = ucl_object_alloc(); + struct ucl_object* obj = ucl_object_alloc(ucl); obj->type = UCL_TYPE_SYMBOL; obj->symbol = strdup(symbol); return obj; @@ -48,7 +48,7 @@ struct ucl_object *ucl_symbol_create(struct ucl* ucl, const char *symbol) struct ucl_object *ucl_string_create(struct ucl* ucl, const char *string) { - struct ucl_object* obj = ucl_object_alloc(); + struct ucl_object* obj = ucl_object_alloc(ucl); obj->type = UCL_TYPE_STRING; obj->string = strdup(string); return obj; @@ -56,7 +56,7 @@ struct ucl_object *ucl_string_create(struct ucl* ucl, const char *string) struct ucl_object *ucl_error_create(struct ucl* ucl, const char *error) { - struct ucl_object* obj = ucl_object_alloc(); + struct ucl_object* obj = ucl_object_alloc(ucl); obj->type = UCL_TYPE_ERROR; obj->error = strdup(error); return obj; @@ -65,7 +65,7 @@ struct ucl_object *ucl_error_create(struct ucl* ucl, const char *error) struct ucl_object *ucl_builtin_create(struct ucl* ucl, ucl_lisp builtin) { - struct ucl_object* obj = ucl_object_alloc(); + struct ucl_object* obj = ucl_object_alloc(ucl); obj->type = UCL_TYPE_BUILTIN; obj->builtin = builtin; return obj; @@ -73,7 +73,7 @@ struct ucl_object *ucl_builtin_create(struct ucl* ucl, ucl_lisp builtin) struct ucl_object *ucl_special_create(struct ucl* ucl, ucl_lisp special) { - struct ucl_object* obj = ucl_object_alloc(); + struct ucl_object* obj = ucl_object_alloc(ucl); obj->type = UCL_TYPE_SPECIAL; obj->special = special; return obj; diff --git a/src/parse.c b/src/parse.c index 911e1c8..738f725 100644 --- a/src/parse.c +++ b/src/parse.c @@ -73,7 +73,16 @@ struct ucl_object *ucl_token_next(struct ucl* state, const char **curr_src) { return ucl_string_create(state, str); case '-': case '+': - case '0'...'9': { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': { char *end = NULL; errno = 0; long value = strtol(*curr_src, &end, 0); diff --git a/src/special.c b/src/special.c index 6df192b..8a45560 100644 --- a/src/special.c +++ b/src/special.c @@ -73,7 +73,7 @@ struct ucl_object *ucl_special_defun(struct ucl *state, struct ucl_scope *scope, } -struct ucl_object *ucl_special_lambda(struct ucl *state, struct ucl_scope *scope, struct ucl_object *args) { +struct ucl_object *ucl_special_lambda(struct ucl *state, UNUSED struct ucl_scope *scope, struct ucl_object *args) { // TODO: Check arguments struct ucl_object *fun_args = ucl_list_nth(state, args, 0); if (fun_args->type != UCL_TYPE_CELL) { @@ -167,7 +167,7 @@ struct ucl_object *ucl_special_progn(struct ucl *state, struct ucl_scope *scope, return ucl_progn(state, scope, args); } -struct ucl_object *ucl_special_quote(struct ucl *state, struct ucl_scope *scope, struct ucl_object *args) { +struct ucl_object *ucl_special_quote(struct ucl *state, UNUSED struct ucl_scope *scope, struct ucl_object *args) { return ucl_car(state, args); } diff --git a/src/utility.c b/src/utility.c index 1e4b332..8e800bd 100644 --- a/src/utility.c +++ b/src/utility.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "uclisp.h" #include "lisp.h" @@ -142,10 +143,12 @@ void ucl_print_obj(struct ucl_object *obj) { printf("(error \"%s\")", obj->error); break; case UCL_TYPE_BUILTIN: - printf("", obj->builtin); + // TODO: Hack to work around -pedantic temporarily + printf("", (void *)(uintptr_t) obj->builtin); break; case UCL_TYPE_SPECIAL: - printf("", obj->special); + // TODO: Hack to work around -pedantic temporarily + printf("", (void *)(uintptr_t) obj->special); break; case UCL_TYPE_CELL: { int first = true; diff --git a/test/test_arena.c b/test/test_arena.c index 0975363..4d993ce 100644 --- a/test/test_arena.c +++ b/test/test_arena.c @@ -30,7 +30,7 @@ static void test_arena_single(void) { } static void test_arena_get_all(void) { - struct test_5 *objects[NUM_OBJECTS] = {}; + struct test_5 *objects[NUM_OBJECTS] = { NULL }; for (int i = 0; i < NUM_OBJECTS; i++) { objects[i] = ucl_arena_get(arena); TEST_ASSERT_NOT_NULL(objects[i]); @@ -38,7 +38,7 @@ static void test_arena_get_all(void) { } static void test_arena_get_put_limit(void) { - struct test_5 *objects[NUM_OBJECTS] = {}; + struct test_5 *objects[NUM_OBJECTS] = { NULL }; for (int i = 0; i < NUM_OBJECTS; i++) { objects[i] = ucl_arena_get(arena); @@ -51,8 +51,7 @@ static void test_arena_get_put_limit(void) { } static void test_arena_get_over_limit(void) { - struct test_5 *objects[NUM_OBJECTS + 1] = {}; - + struct test_5 *objects[NUM_OBJECTS + 1] = { NULL }; for (int i = 0; i < NUM_OBJECTS + 1; i++) { objects[i] = ucl_arena_get(arena); if (i < NUM_OBJECTS) {