From: ludovic.courtes@laas.fr (Ludovic Courtès)
Cc: Han-Wen Nienhuys <hanwen@xs4all.nl>, guile-devel@gnu.org
Subject: Re: [PATCH] Reference leak in `iprin1 ()'
Date: Mon, 14 Nov 2005 10:58:46 +0100 [thread overview]
Message-ID: <874q6fsg89.fsf@laas.fr> (raw)
In-Reply-To: <87zmoa2pad.fsf@ossau.uklinux.net> (Neil Jerram's message of "Sat, 12 Nov 2005 09:23:06 +0000")
Hello,
Neil Jerram <neil@ossau.uklinux.net> writes:
> Nice work, but it looks to me that PUSH_REF sets the value of the
> (pstate->top)th element _before_ incrementing pstate->top. So
> shouldn't your fix do the decrement first and then set the slot to
> undefined?
Yes, you're perfectly right.
> (Note that your fix will still prevent most reference leaks, just not
> the outermost one. So that's why it may appear to be working
> already.)
Exactly.
> Also, is the () -> (void) change strictly related?
In fact, it's strictly unrelated, but while we're at it (really `(void)'
was meant here, not `()')...
Below is an updated patch. I modified `PUSH_REF ()' as well so that it
does PSTATE->TOP++ _after_ using the `PSTATE_STACK_SET ()' macro: this
is safer. And, well, I couldn't resist the desire to "beautifully
backslashify" `ENTER_NESTED_DATA ()' as well. :-) I hope this is not
too much pollution for you.
Thanks,
Ludovic.
2005-11-14 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 side effects.
(scm_current_pstate): Replaced `()' by `(void)'.
--- orig/libguile/print.c
+++ mod/libguile/print.c
@@ -112,31 +112,40 @@
* 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;
@@ -144,8 +153,8 @@
#ifdef GUILE_DEBUG /* Used for debugging purposes */
-SCM_DEFINE (scm_current_pstate, "current-pstate", 0, 0, 0,
- (),
+SCM_DEFINE (scm_current_pstate, "current-pstate", 0, 0, 0,
+ (void),
"Return the current-pstate -- the car of the\n"
"@code{print_state_pool}. @code{current-pstate} is only\n"
"included in @code{--enable-guile-debug} builds.")
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2005-11-14 9:58 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-08 17:22 [PATCH] Marking weak alist vectors Ludovic Courtès
2005-11-08 23:51 ` Marius Vollmer
2005-11-09 9:03 ` Ludovic Courtès
2005-12-06 23:55 ` Marius Vollmer
2005-12-07 10:33 ` Ludovic Courtès
2005-12-13 23:45 ` Marius Vollmer
2005-12-14 9:30 ` Ludovic Courtès
2005-11-09 10:28 ` Han-Wen Nienhuys
2005-11-09 16:28 ` Ludovic Courtès
2005-11-09 18:36 ` Han-Wen Nienhuys
2005-11-09 21:11 ` Kevin Ryde
2005-11-09 22:45 ` Marius Vollmer
2005-11-10 12:11 ` Han-Wen Nienhuys
2005-11-10 9:47 ` [PATCH] Reference leak in `iprin1 ()' Ludovic Courtès
2005-11-12 9:23 ` Neil Jerram
2005-11-14 9:58 ` Ludovic Courtès [this message]
2005-11-16 21:18 ` Neil Jerram
2005-11-17 9:54 ` Ludovic Courtès
2005-11-17 18:52 ` Neil Jerram
2005-11-23 10:19 ` [PATCH] Marking weak alist vectors, #2 Ludovic Courtès
2005-11-24 0:59 ` Han-Wen Nienhuys
2005-11-24 9:01 ` Ludovic Courtès
2005-11-26 0:49 ` Kevin Ryde
2006-01-09 14:51 ` [PATCH] Marking weak alist vectors, epilogue Ludovic Courtès
2006-01-09 19:29 ` Neil Jerram
2006-01-10 8:21 ` Ludovic Courtès
2006-01-10 9:33 ` Neil Jerram
2006-01-10 15:43 ` Ludovic Courtès
2005-11-17 13:21 ` [PATCH] Fixing `gc-live-object-stats' Ludovic Courtès
2005-11-17 14:12 ` Han-Wen Nienhuys
2005-11-30 8:54 ` Ludovic Courtès
2005-11-30 23:45 ` Han-Wen Nienhuys
2005-12-03 19:31 ` Neil Jerram
2005-12-05 8:50 ` Ludovic Courtès
2005-12-06 19:14 ` Neil Jerram
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874q6fsg89.fsf@laas.fr \
--to=ludovic.courtes@laas.fr \
--cc=guile-devel@gnu.org \
--cc=hanwen@xs4all.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).