From e30f1a11dc0864b5c9ff3e645522bf19e6e4d2aa Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 28 May 2015 17:06:41 +0900 Subject: [PATCH] more strict unused variable check --- extlib/benz/dict.c | 12 +++------ extlib/benz/error.c | 6 ++--- extlib/benz/gc.c | 2 -- extlib/benz/include/picrin/util.h | 9 +++++-- extlib/benz/read.c | 42 +++++++------------------------ extlib/benz/string.c | 4 +-- extlib/benz/write.c | 2 -- 7 files changed, 22 insertions(+), 55 deletions(-) diff --git a/extlib/benz/dict.c b/extlib/benz/dict.c index 0ad6f769..3904dbd0 100644 --- a/extlib/benz/dict.c +++ b/extlib/benz/dict.c @@ -33,26 +33,20 @@ pic_dict_ref(pic_state *pic, struct pic_dict *dict, pic_sym *key) } void -pic_dict_set(pic_state *pic, struct pic_dict *dict, pic_sym *key, pic_value val) +pic_dict_set(pic_state PIC_UNUSED(*pic), struct pic_dict *dict, pic_sym *key, pic_value val) { - PIC_UNUSED(pic); - xh_put_ptr(&dict->hash, key, &val); } size_t -pic_dict_size(pic_state *pic, struct pic_dict *dict) +pic_dict_size(pic_state PIC_UNUSED(*pic), struct pic_dict *dict) { - PIC_UNUSED(pic); - return dict->hash.count; } bool -pic_dict_has(pic_state *pic, struct pic_dict *dict, pic_sym *key) +pic_dict_has(pic_state PIC_UNUSED(*pic), struct pic_dict *dict, pic_sym *key) { - PIC_UNUSED(pic); - return xh_get_ptr(&dict->hash, key) != NULL; } diff --git a/extlib/benz/error.c b/extlib/benz/error.c index 6d2abc37..2c70e188 100644 --- a/extlib/benz/error.c +++ b/extlib/benz/error.c @@ -12,14 +12,12 @@ #include "picrin/port.h" void -pic_panic(pic_state *pic, const char *msg) +pic_panic(pic_state PIC_UNUSED(*pic), const char *msg) { - PIC_UNUSED(pic); - #if DEBUG fprintf(stderr, "abort: %s\n", msg); #else - PIC_UNUSED(msg); + (void)msg; #endif PIC_ABORT(pic); diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index 0fea8df1..4220c758 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -169,8 +169,6 @@ pic_calloc(pic_state *pic, size_t count, size_t size) void pic_free(pic_state *pic, void *ptr) { - PIC_UNUSED(pic); - pic->allocf(ptr, 0); } diff --git a/extlib/benz/include/picrin/util.h b/extlib/benz/include/picrin/util.h index a04c2813..5c831bad 100644 --- a/extlib/benz/include/picrin/util.h +++ b/extlib/benz/include/picrin/util.h @@ -35,13 +35,18 @@ extern "C" { #if __STDC_VERSION__ >= 199901L # define PIC_INLINE static inline #elif __GNUC__ || __clang__ -# define PIC_INLINE static __attribute__((unused)) +# define PIC_INLINE static __inline__ #else # define PIC_INLINE static #endif #define PIC_FALLTHROUGH ((void)0) -#define PIC_UNUSED(v) ((void)(v)) + +#if __GNUC__ || __clang__ +# define PIC_UNUSED(v) __attribute__((unused)) v +#else +# define PIC_UNUSED(v) v +#endif #define PIC_GENSYM2_(x,y) PIC_G##x##_##y##_ #define PIC_GENSYM1_(x,y) PIC_GENSYM2_(x,y) diff --git a/extlib/benz/read.c b/extlib/benz/read.c index f0d0299f..d2300579 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -91,10 +91,8 @@ case_fold(pic_state *pic, int c) } static pic_value -read_comment(pic_state *pic, struct pic_port *port, int c) +read_comment(pic_state PIC_UNUSED(*pic), struct pic_port *port, int c) { - PIC_UNUSED(pic); - do { c = next(port); } while (! (c == EOF || c == '\n')); @@ -103,14 +101,11 @@ read_comment(pic_state *pic, struct pic_port *port, int c) } static pic_value -read_block_comment(pic_state *pic, struct pic_port *port, int c) +read_block_comment(pic_state PIC_UNUSED(*pic), struct pic_port *port, int PIC_UNUSED(c)) { int x, y; int i = 1; - PIC_UNUSED(pic); - PIC_UNUSED(c); - y = next(port); while (y != EOF && i > 0) { @@ -128,10 +123,8 @@ read_block_comment(pic_state *pic, struct pic_port *port, int c) } static pic_value -read_datum_comment(pic_state *pic, struct pic_port *port, int c) +read_datum_comment(pic_state *pic, struct pic_port *port, int PIC_UNUSED(c)) { - PIC_UNUSED(c); - read(pic, port, next(port)); return pic_undef_value(); @@ -159,40 +152,32 @@ read_directive(pic_state *pic, struct pic_port *port, int c) } static pic_value -read_eval(pic_state *pic, struct pic_port *port, int c) +read_eval(pic_state *pic, struct pic_port *port, int PIC_UNUSED(c)) { pic_value form; - PIC_UNUSED(c); - form = read(pic, port, next(port)); return pic_eval(pic, form, pic->lib); } static pic_value -read_quote(pic_state *pic, struct pic_port *port, int c) +read_quote(pic_state *pic, struct pic_port *port, int PIC_UNUSED(c)) { - PIC_UNUSED(c); - return pic_list2(pic, pic_obj_value(pic->sQUOTE), read(pic, port, next(port))); } static pic_value -read_quasiquote(pic_state *pic, struct pic_port *port, int c) +read_quasiquote(pic_state *pic, struct pic_port *port, int PIC_UNUSED(c)) { - PIC_UNUSED(c); - return pic_list2(pic, pic_obj_value(pic->sQUASIQUOTE), read(pic, port, next(port))); } static pic_value -read_unquote(pic_state *pic, struct pic_port *port, int c) +read_unquote(pic_state *pic, struct pic_port *port, int PIC_UNUSED(c)) { pic_sym *tag = pic->sUNQUOTE; - PIC_UNUSED(c); - if (peek(port) == '@') { tag = pic->sUNQUOTE_SPLICING; next(port); @@ -396,8 +381,6 @@ read_plus(pic_state *pic, struct pic_port *port, int c) static pic_value read_true(pic_state *pic, struct pic_port *port, int c) { - PIC_UNUSED(pic); - if ((c = peek(port)) == 'r') { if (! expect(port, "rue")) { read_error(pic, "unexpected character while reading #true"); @@ -412,8 +395,6 @@ read_true(pic_state *pic, struct pic_port *port, int c) static pic_value read_false(pic_state *pic, struct pic_port *port, int c) { - PIC_UNUSED(pic); - if ((c = peek(port)) == 'a') { if (! expect(port, "alse")) { read_error(pic, "unexpected character while reading #false"); @@ -690,12 +671,10 @@ read_label_set(pic_state *pic, struct pic_port *port, int i) } static pic_value -read_label_ref(pic_state *pic, struct pic_port *port, int i) +read_label_ref(pic_state *pic, struct pic_port PIC_UNUSED(*port), int i) { xh_entry *e; - PIC_UNUSED(port); - e = xh_get_int(&pic->reader->labels, i); if (! e) { read_error(pic, "label of given index not defined"); @@ -723,11 +702,8 @@ read_label(pic_state *pic, struct pic_port *port, int c) } static pic_value -read_unmatch(pic_state *pic, struct pic_port *port, int c) +read_unmatch(pic_state *pic, struct pic_port PIC_UNUSED(*port), int PIC_UNUSED(c)) { - PIC_UNUSED(port); - PIC_UNUSED(c); - read_error(pic, "unmatched parenthesis"); } diff --git a/extlib/benz/string.c b/extlib/benz/string.c index c9b75bd0..e2f356b4 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -37,9 +37,7 @@ struct pic_rope { } while (0) void -pic_rope_incref(pic_state *pic, struct pic_rope *x) { - PIC_UNUSED(pic); - +pic_rope_incref(pic_state PIC_UNUSED(*pic), struct pic_rope *x) { x->refcnt++; } diff --git a/extlib/benz/write.c b/extlib/benz/write.c index e01966de..c9e36553 100644 --- a/extlib/benz/write.c +++ b/extlib/benz/write.c @@ -163,8 +163,6 @@ write_str(pic_state *pic, struct pic_string *str, xFILE *file) size_t i; const char *cstr = pic_str_cstr(pic, str); - PIC_UNUSED(pic); - for (i = 0; i < pic_str_len(str); ++i) { if (cstr[i] == '"' || cstr[i] == '\\') { xfputc('\\', file);