diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-12-08 22:39:07 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-12-08 22:39:07 +0100 |
commit | 2064b68718ea5f15de76d661ae1f307d67a0cf26 (patch) | |
tree | 3b8f93932cb4a13ab6001f165de7714ec7e86848 /src/mds-kbdc/compile-layout.c | |
parent | update the texinfo manual for the new use of fail_if (diff) | |
download | mds-2064b68718ea5f15de76d661ae1f307d67a0cf26.tar.gz mds-2064b68718ea5f15de76d661ae1f307d67a0cf26.tar.bz2 mds-2064b68718ea5f15de76d661ae1f307d67a0cf26.tar.xz |
with a few exceptions and some remaining files, never return directly on failure, always goto fail by invoking fail_if
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-kbdc/compile-layout.c | 90 |
1 files changed, 68 insertions, 22 deletions
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c index ccf647c..539ade3 100644 --- a/src/mds-kbdc/compile-layout.c +++ b/src/mds-kbdc/compile-layout.c @@ -604,6 +604,8 @@ static int check_function_calls_in_literal(const mds_kbdc_tree_t* restrict tree, { int rc = 0; (void) check_function_calls_in_literal_(tree, raw, lineoff, &raw, &rc); + fail_if (rc < 0); + fail: return rc; } @@ -669,7 +671,10 @@ static char32_t* parse_escape(mds_kbdc_tree_t* restrict tree, const char* restri /* Read escape. */ if (*escape == 100) /* Function call. */ - return parse_function_call(tree, raw_, lineoff, escape, end); + { + fail_if (rc = parse_function_call(tree, raw_, lineoff, escape, end), rc == NULL); + return rc; + } /* Octal or hexadecimal representation, or variable dereference. */ for (; (c = *raw); have = 1, raw++) if (CR( 8, '0', '7')) numbuf = 8 * numbuf + (c & 15); @@ -909,7 +914,11 @@ static char32_t* parse_string(mds_kbdc_tree_t* restrict tree, const char* restri { mds_kbdc_tree_t* old_last_value_statement = last_value_statement; char32_t* rc = (strchr("\"\\", *raw) ? parse_quoted_string : parse_unquoted_string)(tree, raw, lineoff); - return last_value_statement = old_last_value_statement, rc; + last_value_statement = old_last_value_statement; + fail_if (rc == NULL); + return rc; + fail: + return NULL; } @@ -1077,7 +1086,7 @@ static size_t parse_variable(mds_kbdc_tree_t* restrict tree, const char* restric memcpy(dotless, raw_, n * sizeof(char)), dotless[n] = '\0'; var = (size_t)atoll(dotless + 1); if (strlen(dotless + 1) != (size_t)snprintf(NULL, 0, "%zu", var)) - return errno = ERANGE, (size_t)0; + fail_if ((errno = ERANGE)); return var; fail: return 0; @@ -1172,7 +1181,10 @@ static int parse_function_argument(mds_kbdc_tree_t* restrict tree, const char* r static int set_macro(mds_kbdc_tree_macro_t* restrict macro, mds_kbdc_include_stack_t* macro_include_stack) { - return callables_set(macro->name, 0, (mds_kbdc_tree_t*)macro, macro_include_stack); + fail_if (callables_set(macro->name, 0, (mds_kbdc_tree_t*)macro, macro_include_stack)); + return 0; + fail: + return -1; } @@ -1246,7 +1258,10 @@ static int set_function(mds_kbdc_tree_function_t* restrict function, *suffix_start = '\0'; r = callables_set(suffixless, arg_count, (mds_kbdc_tree_t*)function, function_include_stack); - return *suffix_start = '/', r; + fail_if (*suffix_start = '/', r); + return 0; + fail: + return -1; } @@ -1304,8 +1319,7 @@ static int compile_include(mds_kbdc_tree_include_t* restrict tree) { void* data; int r; - if (mds_kbdc_include_stack_push(tree, &data)) - return -1; + fail_if (mds_kbdc_include_stack_push(tree, &data)); r = compile_subtree(tree->inner); mds_kbdc_include_stack_pop(data); @@ -1314,7 +1328,10 @@ static int compile_include(mds_kbdc_tree_include_t* restrict tree) * include-stack as its overriding statement. */ last_value_statement = NULL; - return r; + fail_if (r); + return 0; + fail: + return -1; } @@ -1650,7 +1667,7 @@ static int compile_have_range(mds_kbdc_tree_assumption_have_range_t* restrict tr */ static int check_marco_calls(mds_kbdc_tree_t* restrict tree) { -#define t(...) if (rc |= r = (__VA_ARGS__), r < 0) return r +#define t(...) fail_if (rc |= r = (__VA_ARGS__), r < 0) mds_kbdc_tree_macro_t* _macro; mds_kbdc_include_stack_t* _macro_include_stack; void* data; @@ -1685,6 +1702,8 @@ static int check_marco_calls(mds_kbdc_tree_t* restrict tree) tree = tree->next; goto again; + fail: + return -1; (void) _macro; (void) _macro_include_stack; #undef t @@ -1699,7 +1718,7 @@ static int check_marco_calls(mds_kbdc_tree_t* restrict tree) */ static int check_function_calls_in_for(const mds_kbdc_tree_for_t* restrict tree) { -#define t(...) if (rc |= r = check_function_calls_in_literal(__VA_ARGS__), r < 0) return r +#define t(...) fail_if (rc |= r = check_function_calls_in_literal(__VA_ARGS__), r < 0) size_t lineoff_first; size_t lineoff_last; char* restrict code = result->source_code->real_lines[tree->loc_line]; @@ -1713,6 +1732,8 @@ static int check_function_calls_in_for(const mds_kbdc_tree_for_t* restrict tree) t ((const mds_kbdc_tree_t*)tree, tree->last, lineoff_last); return rc; + fail: + return -1; #undef t } @@ -1727,9 +1748,13 @@ static int check_function_calls_in_if(const mds_kbdc_tree_if_t* restrict tree) { size_t lineoff; char* restrict code = result->source_code->real_lines[tree->loc_line]; + int r; for (lineoff = tree->loc_end; code[lineoff] == ' '; lineoff++); - return check_function_calls_in_literal((const mds_kbdc_tree_t*)tree, tree->condition, lineoff); + r = check_function_calls_in_literal((const mds_kbdc_tree_t*)tree, tree->condition, lineoff); + fail_if (r < 0); + fail: + return r; } @@ -1741,7 +1766,11 @@ static int check_function_calls_in_if(const mds_kbdc_tree_if_t* restrict tree) */ static int check_function_calls_in_keys(const mds_kbdc_tree_keys_t* restrict tree) { - return check_function_calls_in_literal((const mds_kbdc_tree_t*)tree, tree->keys, tree->loc_start); + int r; + r = check_function_calls_in_literal((const mds_kbdc_tree_t*)tree, tree->keys, tree->loc_start); + fail_if (r < 0); + fail: + return r; } @@ -1753,7 +1782,11 @@ static int check_function_calls_in_keys(const mds_kbdc_tree_keys_t* restrict tre */ static int check_function_calls_in_string(const mds_kbdc_tree_string_t* restrict tree) { - return check_function_calls_in_literal((const mds_kbdc_tree_t*)tree, tree->string, tree->loc_start); + int r; + r = check_function_calls_in_literal((const mds_kbdc_tree_t*)tree, tree->string, tree->loc_start); + fail_if (r < 0); + fail: + return r; } @@ -1765,7 +1798,7 @@ static int check_function_calls_in_string(const mds_kbdc_tree_string_t* restrict */ static int check_function_calls(const mds_kbdc_tree_t* restrict tree) { -#define t(...) if (rc |= r = (__VA_ARGS__), r < 0) return r +#define t(...) fail_if (rc |= r = (__VA_ARGS__), r < 0) void* data; int r, rc = 0; again: @@ -1801,6 +1834,8 @@ static int check_function_calls(const mds_kbdc_tree_t* restrict tree) tree = tree->next; goto again; + fail: + return -1; #undef t } @@ -2103,12 +2138,13 @@ static int compile_if(mds_kbdc_tree_if_t* restrict tree) /* Evaluate whether the evaluted value is true. */ for (ok = 1, i = 0; data[i] >= 0; i++) ok &= !!(data[i]); - free(data); + free(data), data = NULL;; /* Compile the appropriate clause. */ ok = compile_subtree(ok ? tree->inner : tree->otherwise); last_value_statement = NULL; - return ok; + fail_if (ok < 0); + return 0; FAIL_BEGIN; free(data); FAIL_END; @@ -2200,7 +2236,10 @@ static int evaluate_element(mds_kbdc_tree_t* restrict node) */ static int compile_keys(mds_kbdc_tree_keys_t* restrict tree) { - return evaluate_element((mds_kbdc_tree_t*)tree) < 0 ? -1 : 0; + fail_if (evaluate_element((mds_kbdc_tree_t*)tree)); + return 0; + fail: + return -1; } @@ -2212,7 +2251,10 @@ static int compile_keys(mds_kbdc_tree_keys_t* restrict tree) */ static int compile_string(mds_kbdc_tree_string_t* restrict tree) { - return evaluate_element((mds_kbdc_tree_t*)tree) < 0 ? -1 : 0; + fail_if (evaluate_element((mds_kbdc_tree_t*)tree)); + return 0; + fail: + return -1; } @@ -2225,11 +2267,12 @@ static int compile_string(mds_kbdc_tree_string_t* restrict tree) static int compile_array(mds_kbdc_tree_array_t* restrict tree) { int r = evaluate_element(tree->elements); - if (r < 0) - return -1; + fail_if (r < 0); if (r) tree->processed = PROCESS_LEVEL; return 0; + fail: + return -1; } @@ -2261,7 +2304,7 @@ static int check_nonnul(mds_kbdc_tree_t* restrict tree) tree = tree->next; goto again; fail: - return -1; + return -1; } @@ -2533,7 +2576,10 @@ int compile_layout(mds_kbdc_parsed_t* restrict result_) variables_terminate(); callables_terminate(); errno = saved_errno; - return r; + fail_if (r); + return 0; + fail: + return -1; } |