mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
gpgscm: Refactor cell finalization.
* tests/gpgscm/scheme.c (finalize_cell): Use switch, return whether the cell may be freed. (gc): Update callsite. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
78547bfe8a
commit
d2f6798621
@ -402,7 +402,7 @@ static pointer _get_cell(scheme *sc, pointer a, pointer b);
|
|||||||
static pointer reserve_cells(scheme *sc, int n);
|
static pointer reserve_cells(scheme *sc, int n);
|
||||||
static pointer get_consecutive_cells(scheme *sc, int n);
|
static pointer get_consecutive_cells(scheme *sc, int n);
|
||||||
static pointer find_consecutive_cells(scheme *sc, int n);
|
static pointer find_consecutive_cells(scheme *sc, int n);
|
||||||
static void finalize_cell(scheme *sc, pointer a);
|
static int finalize_cell(scheme *sc, pointer a);
|
||||||
static int count_consecutive_cells(pointer x, int needed);
|
static int count_consecutive_cells(pointer x, int needed);
|
||||||
static pointer find_slot_in_env(scheme *sc, pointer env, pointer sym, int all);
|
static pointer find_slot_in_env(scheme *sc, pointer env, pointer sym, int all);
|
||||||
static pointer mk_number(scheme *sc, num n);
|
static pointer mk_number(scheme *sc, num n);
|
||||||
@ -1723,15 +1723,16 @@ static void gc(scheme *sc, pointer a, pointer b) {
|
|||||||
if (is_mark(p)) {
|
if (is_mark(p)) {
|
||||||
clrmark(p);
|
clrmark(p);
|
||||||
} else {
|
} else {
|
||||||
/* reclaim cell */
|
/* reclaim cell */
|
||||||
if (typeflag(p) & T_FINALIZE) {
|
if ((typeflag(p) & T_FINALIZE) == 0
|
||||||
finalize_cell(sc, p);
|
|| finalize_cell(sc, p)) {
|
||||||
}
|
/* Reclaim cell. */
|
||||||
++sc->fcells;
|
++sc->fcells;
|
||||||
typeflag(p) = 0;
|
typeflag(p) = 0;
|
||||||
car(p) = sc->NIL;
|
car(p) = sc->NIL;
|
||||||
cdr(p) = sc->free_cell;
|
cdr(p) = sc->free_cell;
|
||||||
sc->free_cell = p;
|
sc->free_cell = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1748,10 +1749,17 @@ static void gc(scheme *sc, pointer a, pointer b) {
|
|||||||
sc->no_memory = 1;
|
sc->no_memory = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void finalize_cell(scheme *sc, pointer a) {
|
/* Finalize A. Returns true if a can be added to the list of free
|
||||||
if(is_string(a)) {
|
* cells. */
|
||||||
|
static int
|
||||||
|
finalize_cell(scheme *sc, pointer a)
|
||||||
|
{
|
||||||
|
switch (type(a)) {
|
||||||
|
case T_STRING:
|
||||||
sc->free(strvalue(a));
|
sc->free(strvalue(a));
|
||||||
} else if(is_port(a)) {
|
break;
|
||||||
|
|
||||||
|
case T_PORT:
|
||||||
if(a->_object._port->kind&port_file
|
if(a->_object._port->kind&port_file
|
||||||
&& a->_object._port->rep.stdio.closeit) {
|
&& a->_object._port->rep.stdio.closeit) {
|
||||||
port_close(sc,a,port_input|port_output);
|
port_close(sc,a,port_input|port_output);
|
||||||
@ -1759,19 +1767,28 @@ static void finalize_cell(scheme *sc, pointer a) {
|
|||||||
sc->free(a->_object._port->rep.string.start);
|
sc->free(a->_object._port->rep.string.start);
|
||||||
}
|
}
|
||||||
sc->free(a->_object._port);
|
sc->free(a->_object._port);
|
||||||
} else if(is_foreign_object(a)) {
|
break;
|
||||||
|
|
||||||
|
case T_FOREIGN_OBJECT:
|
||||||
a->_object._foreign_object._vtable->finalize(sc, a->_object._foreign_object._data);
|
a->_object._foreign_object._vtable->finalize(sc, a->_object._foreign_object._data);
|
||||||
} else if (is_vector(a)) {
|
break;
|
||||||
int i;
|
|
||||||
for (i = vector_size(vector_length(a)) - 1; i > 0; i--) {
|
case T_VECTOR:
|
||||||
pointer p = a + i;
|
do {
|
||||||
typeflag(p) = 0;
|
int i;
|
||||||
car(p) = sc->NIL;
|
for (i = vector_size(vector_length(a)) - 1; i > 0; i--) {
|
||||||
cdr(p) = sc->free_cell;
|
pointer p = a + i;
|
||||||
sc->free_cell = p;
|
typeflag(p) = 0;
|
||||||
sc->fcells += 1;
|
car(p) = sc->NIL;
|
||||||
}
|
cdr(p) = sc->free_cell;
|
||||||
|
sc->free_cell = p;
|
||||||
|
sc->fcells += 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} while (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1; /* Free cell. */
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SHOW_ERROR_LINE
|
#if SHOW_ERROR_LINE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user