diff options
author | Justus Winter <justus@g10code.com> | 2017-03-29 16:32:36 +0200 |
---|---|---|
committer | Justus Winter <justus@g10code.com> | 2017-04-10 14:57:25 +0200 |
commit | 7dff6248bddd5583988ac562318cf0d76a409d0e (patch) | |
tree | 75ce9fa1d11bd6ee7f474843f4ec9e3498be4c28 | |
parent | gpgscm: Use more threaded code. (diff) | |
download | gnupg2-7dff6248bddd5583988ac562318cf0d76a409d0e.tar.xz gnupg2-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 <justus@g10code.com>
-rw-r--r-- | tests/gpgscm/opdefines.h | 2 | ||||
-rw-r--r-- | tests/gpgscm/scheme.c | 25 |
2 files changed, 14 insertions, 13 deletions
diff --git a/tests/gpgscm/opdefines.h b/tests/gpgscm/opdefines.h index 6c53e1fad..bee2b6d1f 100644 --- a/tests/gpgscm/opdefines.h +++ b/tests/gpgscm/opdefines.h @@ -154,7 +154,7 @@ _OP_DEF("set-symbol-property!", 3, 3, TST_SYMBOL TST_SYMBOL TST _OP_DEF("symbol-property", 2, 2, TST_SYMBOL TST_SYMBOL, OP_SYMBOL_PROPERTY ) #endif #if USE_TAGS -_OP_DEF(NULL, 0, 0, TST_NONE, OP_TAG_VALUE ) +_OP_DEF(0, 0, 0, TST_NONE, OP_TAG_VALUE ) _OP_DEF("make-tagged-value", 2, 2, TST_ANY TST_PAIR, OP_MK_TAGGED ) _OP_DEF("get-tag", 1, 1, TST_ANY, OP_GET_TAG ) #endif 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); } } |