summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2014-04-25 01:39:59 -0400
committerMark H Weaver <mhw@netris.org>2014-04-25 01:39:59 -0400
commit0e92ef40d047696eb3334405b2dd32f51ca55006 (patch)
tree941963e64f91b6764462e942dfee6fa814f5c56c
parent7a85f2b68ce8c7c8a28e6bde03b7c9da01004db5 (diff)
print: Fix printing of weak vectors.
* libguile/print.c (print_vector_or_weak_vector): New static function. (iprin1): Use 'print_vector_or_weak_vector' in the vector and weak vector cases.
-rw-r--r--libguile/print.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/libguile/print.c b/libguile/print.c
index 4ad2a9572..b79eb3ffe 100644
--- a/libguile/print.c
+++ b/libguile/print.c
@@ -585,6 +585,33 @@ scm_iprin1 (SCM exp, SCM port, scm_print_state *pstate)
}
static void
+print_vector_or_weak_vector (SCM v, size_t len, SCM (*ref) (SCM, size_t),
+ SCM port, scm_print_state *pstate)
+{
+ long i;
+ long last = len - 1;
+ int cutp = 0;
+ if (pstate->fancyp && len > pstate->length)
+ {
+ last = pstate->length - 1;
+ cutp = 1;
+ }
+ for (i = 0; i < last; ++i)
+ {
+ scm_iprin1 (ref (v, i), port, pstate);
+ scm_putc_unlocked (' ', port);
+ }
+ if (i == last)
+ {
+ /* CHECK_INTS; */
+ scm_iprin1 (ref (v, i), port, pstate);
+ }
+ if (cutp)
+ scm_puts_unlocked (" ...", port);
+ scm_putc_unlocked (')', port);
+}
+
+static void
iprin1 (SCM exp, SCM port, scm_print_state *pstate)
{
switch (SCM_ITAG3 (exp))
@@ -766,35 +793,15 @@ iprin1 (SCM exp, SCM port, scm_print_state *pstate)
case scm_tc7_wvect:
ENTER_NESTED_DATA (pstate, exp, circref);
scm_puts_unlocked ("#w(", port);
- goto common_vector_printer;
+ print_vector_or_weak_vector (exp, scm_c_weak_vector_length (exp),
+ scm_c_weak_vector_ref, port, pstate);
+ EXIT_NESTED_DATA (pstate);
+ break;
case scm_tc7_vector:
ENTER_NESTED_DATA (pstate, exp, circref);
scm_puts_unlocked ("#(", port);
- common_vector_printer:
- {
- register long i;
- long last = SCM_SIMPLE_VECTOR_LENGTH (exp) - 1;
- int cutp = 0;
- if (pstate->fancyp
- && SCM_SIMPLE_VECTOR_LENGTH (exp) > pstate->length)
- {
- last = pstate->length - 1;
- cutp = 1;
- }
- for (i = 0; i < last; ++i)
- {
- scm_iprin1 (scm_c_vector_ref (exp, i), port, pstate);
- scm_putc_unlocked (' ', port);
- }
- if (i == last)
- {
- /* CHECK_INTS; */
- scm_iprin1 (scm_c_vector_ref (exp, i), port, pstate);
- }
- if (cutp)
- scm_puts_unlocked (" ...", port);
- scm_putc_unlocked (')', port);
- }
+ print_vector_or_weak_vector (exp, SCM_SIMPLE_VECTOR_LENGTH (exp),
+ scm_c_vector_ref, port, pstate);
EXIT_NESTED_DATA (pstate);
break;
case scm_tc7_port: