diff options
author | Justus Winter <[email protected]> | 2017-03-29 14:32:36 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2017-04-10 12:57:25 +0000 |
commit | 7dff6248bddd5583988ac562318cf0d76a409d0e (patch) | |
tree | 75ce9fa1d11bd6ee7f474843f4ec9e3498be4c28 /tests/gpgscm/scheme.c | |
parent | gpgscm: Use more threaded code. (diff) | |
download | gnupg-7dff6248bddd5583988ac562318cf0d76a409d0e.tar.gz gnupg-7dff6248bddd5583988ac562318cf0d76a409d0e.zip |
gpgscm: Move dispatch table into rodata.
* tests/gpgscm/opdefines.h: Use 0 instead of NULL.
* tests/gpgscm/scheme.c (op_code_info): Use char arrays instead of
pointers, make arity parameters smaller.
(INF_ARG): Adapt.
(_OP_DEF): Likewise.
(dispatch_table): Likewise.
(procname): Likewise.
(Eval_cycle): Likewise.
(scheme_init_custom_alloc): Likewise.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'tests/gpgscm/scheme.c')
-rw-r--r-- | tests/gpgscm/scheme.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tests/gpgscm/scheme.c b/tests/gpgscm/scheme.c index 3b6dffffe..7ba1cc22a 100644 --- a/tests/gpgscm/scheme.c +++ b/tests/gpgscm/scheme.c @@ -5262,25 +5262,25 @@ static const struct { #define TST_NATURAL "\016" typedef struct { - const char *name; - int min_arity; - int max_arity; - const char *arg_tests_encoding; + char name[31]; /* strlen ("call-with-current-continuation") + 1 */ + unsigned char min_arity; + unsigned char max_arity; + char arg_tests_encoding[3]; } op_code_info; -#define INF_ARG 0xffff +#define INF_ARG 0xff static const op_code_info dispatch_table[]= { -#define _OP_DEF(A,B,C,D,OP) {A,B,C,D}, +#define _OP_DEF(A,B,C,D,OP) {{A},B,C,{D}}, #include "opdefines.h" #undef _OP_DEF - { 0 } + {{0},0,0,{0}}, }; static const char *procname(pointer x) { int n=procnum(x); const char *name=dispatch_table[n].name; - if(name==0) { + if (name[0] == 0) { name="ILLEGAL!"; } return name; @@ -5291,7 +5291,7 @@ static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) { sc->op = op; for (;;) { const op_code_info *pcd=dispatch_table+sc->op; - if (pcd->name!=0) { /* if built-in function, check arguments */ + if (pcd->name[0] != 0) { /* if built-in function, check arguments */ char msg[STRBUFFSIZE]; int ok=1; int n=list_length(sc,sc->args); @@ -5312,7 +5312,7 @@ static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) { pcd->max_arity); } if(ok) { - if(pcd->arg_tests_encoding!=0) { + if (pcd->arg_tests_encoding[0] != 0) { int i=0; int j; const char *t=pcd->arg_tests_encoding; @@ -5326,7 +5326,8 @@ static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) { if(!tests[j].fct(arg)) break; } - if(t[1]!=0) {/* last test is replicated as necessary */ + if (t[1] != 0 && i < sizeof pcd->arg_tests_encoding) { + /* last test is replicated as necessary */ t++; } arglist=cdr(arglist); @@ -5620,7 +5621,7 @@ int scheme_init_custom_alloc(scheme *sc, func_alloc malloc, func_dealloc free) { assign_syntax(sc, "case"); for(i=0; i<n; i++) { - if(dispatch_table[i].name!=0) { + if (dispatch_table[i].name[0] != 0) { assign_proc(sc, (enum scheme_opcodes)i, dispatch_table[i].name); } } |