[PATCH v2] ash: reorder control characters to save bytes
Denys Vlasenko
vda.linux at googlemail.com
Fri Nov 16 17:21:27 UTC 2018
Let's keep the same values or at least the order as in dash.
There were bugs related to handling incoming chars which match "escape chars".
For example:
shell/ash_test/ash-quoting/dollar_squote_bash2.tests
shell/ash_test/ash-quoting/unicode_8x_chars.tests
shell/ash_test/ash-redir/redir7.tests
shell/ash_test/ash-redir/redir8.tests
If we change values of "escape chars", dash and ash will start exhibiting
*different behavior* if there are still bugs in this area =>
more PITA when debugging.
On Fri, Nov 16, 2018 at 2:48 PM Ron Yorston <rmy at pobox.com> wrote:
>
> During the processing of argument strings ash uses non-ASCII values
> to indicate particular constructs. These values are arbitrary and
> can be changed at will.
>
> Sampling a number of permutations showed that the current choice
> of values results in the largest code. 11% of samples were just
> as bad and 89% were better. The average reduction in code size
> was 11.77 bytes.
>
> function old new delta
> cmdputs 393 383 -10
> argstr 1313 1301 -12
> .rodata 168610 168594 -16
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-38) Total: -38 bytes
>
> v2: For completeness also update comments in syntax_index_table.
>
> Signed-off-by: Ron Yorston <rmy at pobox.com>
> ---
> shell/ash.c | 30 +++++++++++++++---------------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/shell/ash.c b/shell/ash.c
> index 90eaf6faf..7ae81ec7a 100644
> --- a/shell/ash.c
> +++ b/shell/ash.c
> @@ -715,15 +715,15 @@ out2str(const char *p)
> /* ============ Parser structures */
>
> /* control characters in argument strings */
> -#define CTL_FIRST CTLESC
> -#define CTLESC ((unsigned char)'\201') /* escape next character */
> +#define CTL_FIRST CTLENDARI
> +#define CTLENDARI ((unsigned char)'\201')
> #define CTLVAR ((unsigned char)'\202') /* variable defn */
> -#define CTLENDVAR ((unsigned char)'\203')
> -#define CTLBACKQ ((unsigned char)'\204')
> -#define CTLARI ((unsigned char)'\206') /* arithmetic expression */
> -#define CTLENDARI ((unsigned char)'\207')
> -#define CTLQUOTEMARK ((unsigned char)'\210')
> -#define CTL_LAST CTLQUOTEMARK
> +#define CTLESC ((unsigned char)'\203') /* escape next character */
> +#define CTLQUOTEMARK ((unsigned char)'\204')
> +#define CTLENDVAR ((unsigned char)'\205')
> +#define CTLBACKQ ((unsigned char)'\206')
> +#define CTLARI ((unsigned char)'\207') /* arithmetic expression */
> +#define CTL_LAST CTLARI
>
> /* variable substitution byte (follows CTLVAR) */
> #define VSTYPE 0x0f /* type of variable substitution */
> @@ -3156,14 +3156,14 @@ static const uint8_t syntax_index_table[] ALIGN1 = {
> /* 126 "~" */ CWORD_CCTL_CCTL_CWORD,
> /* 127 del */ CWORD_CWORD_CWORD_CWORD,
> /* 128 0x80 */ CWORD_CWORD_CWORD_CWORD,
> - /* 129 CTLESC */ CCTL_CCTL_CCTL_CCTL,
> + /* 129 CTLENDARI */ CCTL_CCTL_CCTL_CCTL,
> /* 130 CTLVAR */ CCTL_CCTL_CCTL_CCTL,
> - /* 131 CTLENDVAR */ CCTL_CCTL_CCTL_CCTL,
> - /* 132 CTLBACKQ */ CCTL_CCTL_CCTL_CCTL,
> - /* 133 CTLQUOTE */ CCTL_CCTL_CCTL_CCTL,
> - /* 134 CTLARI */ CCTL_CCTL_CCTL_CCTL,
> - /* 135 CTLENDARI */ CCTL_CCTL_CCTL_CCTL,
> - /* 136 CTLQUOTEMARK */ CCTL_CCTL_CCTL_CCTL,
> + /* 131 CTLESC */ CCTL_CCTL_CCTL_CCTL,
> + /* 132 CTLQUOTEMARK */ CCTL_CCTL_CCTL_CCTL,
> + /* 133 CTLENDVAR */ CCTL_CCTL_CCTL_CCTL,
> + /* 134 CTLBACKQ */ CCTL_CCTL_CCTL_CCTL,
> + /* 135 CTLARI */ CCTL_CCTL_CCTL_CCTL,
> + /* 136 */ CWORD_CWORD_CWORD_CWORD,
> /* 137 */ CWORD_CWORD_CWORD_CWORD,
> /* 138 */ CWORD_CWORD_CWORD_CWORD,
> /* 139 */ CWORD_CWORD_CWORD_CWORD,
> --
> 2.19.1
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list