diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-12-29 18:59:27 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-12-29 23:42:14 -0800 |
commit | 5f67b95d218e1ef3473c39bca2f6491503aeeabe (patch) | |
tree | 095d53b02f0093911e06ab06221d0529f6f7da42 /lib.c | |
parent | 0b6c09e067981c232cef09f0d82fb9b4a9864553 (diff) | |
download | txr-5f67b95d218e1ef3473c39bca2f6491503aeeabe.tar.gz txr-5f67b95d218e1ef3473c39bca2f6491503aeeabe.tar.bz2 txr-5f67b95d218e1ef3473c39bca2f6491503aeeabe.zip |
Eliminate declaration-after-statement everywhere.
The use of -ansi doesn't by itself diagnose instances of some
constructs we don't want in the project, like mixed
declarations and statements.
* configure (diag_flags): Add -Werror=declaration-after-statement.
This is C only, so filter it out for C++.
Also add -Werror=vla.
* HACKING: Update inaccurate statements about what dialect we
are using. TXR isn't pure C90: some GCC extensions are used.
We even use long long if the configure script detects it as
working, and some C99 library features.
* buf.c (replace_buf, buf_list): Fix by reordering.
* eval.c (op_dohash, op_load_time_lit): Fix by reordering.
* ffi.c (ffi_simple_release): Fix by reordering.
(align_sw_get): Fix empty macro to expand to dummy declaration
so a semicolon after it isn't interpreted as a statement.
On platforms with alignment, remove a semicolon from the macro
so that it requires one.
(ffi_i8_put, ffi_u8_put): Fix by reordering.
* gc.c (gc_init): Fix with extra braces.
* hash.c (hash_init): Fix by reordering.
* lib.c (list_collect_revappend, sub_iter, replace_str,
replace_vec, mapcar_listout, mappend, mapdo, window_map_list,
subst): Fix by reordering.
(gensym, find, rfind, pos, rpos, in, search_common): Fix by
renaming optional argument and using declaration instead of
assignment.
* linenoise/linenoise.c (edit_in_editor): Fix by reordering.
* parser.c (is_balanced_line): Fix by reordering.
* regex.c (nfa_count_one, print_rec): Fix by reordering.
* signal.c (sig_mask): Fix by reordering.
* stream.c (get_string): Fix by renaming optional argument and
using declaration instead of assignment.
* struct.c (lookup_static_slot_desc): Fix by turning mutated
variable into block local.
(umethod_args_fun): Fix by reordering.
(get_special_slot): Fix by new scope via braces.
* sysif.c (usleep_wrap): Fix by new scope via braces.
(setrlimit_wrap): Fix by new scope via braces.
* time.c (time_string_meth, time_parse_meth): Fix by reordering.
* tree.c (tr_do_delete_spec): Fix by new scope via braces.
* unwind.h (uw_block_beg): New macro which doesn't define
RESULTVAR but expects it to refers to an existing one.
(uw_block_begin): Replace do while (0) with enum trick
so that we have a declaration that requires a semicolon,
rather than a statement, allowing declarations to follow.
(uw_match_env_begin): Now opens a scope and features the
same enum trick as in uw_block_begin.
This fixes a declaration-follows-statement issue in
the v_output function in match.c.
(uw_match_env_end): Closes scope opened by uw_match_env_begin.
* unwind.c (revive_cont): Fix by introducing variable, and
using new uw_block_beg macro.
* vm.c (vm_execute_closure): Fix using combination of local
variable and reordering.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 79 |
1 files changed, 44 insertions, 35 deletions
@@ -2256,9 +2256,10 @@ static val revlist(val in, val *tail) loc list_collect_revappend(loc ptail, val obj) { val last; - obj = nullify(obj); val tailobj = deref(ptail); + obj = nullify(obj); + again: switch (type(tailobj)) { case CONS: @@ -2520,10 +2521,11 @@ static val sub_iter(val obj, val from, val to) { val self = lit("sub"); seq_iter_t iter; - seq_iter_init(self, &iter, obj); val idx = zero, elem; list_collect_decl (out, ptail); + seq_iter_init(self, &iter, obj); + if (from == t) return nil; @@ -5443,10 +5445,11 @@ val replace_str(val str_in, val items, val from, val to) c_str(items, self), c_num(len_it, self)); } else { seq_iter_t item_iter; - seq_iter_init(self, &item_iter, items); cnum f = c_num(from, self); cnum t = c_num(to, self); + seq_iter_init(self, &item_iter, items); + for (; f != t; f++) str_in->st.str[f] = c_chr(seq_geti(&item_iter)); } @@ -6719,9 +6722,9 @@ val make_sym(val name) } } -val gensym(val prefix) +val gensym(val prefix_in) { - prefix = default_arg(prefix, lit("g")); + val prefix = default_arg(prefix_in, lit("g")); loc gs_loc = lookup_var_l(nil, gensym_counter_s); val name = format(nil, lit("~a~,04d"), prefix, set(gs_loc, plus(deref(gs_loc), one)), nao); @@ -9220,11 +9223,12 @@ val replace_vec(val vec_in, val items, val from, val to) mut(vec_in); } else { seq_iter_t item_iter; - seq_iter_init(self, &item_iter, items); int mut_needed = 0; cnum f = c_num(from, self); cnum t = c_num(to, self); + seq_iter_init(self, &item_iter, items); + for (; f != t; f++) { val item = seq_geti(&item_iter); if (is_ptr(item)) @@ -10126,10 +10130,11 @@ val mapcar_listout(val fun, val seq) { val self = lit("mapcar"); seq_iter_t iter; - seq_iter_init(self, &iter, seq); val elem; list_collect_decl (out, ptail); + seq_iter_init(self, &iter, seq); + while (seq_get(&iter, &elem)) ptail = list_collect(ptail, funcall1(fun, elem)); @@ -10158,10 +10163,11 @@ val mappend(val fun, val seq) { val self = lit("mappend"); seq_iter_t iter; - seq_iter_init(self, &iter, seq); val elem; list_collect_decl (out, ptail); + seq_iter_init(self, &iter, seq); + while (seq_get(&iter, &elem)) ptail = list_collect_append(ptail, funcall1(fun, elem)); @@ -10172,9 +10178,10 @@ val mapdo(val fun, val seq) { val self = lit("mapdo"); seq_iter_t iter; - seq_iter_init(self, &iter, seq); val elem; + seq_iter_init(self, &iter, seq); + while (seq_get(&iter, &elem)) funcall1(fun, elem); @@ -10239,9 +10246,11 @@ static val window_map_list(val range, val boundary, val fun, val list, args->arg[i] = ref(boundary, num(j++)); for (;;) { + val item; args_decl (args_cp, ws); args_copy(args_cp, args); - val item = generic_funcall(fun, args_cp); + + item = generic_funcall(fun, args_cp); switch (op) { case WMAP_MAP: ptail = list_collect(ptail, item); break; @@ -10819,11 +10828,11 @@ val rot(val seq, val n_in) return seq; } -val find(val item, val seq, val testfun, val keyfun) +val find(val item, val seq, val testfun_in, val keyfun_in) { val self = lit("find"); - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); seq_info_t si = seq_info(seq); switch (si.kind) { @@ -10877,11 +10886,11 @@ val find(val item, val seq, val testfun, val keyfun) } } -val rfind(val item, val seq, val testfun, val keyfun) +val rfind(val item, val seq, val testfun_in, val keyfun_in) { val self = lit("rfind"); - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); seq_info_t si = seq_info(seq); switch (si.kind) { @@ -11199,11 +11208,11 @@ val rfind_if(val predi, val seq, val key) return found; } -val pos(val item, val seq, val testfun, val keyfun) +val pos(val item, val seq, val testfun_in, val keyfun_in) { val self = lit("pos"); - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); seq_info_t si = seq_info(seq); switch (si.kind) { @@ -11260,11 +11269,11 @@ val pos(val item, val seq, val testfun, val keyfun) } } -val rpos(val item, val seq, val testfun, val keyfun) +val rpos(val item, val seq, val testfun_in, val keyfun_in) { val self = lit("rpos"); - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); seq_info_t si = seq_info(seq); switch (si.kind) { @@ -11525,12 +11534,13 @@ val subst(val oldv, val newv, val seq, val testfun_in, val keyfun_in) { val self = lit("subst"); seq_iter_t iter; - seq_iter_init(self, &iter, seq); val elem; val testfun = default_arg(testfun_in, equal_f); val keyfun = default_arg(keyfun_in, identity_f); list_collect_decl (out, ptail); + seq_iter_init(self, &iter, seq); + while (seq_get(&iter, &elem)) { val key = funcall1(keyfun, elem); ptail = list_collect(ptail, if3(funcall2(testfun, oldv, key), newv, elem)); @@ -12003,7 +12013,7 @@ val drop_until(val pred, val seq, val keyfun) } } -val in(val seq, val item, val testfun, val keyfun) +val in(val seq, val item, val testfun_in, val keyfun_in) { val self = lit("in"); seq_info_t si = seq_info(seq); @@ -12015,8 +12025,8 @@ val in(val seq, val item, val testfun, val keyfun) case STR: case LSTR: { - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); val len = length_str(seq); val ind; @@ -12032,8 +12042,8 @@ val in(val seq, val item, val testfun, val keyfun) } case VEC: { - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); val len = length_vec(seq); val ind; @@ -12050,7 +12060,7 @@ val in(val seq, val item, val testfun, val keyfun) default: switch (si.kind) { case SEQ_HASHLIKE: - if (null_or_missing_p(testfun) && null_or_missing_p(keyfun)) + if (null_or_missing_p(testfun_in) && null_or_missing_p(keyfun_in)) return tnil(gethash_e(self, si.obj, item)); /* fallthrough */ case SEQ_LISTLIKE: @@ -12058,12 +12068,11 @@ val in(val seq, val item, val testfun, val keyfun) { seq_iter_t iter; val elem; + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); seq_iter_init(self, &iter, seq); - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); - while (seq_get(&iter, &elem)) { val key = funcall1(keyfun, elem); if (funcall2(testfun, item, key)) @@ -12629,10 +12638,10 @@ val update(val seq, val fun) } static val search_common(val self, int from_right, - val seq, val key, val testfun, val keyfun) + val seq, val key, val testfun_in, val keyfun_in) { - testfun = default_arg(testfun, equal_f); - keyfun = default_arg(keyfun, identity_f); + val testfun = default_arg(testfun_in, equal_f); + val keyfun = default_arg(keyfun_in, identity_f); seq_iter_t si, ki; seq_iter_init(self, &si, seq); |