summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Djurfeldt <djurfeldt@nada.kth.se>1996-10-15 03:40:21 +0000
committerMikael Djurfeldt <djurfeldt@nada.kth.se>1996-10-15 03:40:21 +0000
commitbf685b6d20c6cf9e7e49ecc09ab8dbb005a5e4e9 (patch)
treec327b9fa495a10a4af0d462dc0075133300987c7
parent2a786759c1e151443cb794ef105183db40f0dd89 (diff)
downloadguile-bf685b6d20c6cf9e7e49ecc09ab8dbb005a5e4e9.tar.gz
* 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.
-rw-r--r--libguile/print.c32
-rw-r--r--libguile/print.h6
2 files changed, 14 insertions, 24 deletions
diff --git a/libguile/print.c b/libguile/print.c
index fc7e6aa14..75ae40e6f 100644
--- a/libguile/print.c
+++ b/libguile/print.c
@@ -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;
}
diff --git a/libguile/print.h b/libguile/print.h
index 483d31386..cb326fb5b 100644
--- a/libguile/print.h
+++ b/libguile/print.h
@@ -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));