diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-04 19:11:02 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 15:43:35 +0100 |
commit | d38af48e0ae96fc4dc4a794ae8129372ed7c593f (patch) | |
tree | 9968b6b9ed7d2f563bc82c78d6556d4bcb524d0a | |
parent | abbc433d29307ee1e42f3a98c55b3d8e75a42350 (diff) | |
download | busybox-w32-d38af48e0ae96fc4dc4a794ae8129372ed7c593f.tar.gz busybox-w32-d38af48e0ae96fc4dc4a794ae8129372ed7c593f.tar.bz2 busybox-w32-d38af48e0ae96fc4dc4a794ae8129372ed7c593f.zip |
bc: convert BC_STATUS_EXEC_SIGNAL - its message string was never used
function old new delta
bc_vm_process 132 130 -2
bc_err_msgs 168 164 -4
dc_parse_parse 52 47 -5
bc_parse_reset 187 181 -6
bc_program_ready_msg 22 - -22
bc_program_exec 4478 4453 -25
bc_parse_parse 461 432 -29
bc_program_reset 159 105 -54
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/7 up/down: 0/-147) Total: -147 bytes
text data bss dec hex filename
987923 485 7296 995704 f3178 busybox_old
987766 485 7296 995547 f30db busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 2bde51521..bd70670d5 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -213,7 +213,7 @@ typedef enum BcStatus { | |||
213 | BC_STATUS_EXEC_REC_READ, | 213 | BC_STATUS_EXEC_REC_READ, |
214 | BC_STATUS_EXEC_BAD_TYPE, | 214 | BC_STATUS_EXEC_BAD_TYPE, |
215 | // BC_STATUS_EXEC_BAD_OBASE, | 215 | // BC_STATUS_EXEC_BAD_OBASE, |
216 | BC_STATUS_EXEC_SIGNAL, | 216 | // BC_STATUS_EXEC_SIGNAL, |
217 | BC_STATUS_EXEC_STACK, | 217 | BC_STATUS_EXEC_STACK, |
218 | 218 | ||
219 | // BC_STATUS_VEC_OUT_OF_BOUNDS, | 219 | // BC_STATUS_VEC_OUT_OF_BOUNDS, |
@@ -285,7 +285,7 @@ static const char *const bc_err_msgs[] = { | |||
285 | "read() call inside of a read() call", | 285 | "read() call inside of a read() call", |
286 | "variable is wrong type", | 286 | "variable is wrong type", |
287 | // "bad obase; must be [2, BC_BASE_MAX]", | 287 | // "bad obase; must be [2, BC_BASE_MAX]", |
288 | "signal caught and not handled", | 288 | // "signal caught and not handled", |
289 | "stack has too few elements", | 289 | "stack has too few elements", |
290 | 290 | ||
291 | // "index is out of bounds", | 291 | // "index is out of bounds", |
@@ -840,7 +840,7 @@ typedef struct BcProgram { | |||
840 | typedef unsigned long (*BcProgramBuiltIn)(BcNum *); | 840 | typedef unsigned long (*BcProgramBuiltIn)(BcNum *); |
841 | 841 | ||
842 | static void bc_program_addFunc(char *name, size_t *idx); | 842 | static void bc_program_addFunc(char *name, size_t *idx); |
843 | static BcStatus bc_program_reset(BcStatus s); | 843 | static void bc_program_reset(void); |
844 | 844 | ||
845 | #define BC_FLAG_X (1 << 0) | 845 | #define BC_FLAG_X (1 << 0) |
846 | #define BC_FLAG_W (1 << 1) | 846 | #define BC_FLAG_W (1 << 1) |
@@ -1034,7 +1034,6 @@ static const BcNumBinaryOp bc_program_ops[] = { | |||
1034 | }; | 1034 | }; |
1035 | 1035 | ||
1036 | static const char bc_program_stdin_name[] = "<stdin>"; | 1036 | static const char bc_program_stdin_name[] = "<stdin>"; |
1037 | static const char bc_program_ready_msg[] = "ready for more input\n"; | ||
1038 | 1037 | ||
1039 | #if ENABLE_BC | 1038 | #if ENABLE_BC |
1040 | static const char *bc_lib_name = "gen/lib.bc"; | 1039 | static const char *bc_lib_name = "gen/lib.bc"; |
@@ -3617,7 +3616,9 @@ static BcStatus bc_parse_text(BcParse *p, const char *text) | |||
3617 | return bc_lex_text(&p->l, text); | 3616 | return bc_lex_text(&p->l, text); |
3618 | } | 3617 | } |
3619 | 3618 | ||
3620 | static BcStatus bc_parse_reset(BcParse *p, BcStatus s) | 3619 | // Called when bc/dc_parse_parse() detects a failure, |
3620 | // resets parsing structures. | ||
3621 | static void bc_parse_reset(BcParse *p) | ||
3621 | { | 3622 | { |
3622 | if (p->fidx != BC_PROG_MAIN) { | 3623 | if (p->fidx != BC_PROG_MAIN) { |
3623 | 3624 | ||
@@ -3638,7 +3639,7 @@ static BcStatus bc_parse_reset(BcParse *p, BcStatus s) | |||
3638 | bc_vec_npop(&p->conds, p->conds.len); | 3639 | bc_vec_npop(&p->conds, p->conds.len); |
3639 | bc_vec_npop(&p->ops, p->ops.len); | 3640 | bc_vec_npop(&p->ops, p->ops.len); |
3640 | 3641 | ||
3641 | return bc_program_reset(s); | 3642 | bc_program_reset(); |
3642 | } | 3643 | } |
3643 | 3644 | ||
3644 | static void bc_parse_free(BcParse *p) | 3645 | static void bc_parse_free(BcParse *p) |
@@ -4733,8 +4734,10 @@ static BcStatus bc_parse_parse(BcParse *p) | |||
4733 | else | 4734 | else |
4734 | s = bc_parse_stmt(p); | 4735 | s = bc_parse_stmt(p); |
4735 | 4736 | ||
4736 | if (s || G_interrupt) | 4737 | if (s || G_interrupt) { |
4737 | s = bc_parse_reset(p, s); | 4738 | bc_parse_reset(p); |
4739 | s = BC_STATUS_FAILURE; | ||
4740 | } | ||
4738 | 4741 | ||
4739 | return s; | 4742 | return s; |
4740 | } | 4743 | } |
@@ -4947,7 +4950,7 @@ static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next) | |||
4947 | } | 4950 | } |
4948 | 4951 | ||
4949 | if (s) return s; | 4952 | if (s) return s; |
4950 | if (G_interrupt) return BC_STATUS_EXEC_SIGNAL; | 4953 | if (G_interrupt) return BC_STATUS_FAILURE; // ^C: stop parsing |
4951 | 4954 | ||
4952 | while (p->ops.len > ops_bgn) { | 4955 | while (p->ops.len > ops_bgn) { |
4953 | 4956 | ||
@@ -5207,7 +5210,10 @@ static BcStatus dc_parse_parse(BcParse *p) | |||
5207 | else | 5210 | else |
5208 | s = dc_parse_expr(p, 0); | 5211 | s = dc_parse_expr(p, 0); |
5209 | 5212 | ||
5210 | if (s || G_interrupt) s = bc_parse_reset(p, s); | 5213 | if (s || G_interrupt) { |
5214 | bc_parse_reset(p); | ||
5215 | s = BC_STATUS_FAILURE; | ||
5216 | } | ||
5211 | 5217 | ||
5212 | return s; | 5218 | return s; |
5213 | } | 5219 | } |
@@ -6494,7 +6500,9 @@ static void bc_program_addFunc(char *name, size_t *idx) | |||
6494 | } | 6500 | } |
6495 | } | 6501 | } |
6496 | 6502 | ||
6497 | static BcStatus bc_program_reset(BcStatus s) | 6503 | // Called when parsing or execution detects a failure, |
6504 | // resets execution structures. | ||
6505 | static void bc_program_reset(void) | ||
6498 | { | 6506 | { |
6499 | BcFunc *f; | 6507 | BcFunc *f; |
6500 | BcInstPtr *ip; | 6508 | BcInstPtr *ip; |
@@ -6506,18 +6514,12 @@ static BcStatus bc_program_reset(BcStatus s) | |||
6506 | ip = bc_vec_top(&G.prog.stack); | 6514 | ip = bc_vec_top(&G.prog.stack); |
6507 | ip->idx = f->code.len; | 6515 | ip->idx = f->code.len; |
6508 | 6516 | ||
6509 | if (!s && G_interrupt && !G.tty) quit(); | 6517 | // If !tty, no need to check for ^C: we don't have ^C handler, |
6518 | // we would be killed by a signal and won't reach this place | ||
6510 | 6519 | ||
6511 | if (!s || s == BC_STATUS_EXEC_SIGNAL) { | 6520 | fflush_and_check(); // make sure buffered stdout is printed |
6512 | if (!G.ttyin) | 6521 | fputs("ready for more input\n", stderr); |
6513 | quit(); | 6522 | fflush_and_check(); |
6514 | fflush_and_check(); // make sure buffered stdout is printed | ||
6515 | fputs(bc_program_ready_msg, stderr); | ||
6516 | fflush_and_check(); | ||
6517 | s = BC_STATUS_SUCCESS; | ||
6518 | } | ||
6519 | |||
6520 | return s; | ||
6521 | } | 6523 | } |
6522 | 6524 | ||
6523 | static BcStatus bc_program_exec(void) | 6525 | static BcStatus bc_program_exec(void) |
@@ -6828,7 +6830,10 @@ static BcStatus bc_program_exec(void) | |||
6828 | #endif // ENABLE_DC | 6830 | #endif // ENABLE_DC |
6829 | } | 6831 | } |
6830 | 6832 | ||
6831 | if (s || G_interrupt) s = bc_program_reset(s); | 6833 | if (s || G_interrupt) { |
6834 | bc_program_reset(); | ||
6835 | break; | ||
6836 | } | ||
6832 | 6837 | ||
6833 | // If the stack has changed, pointers may be invalid. | 6838 | // If the stack has changed, pointers may be invalid. |
6834 | ip = bc_vec_top(&G.prog.stack); | 6839 | ip = bc_vec_top(&G.prog.stack); |
@@ -6951,8 +6956,10 @@ static BcStatus bc_vm_process(const char *text) | |||
6951 | if (BC_PARSE_CAN_EXEC(&G.prs)) { | 6956 | if (BC_PARSE_CAN_EXEC(&G.prs)) { |
6952 | s = bc_program_exec(); | 6957 | s = bc_program_exec(); |
6953 | fflush_and_check(); | 6958 | fflush_and_check(); |
6954 | if (s) | 6959 | if (s) { |
6955 | s = bc_vm_error(bc_program_reset(s), G.prs.l.f, 0); | 6960 | bc_program_reset(); |
6961 | s = bc_vm_error(s, G.prs.l.f, 0); | ||
6962 | } | ||
6956 | } | 6963 | } |
6957 | 6964 | ||
6958 | return s; | 6965 | return s; |
@@ -7185,10 +7192,6 @@ static void bc_vm_init(const char *env_len) | |||
7185 | { | 7192 | { |
7186 | size_t len = bc_vm_envLen(env_len); | 7193 | size_t len = bc_vm_envLen(env_len); |
7187 | 7194 | ||
7188 | #if ENABLE_FEATURE_BC_SIGNALS | ||
7189 | signal_no_SA_RESTART_empty_mask(SIGINT, record_signo); | ||
7190 | #endif | ||
7191 | |||
7192 | bc_vec_init(&G.files, sizeof(char *), NULL); | 7195 | bc_vec_init(&G.files, sizeof(char *), NULL); |
7193 | 7196 | ||
7194 | if (IS_BC) { | 7197 | if (IS_BC) { |
@@ -7216,7 +7219,13 @@ static BcStatus bc_vm_run(int argc, char *argv[], | |||
7216 | G.ttyin = isatty(0); | 7219 | G.ttyin = isatty(0); |
7217 | G.tty = G.ttyin || (G.flags & BC_FLAG_I) || isatty(1); | 7220 | G.tty = G.ttyin || (G.flags & BC_FLAG_I) || isatty(1); |
7218 | 7221 | ||
7219 | if (G.ttyin && !(G.flags & BC_FLAG_Q)) bc_vm_info(); | 7222 | if (G.ttyin) { |
7223 | #if ENABLE_FEATURE_BC_SIGNALS | ||
7224 | signal_no_SA_RESTART_empty_mask(SIGINT, record_signo); | ||
7225 | #endif | ||
7226 | if (!(G.flags & BC_FLAG_Q)) | ||
7227 | bc_vm_info(); | ||
7228 | } | ||
7220 | st = bc_vm_exec(); | 7229 | st = bc_vm_exec(); |
7221 | 7230 | ||
7222 | #if ENABLE_FEATURE_CLEAN_UP | 7231 | #if ENABLE_FEATURE_CLEAN_UP |