mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-18 14:17:03 +01:00
gpgscm: Deduplicate code.
* tests/gpgscm/scheme.c (oblist_add_by_name): Deduplicate. (new_slot_spec_in_env): Likewise. Fixes-commit: 6a3f857224eab108ae38e6259194b01b0ffdad8b Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
7dff6248bd
commit
3e91019a92
@ -1145,6 +1145,7 @@ pointer _cons(scheme *sc, pointer a, pointer b, int immutable) {
|
|||||||
return (x);
|
return (x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ========== oblist implementation ========== */
|
/* ========== oblist implementation ========== */
|
||||||
|
|
||||||
#ifndef USE_OBJECT_LIST
|
#ifndef USE_OBJECT_LIST
|
||||||
@ -1158,24 +1159,6 @@ static pointer oblist_initial_value(scheme *sc)
|
|||||||
return mk_vector(sc, 1009);
|
return mk_vector(sc, 1009);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a new symbol NAME at SLOT. SLOT must be obtained using
|
|
||||||
* oblist_find_by_name, and no insertion must be done between
|
|
||||||
* obtaining the SLOT and calling this function. Returns the new
|
|
||||||
* symbol. */
|
|
||||||
static pointer oblist_add_by_name(scheme *sc, const char *name, pointer *slot)
|
|
||||||
{
|
|
||||||
#define oblist_add_by_name_allocates 3
|
|
||||||
pointer x;
|
|
||||||
|
|
||||||
gc_disable(sc, gc_reservations (oblist_add_by_name));
|
|
||||||
x = immutable_cons(sc, mk_string(sc, name), sc->NIL);
|
|
||||||
typeflag(x) = T_SYMBOL;
|
|
||||||
setimmutable(car(x));
|
|
||||||
*slot = immutable_cons(sc, x, *slot);
|
|
||||||
gc_enable(sc);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Lookup the symbol NAME. Returns the symbol, or NIL if it does not
|
/* Lookup the symbol NAME. Returns the symbol, or NIL if it does not
|
||||||
* exist. In that case, SLOT points to the point where the new symbol
|
* exist. In that case, SLOT points to the point where the new symbol
|
||||||
* is to be inserted. */
|
* is to be inserted. */
|
||||||
@ -1244,6 +1227,13 @@ oblist_find_by_name(scheme *sc, const char *name, pointer **slot)
|
|||||||
return sc->NIL;
|
return sc->NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pointer oblist_all_symbols(scheme *sc)
|
||||||
|
{
|
||||||
|
return sc->oblist;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Add a new symbol NAME at SLOT. SLOT must be obtained using
|
/* Add a new symbol NAME at SLOT. SLOT must be obtained using
|
||||||
* oblist_find_by_name, and no insertion must be done between
|
* oblist_find_by_name, and no insertion must be done between
|
||||||
* obtaining the SLOT and calling this function. Returns the new
|
* obtaining the SLOT and calling this function. Returns the new
|
||||||
@ -1253,18 +1243,16 @@ static pointer oblist_add_by_name(scheme *sc, const char *name, pointer *slot)
|
|||||||
#define oblist_add_by_name_allocates 3
|
#define oblist_add_by_name_allocates 3
|
||||||
pointer x;
|
pointer x;
|
||||||
|
|
||||||
|
gc_disable(sc, gc_reservations (oblist_add_by_name));
|
||||||
x = immutable_cons(sc, mk_string(sc, name), sc->NIL);
|
x = immutable_cons(sc, mk_string(sc, name), sc->NIL);
|
||||||
typeflag(x) = T_SYMBOL;
|
typeflag(x) = T_SYMBOL;
|
||||||
setimmutable(car(x));
|
setimmutable(car(x));
|
||||||
*slot = immutable_cons(sc, x, *slot);
|
*slot = immutable_cons(sc, x, *slot);
|
||||||
|
gc_enable(sc);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
static pointer oblist_all_symbols(scheme *sc)
|
|
||||||
{
|
|
||||||
return sc->oblist;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static pointer mk_port(scheme *sc, port *p) {
|
static pointer mk_port(scheme *sc, port *p) {
|
||||||
pointer x = get_cell(sc, sc->NIL, sc->NIL);
|
pointer x = get_cell(sc, sc->NIL, sc->NIL);
|
||||||
@ -2643,6 +2631,7 @@ int eqv(pointer a, pointer b) {
|
|||||||
#define is_true(p) ((p) != sc->F)
|
#define is_true(p) ((p) != sc->F)
|
||||||
#define is_false(p) ((p) == sc->F)
|
#define is_false(p) ((p) == sc->F)
|
||||||
|
|
||||||
|
|
||||||
/* ========== Environment implementation ========== */
|
/* ========== Environment implementation ========== */
|
||||||
|
|
||||||
#if !defined(USE_ALIST_ENV) || !defined(USE_OBJECT_LIST)
|
#if !defined(USE_ALIST_ENV) || !defined(USE_OBJECT_LIST)
|
||||||
@ -2705,21 +2694,6 @@ static void new_frame_in_env(scheme *sc, pointer old_env)
|
|||||||
setenvironment(sc->envir);
|
setenvironment(sc->envir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert (VARIABLE, VALUE) at SSLOT. SSLOT must be obtained using
|
|
||||||
* find_slot_spec_in_env, and no insertion must be done between
|
|
||||||
* obtaining SSLOT and the call to this function. */
|
|
||||||
static INLINE void new_slot_spec_in_env(scheme *sc,
|
|
||||||
pointer variable, pointer value,
|
|
||||||
pointer *sslot)
|
|
||||||
{
|
|
||||||
#define new_slot_spec_in_env_allocates 2
|
|
||||||
pointer slot;
|
|
||||||
gc_disable(sc, gc_reservations (new_slot_spec_in_env));
|
|
||||||
slot = immutable_cons(sc, variable, value);
|
|
||||||
*sslot = immutable_cons(sc, slot, *sslot);
|
|
||||||
gc_enable(sc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the slot in ENV under the key HDL. If ALL is given, look in
|
/* Find the slot in ENV under the key HDL. If ALL is given, look in
|
||||||
* all environments enclosing ENV. If the lookup fails, and SSLOT is
|
* all environments enclosing ENV. If the lookup fails, and SSLOT is
|
||||||
* given, the position where the new slot has to be inserted is stored
|
* given, the position where the new slot has to be inserted is stored
|
||||||
@ -2766,18 +2740,6 @@ static INLINE void new_frame_in_env(scheme *sc, pointer old_env)
|
|||||||
setenvironment(sc->envir);
|
setenvironment(sc->envir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert (VARIABLE, VALUE) at SSLOT. SSLOT must be obtained using
|
|
||||||
* find_slot_spec_in_env, and no insertion must be done between
|
|
||||||
* obtaining SSLOT and the call to this function. */
|
|
||||||
static INLINE void new_slot_spec_in_env(scheme *sc,
|
|
||||||
pointer variable, pointer value,
|
|
||||||
pointer *sslot)
|
|
||||||
{
|
|
||||||
#define new_slot_spec_in_env_allocates 2
|
|
||||||
assert(is_symbol(variable));
|
|
||||||
*sslot = immutable_cons(sc, immutable_cons(sc, variable, value), *sslot);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the slot in ENV under the key HDL. If ALL is given, look in
|
/* Find the slot in ENV under the key HDL. If ALL is given, look in
|
||||||
* all environments enclosing ENV. If the lookup fails, and SSLOT is
|
* all environments enclosing ENV. If the lookup fails, and SSLOT is
|
||||||
* given, the position where the new slot has to be inserted is stored
|
* given, the position where the new slot has to be inserted is stored
|
||||||
@ -2816,6 +2778,21 @@ static pointer find_slot_in_env(scheme *sc, pointer env, pointer hdl, int all)
|
|||||||
return find_slot_spec_in_env(sc, env, hdl, all, NULL);
|
return find_slot_spec_in_env(sc, env, hdl, all, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Insert (VARIABLE, VALUE) at SSLOT. SSLOT must be obtained using
|
||||||
|
* find_slot_spec_in_env, and no insertion must be done between
|
||||||
|
* obtaining SSLOT and the call to this function. */
|
||||||
|
static INLINE void new_slot_spec_in_env(scheme *sc,
|
||||||
|
pointer variable, pointer value,
|
||||||
|
pointer *sslot)
|
||||||
|
{
|
||||||
|
#define new_slot_spec_in_env_allocates 2
|
||||||
|
pointer slot;
|
||||||
|
gc_disable(sc, gc_reservations (new_slot_spec_in_env));
|
||||||
|
slot = immutable_cons(sc, variable, value);
|
||||||
|
*sslot = immutable_cons(sc, slot, *sslot);
|
||||||
|
gc_enable(sc);
|
||||||
|
}
|
||||||
|
|
||||||
static INLINE void new_slot_in_env(scheme *sc, pointer variable, pointer value)
|
static INLINE void new_slot_in_env(scheme *sc, pointer variable, pointer value)
|
||||||
{
|
{
|
||||||
#define new_slot_in_env_allocates new_slot_spec_in_env_allocates
|
#define new_slot_in_env_allocates new_slot_spec_in_env_allocates
|
||||||
@ -2838,6 +2815,7 @@ static INLINE pointer slot_value_in_env(pointer slot)
|
|||||||
return cdr(slot);
|
return cdr(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ========== Evaluation Cycle ========== */
|
/* ========== Evaluation Cycle ========== */
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user