1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

* print.c (make_print_state, grow_print_state), print.h: Modified

the print state representation: Don't use a tail array for
recording of circular references.  Resizing of the print state
structure invalidates the print state pointer.  To avoid passing
around an indirect print state reference to all printing
functions, we instead let the print state reference a resizable
vector.
This commit is contained in:
Mikael Djurfeldt 1996-10-15 03:40:21 +00:00
parent 2a786759c1
commit bf685b6d20
2 changed files with 14 additions and 24 deletions

View file

@ -175,9 +175,14 @@ static SCM
make_print_state ()
{
SCM print_state = scm_make_struct (SCM_CAR (print_state_pool), /* pstate type */
SCM_MAKINUM (PSTATE_SIZE),
SCM_INUM0,
SCM_EOL);
SCM_PRINT_STATE (print_state)->ceiling = PSTATE_SIZE;
scm_print_state *pstate = SCM_PRINT_STATE (print_state);
pstate->ref_vect = scm_make_vector (SCM_MAKINUM (PSTATE_SIZE),
SCM_UNDEFINED,
SCM_UNDEFINED);
pstate->ref_stack = SCM_VELTS (pstate->ref_vect);
pstate->ceiling = SCM_LENGTH (pstate->ref_vect);
return print_state;
}
@ -224,25 +229,10 @@ static void
grow_ref_stack (pstate)
scm_print_state *pstate;
{
int i, size = pstate->ceiling;
int total_size;
SCM handle;
SCM *data;
SCM_DEFER_INTS;
handle = pstate->handle;
data = (SCM *) pstate - scm_struct_n_extra_words;
total_size = ((SCM *) pstate)[scm_struct_i_n_words];
data = (SCM *) scm_must_realloc ((char *) data,
total_size,
total_size + size,
"grow_ref_stack");
pstate = (scm_print_state *) (data + scm_struct_n_extra_words);
((SCM *) pstate)[scm_struct_i_n_words] = total_size + size;
pstate->ceiling += size;
for (i = size; i < pstate->ceiling; ++i)
pstate->ref_stack[i] = SCM_BOOL_F;
SCM_SETCDR (handle, pstate);
SCM_ALLOW_INTS;
int new_size = 2 * pstate->ceiling;
scm_vector_set_length_x (pstate->ref_vect, SCM_MAKINUM (new_size));
pstate->ref_stack = SCM_VELTS (pstate->ref_vect);
pstate->ceiling = new_size;
}

View file

@ -67,7 +67,7 @@ extern scm_option scm_print_opts[];
#define SCM_WRITINGP(pstate) ((pstate)->writingp)
#define SCM_SET_WRITINGP(pstate, x) { (pstate)->writingp = (x); }
#define SCM_PRINT_STATE_LAYOUT "sruwuwuwuwpwuwuwurpW"
#define SCM_PRINT_STATE_LAYOUT "sruwuwuwuwpwuwuwuruopr"
typedef struct scm_print_state {
SCM handle; /* Struct handle */
unsigned long writingp; /* Writing? */
@ -78,9 +78,9 @@ typedef struct scm_print_state {
unsigned long list_offset;
unsigned long top; /* Top of reference stack */
unsigned long ceiling; /* Max size of reference stack */
unsigned long n_refs; /* Size of struct tail array */
SCM ref_stack[1]; /* Stack of references used during
SCM *ref_stack; /* Stack of references used during
circular reference detection */
SCM ref_vect;
} scm_print_state;
extern SCM scm_print_options SCM_P ((SCM setting));