* print.c (EXIT_NESTED_DATA): Before popping from the stack, reset
authorNeil Jerram <neil@ossau.uklinux.net>
Thu, 17 Nov 2005 18:50:01 +0000 (18:50 +0000)
committerNeil Jerram <neil@ossau.uklinux.net>
Thu, 17 Nov 2005 18:50:01 +0000 (18:50 +0000)
the value at its top.  This fixes a reference leak.
(PUSH_REF): Perform `pstate->top++' after calling
`PSTATE_STACK_SET ()' in order to avoid undesired potential side
effects.

libguile/ChangeLog
libguile/print.c

index 52c7066..0ea6940 100644 (file)
@@ -1,3 +1,11 @@
+2005-11-17  Ludovic Courtès  <ludovic.courtes@laas.fr>
+
+       * print.c (EXIT_NESTED_DATA): Before popping from the stack, reset
+       the value at its top.  This fixes a reference leak.
+       (PUSH_REF): Perform `pstate->top++' after calling
+       `PSTATE_STACK_SET ()' in order to avoid undesired potential side
+       effects.
+
 2005-11-12  Ludovic Courtès  <ludovic.courtes@laas.fr>
 
        * gc.c (scm_weak_vectors): Removed.
index 43b7165..cdeb0c4 100644 (file)
@@ -112,31 +112,40 @@ SCM_DEFINE (scm_print_options, "print-options-interface", 0, 1, 0,
  * time complexity (O (depth * N)), The printer code can be
  * rewritten to be O(N).
  */
-#define PUSH_REF(pstate, obj) \
-do { \
-  PSTATE_STACK_SET (pstate, pstate->top++, obj); \
-  if (pstate->top == pstate->ceiling) \
-    grow_ref_stack (pstate); \
+#define PUSH_REF(pstate, obj)                  \
+do                                             \
+{                                              \
+  PSTATE_STACK_SET (pstate, pstate->top, obj); \
+  pstate->top++;                               \
+  if (pstate->top == pstate->ceiling)          \
+    grow_ref_stack (pstate);                   \
 } while(0)
 
-#define ENTER_NESTED_DATA(pstate, obj, label) \
-do { \
-  register unsigned long i; \
-  for (i = 0; i < pstate->top; ++i) \
-    if (scm_is_eq (PSTATE_STACK_REF (pstate, i), (obj))) \
-      goto label; \
-  if (pstate->fancyp) \
-    { \
-      if (pstate->top - pstate->list_offset >= pstate->level) \
-       { \
-         scm_putc ('#', port); \
-         return; \
-       } \
-    } \
-  PUSH_REF(pstate, obj); \
+#define ENTER_NESTED_DATA(pstate, obj, label)                  \
+do                                                             \
+{                                                              \
+  register unsigned long i;                                    \
+  for (i = 0; i < pstate->top; ++i)                            \
+    if (scm_is_eq (PSTATE_STACK_REF (pstate, i), (obj)))       \
+      goto label;                                              \
+  if (pstate->fancyp)                                          \
+    {                                                          \
+      if (pstate->top - pstate->list_offset >= pstate->level)  \
+       {                                                       \
+         scm_putc ('#', port);                                 \
+         return;                                               \
+       }                                                       \
+    }                                                          \
+  PUSH_REF(pstate, obj);                                       \
 } while(0)
 
-#define EXIT_NESTED_DATA(pstate) { --pstate->top; }
+#define EXIT_NESTED_DATA(pstate)                               \
+do                                                             \
+{                                                              \
+  --pstate->top;                                               \
+  PSTATE_STACK_SET (pstate, pstate->top, SCM_UNDEFINED);       \
+}                                                              \
+while (0)
 
 SCM scm_print_state_vtable = SCM_BOOL_F;
 static SCM print_state_pool = SCM_EOL;