From: ludovic.courtes@laas.fr (Ludovic Courtès)
Subject: Re: [PATCH] Fixed `scm_i_take_stringbufn ()'
Date: Tue, 14 Feb 2006 10:47:30 +0100 [thread overview]
Message-ID: <87d5hqw9u5.fsf@laas.fr> (raw)
In-Reply-To: <87slqnrlb0.fsf@zip.com.au> (Kevin Ryde's message of "Tue, 14 Feb 2006 08:38:43 +1100")
Hi,
Kevin Ryde <user42@zip.com.au> writes:
> The `if' you put, with an fprintf stderr, should be fine.
I think you're right. Here's the updated patch.
Thanks,
Ludovic.
2006-02-14 Ludovic Courtès <ludovic.courtes@laas.fr>
*strings.c (scm_i_take_stringbufn): Register LEN + 1 octets
instead of LEN. Without this, too much collectable memory gets
unregistered, which results in an underflow of SCM_MALLOCATED in
`decrease_mtrigger ()'.
* gc-malloc.c (decrease_mtrigger): Make sure SIZE is lower than
or equal to SCM_MALLOCATED.
--- orig/libguile/gc-malloc.c
+++ mod/libguile/gc-malloc.c
@@ -64,6 +64,7 @@
#include <unistd.h>
#endif
+
/*
INIT_MALLOC_LIMIT is the initial amount of malloc usage which will
trigger a GC.
@@ -184,6 +185,16 @@
decrease_mtrigger (size_t size, const char * what)
{
scm_i_pthread_mutex_lock (&scm_i_gc_admin_mutex);
+
+ if (size > scm_mallocated)
+ {
+ fprintf (stderr, "`scm_mallocated' underflow. This means that more "
+ "memory was unregistered\n"
+ "via `scm_gc_unregister_collectable_memory ()' than "
+ "registered.\n");
+ abort ();
+ }
+
scm_mallocated -= size;
scm_gc_malloc_collected += size;
scm_i_pthread_mutex_unlock (&scm_i_gc_admin_mutex);
--- orig/libguile/strings.c
+++ mod/libguile/strings.c
@@ -122,12 +122,12 @@
}
}
-/* Return a new stringbuf whose underlying storage consists of the LEN octets
- pointed to by STR. */
+/* Return a new stringbuf whose underlying storage consists of the LEN+1
+ octets pointed to by STR (the last octet is zero). */
SCM_C_INLINE SCM
scm_i_take_stringbufn (char *str, size_t len)
{
- scm_gc_register_collectable_memory (str, len, "stringbuf");
+ scm_gc_register_collectable_memory (str, len + 1, "stringbuf");
return scm_double_cell (STRINGBUF_TAG, (scm_t_bits) str,
(scm_t_bits) len, (scm_t_bits) 0);
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2006-02-14 9:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-13 16:38 [PATCH] Fixed `scm_i_take_stringbufn ()' Ludovic Courtès
2006-02-13 21:38 ` Kevin Ryde
2006-02-14 9:47 ` Ludovic Courtès [this message]
2006-02-15 0:38 ` Kevin Ryde
2006-02-15 7:58 ` Ludovic Courtès
2006-02-15 22:03 ` Kevin Ryde
2006-02-21 8:37 ` Ludovic Courtès
2006-02-15 0:48 ` Kevin Ryde
2006-02-15 8:01 ` Ludovic Courtès
2006-02-15 22:15 ` Kevin Ryde
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=87d5hqw9u5.fsf@laas.fr \
--to=ludovic.courtes@laas.fr \
/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).