mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-05 12:31:50 +01:00
gpgscm: Make global data constant when possible.
* tests/gpgscm/scheme-private.h (struct scheme): Make 'vptr' const. * tests/gpgscm/scheme.c (num_zero): Statically initialize and turn into constant. (num_one): Likewise. (charnames): Change type so that it can be stored in rodata. (is_ascii_name): Adapt slightly. (assign_proc): Make argument const char *. (op_code_info): Make some fields const char *. (tests): Make const. (dispatch_table): Make const. At least it can be made read-only after relocation. (Eval_Cycle): Adapt slightly. (vtbl): Make const. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
56638c28ad
commit
c9c3fe8832
@ -200,7 +200,7 @@ unsigned int flags;
|
|||||||
void *ext_data; /* For the benefit of foreign functions */
|
void *ext_data; /* For the benefit of foreign functions */
|
||||||
long gensym_cnt;
|
long gensym_cnt;
|
||||||
|
|
||||||
struct scheme_interface *vptr;
|
const struct scheme_interface *vptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* operator code */
|
/* operator code */
|
||||||
|
@ -205,8 +205,8 @@ static INLINE int num_is_integer(pointer p) {
|
|||||||
return ((p)->_object._number.is_fixnum);
|
return ((p)->_object._number.is_fixnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
static num num_zero;
|
static const struct num num_zero = { 1, {0} };
|
||||||
static num num_one;
|
static const struct num num_one = { 1, {1} };
|
||||||
|
|
||||||
/* macros for cell operations */
|
/* macros for cell operations */
|
||||||
#define typeflag(p) ((p)->_flag)
|
#define typeflag(p) ((p)->_flag)
|
||||||
@ -339,7 +339,7 @@ static INLINE int Cislower(int c) { return isascii(c) && islower(c); }
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_ASCII_NAMES
|
#if USE_ASCII_NAMES
|
||||||
static const char *charnames[32]={
|
static const char charnames[32][3]={
|
||||||
"nul",
|
"nul",
|
||||||
"soh",
|
"soh",
|
||||||
"stx",
|
"stx",
|
||||||
@ -377,12 +377,12 @@ static const char *charnames[32]={
|
|||||||
static int is_ascii_name(const char *name, int *pc) {
|
static int is_ascii_name(const char *name, int *pc) {
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<32; i++) {
|
for(i=0; i<32; i++) {
|
||||||
if(stricmp(name,charnames[i])==0) {
|
if (strncasecmp(name, charnames[i], 3) == 0) {
|
||||||
*pc=i;
|
*pc=i;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(stricmp(name,"del")==0) {
|
if (strcasecmp(name, "del") == 0) {
|
||||||
*pc=127;
|
*pc=127;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -447,7 +447,7 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op);
|
|||||||
static void Eval_Cycle(scheme *sc, enum scheme_opcodes op);
|
static void Eval_Cycle(scheme *sc, enum scheme_opcodes op);
|
||||||
static void assign_syntax(scheme *sc, char *name);
|
static void assign_syntax(scheme *sc, char *name);
|
||||||
static int syntaxnum(pointer p);
|
static int syntaxnum(pointer p);
|
||||||
static void assign_proc(scheme *sc, enum scheme_opcodes, char *name);
|
static void assign_proc(scheme *sc, enum scheme_opcodes, const char *name);
|
||||||
|
|
||||||
#define num_ivalue(n) (n.is_fixnum?(n).value.ivalue:(long)(n).value.rvalue)
|
#define num_ivalue(n) (n.is_fixnum?(n).value.ivalue:(long)(n).value.rvalue)
|
||||||
#define num_rvalue(n) (!n.is_fixnum?(n).value.rvalue:(double)(n).value.ivalue)
|
#define num_rvalue(n) (!n.is_fixnum?(n).value.rvalue:(double)(n).value.ivalue)
|
||||||
@ -5308,7 +5308,7 @@ static int is_nonneg(pointer p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Correspond carefully with following defines! */
|
/* Correspond carefully with following defines! */
|
||||||
static struct {
|
static const struct {
|
||||||
test_predicate fct;
|
test_predicate fct;
|
||||||
const char *kind;
|
const char *kind;
|
||||||
} tests[]={
|
} tests[]={
|
||||||
@ -5347,17 +5347,18 @@ static struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
dispatch_func func;
|
dispatch_func func;
|
||||||
char *name;
|
const char *name;
|
||||||
int min_arity;
|
int min_arity;
|
||||||
int max_arity;
|
int max_arity;
|
||||||
char *arg_tests_encoding;
|
const char *arg_tests_encoding;
|
||||||
} op_code_info;
|
} op_code_info;
|
||||||
|
|
||||||
#define INF_ARG 0xffff
|
#define INF_ARG 0xffff
|
||||||
|
|
||||||
static op_code_info dispatch_table[]= {
|
static const op_code_info dispatch_table[]= {
|
||||||
#define _OP_DEF(A,B,C,D,E,OP) {A,B,C,D,E},
|
#define _OP_DEF(A,B,C,D,E,OP) {A,B,C,D,E},
|
||||||
#include "opdefines.h"
|
#include "opdefines.h"
|
||||||
|
#undef _OP_DEF
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -5374,7 +5375,7 @@ static const char *procname(pointer x) {
|
|||||||
static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) {
|
static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) {
|
||||||
sc->op = op;
|
sc->op = op;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
op_code_info *pcd=dispatch_table+sc->op;
|
const op_code_info *pcd=dispatch_table+sc->op;
|
||||||
if (pcd->name!=0) { /* if built-in function, check arguments */
|
if (pcd->name!=0) { /* if built-in function, check arguments */
|
||||||
char msg[STRBUFFSIZE];
|
char msg[STRBUFFSIZE];
|
||||||
int ok=1;
|
int ok=1;
|
||||||
@ -5457,7 +5458,7 @@ static void assign_syntax(scheme *sc, char *name) {
|
|||||||
typeflag(x) |= T_SYNTAX;
|
typeflag(x) |= T_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void assign_proc(scheme *sc, enum scheme_opcodes op, char *name) {
|
static void assign_proc(scheme *sc, enum scheme_opcodes op, const char *name) {
|
||||||
pointer x, y;
|
pointer x, y;
|
||||||
|
|
||||||
x = mk_symbol(sc, name);
|
x = mk_symbol(sc, name);
|
||||||
@ -5519,7 +5520,7 @@ INTERFACE static pointer s_immutable_cons(scheme *sc, pointer a, pointer b) {
|
|||||||
return immutable_cons(sc,a,b);
|
return immutable_cons(sc,a,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct scheme_interface vtbl ={
|
static const struct scheme_interface vtbl = {
|
||||||
scheme_define,
|
scheme_define,
|
||||||
s_cons,
|
s_cons,
|
||||||
s_immutable_cons,
|
s_immutable_cons,
|
||||||
@ -5616,11 +5617,6 @@ int scheme_init_custom_alloc(scheme *sc, func_alloc malloc, func_dealloc free) {
|
|||||||
int i, n=sizeof(dispatch_table)/sizeof(dispatch_table[0]);
|
int i, n=sizeof(dispatch_table)/sizeof(dispatch_table[0]);
|
||||||
pointer x;
|
pointer x;
|
||||||
|
|
||||||
num_zero.is_fixnum=1;
|
|
||||||
num_zero.value.ivalue=0;
|
|
||||||
num_one.is_fixnum=1;
|
|
||||||
num_one.value.ivalue=1;
|
|
||||||
|
|
||||||
#if USE_INTERFACE
|
#if USE_INTERFACE
|
||||||
sc->vptr=&vtbl;
|
sc->vptr=&vtbl;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user