From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludovic.courtes@laas.fr (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Fixed `scm_i_take_stringbufn ()' Date: Tue, 14 Feb 2006 10:47:30 +0100 Organization: LAAS-CNRS Message-ID: <87d5hqw9u5.fsf@laas.fr> References: <877j7zb4dl.fsf@laas.fr> <87slqnrlb0.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1139911683 16902 80.91.229.2 (14 Feb 2006 10:08:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 14 Feb 2006 10:08:03 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Feb 14 11:08:03 2006 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1F8x69-0002S4-B5 for guile-devel@m.gmane.org; Tue, 14 Feb 2006 11:07:53 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F8x4d-0001qh-Up for guile-devel@m.gmane.org; Tue, 14 Feb 2006 05:06:20 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F8wms-00031M-EE for guile-devel@gnu.org; Tue, 14 Feb 2006 04:47:58 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F8wmq-00030H-PR for guile-devel@gnu.org; Tue, 14 Feb 2006 04:47:57 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F8wmq-0002zL-1G for guile-devel@gnu.org; Tue, 14 Feb 2006 04:47:56 -0500 Original-Received: from [140.93.0.15] (helo=laas.laas.fr) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1F8wrT-0008Q6-Sc for guile-devel@gnu.org; Tue, 14 Feb 2006 04:52:44 -0500 Original-Received: by laas.laas.fr (8.13.1/8.13.4) with SMTP id k1E9lgtf021503; Tue, 14 Feb 2006 10:47:51 +0100 (CET) Original-To: guile-devel@gnu.org X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 26 =?iso-8859-1?Q?Pluvi=F4se?= an 214 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: powerpc-unknown-linux-gnu Mail-Followup-To: guile-devel@gnu.org In-Reply-To: <87slqnrlb0.fsf@zip.com.au> (Kevin Ryde's message of "Tue, 14 Feb 2006 08:38:43 +1100") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) X-Spam-Score: 0.496 () MAILTO_TO_SPAM_ADDR X-Scanned-By: MIMEDefang at CNRS-LAAS X-MIME-Autoconverted: from 8bit to quoted-printable by laas.laas.fr id k1E9lgtf021503 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:5702 Archived-At: Hi, Kevin Ryde 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=E8s *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 #endif =20 + /* 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 mor= e " + "memory was unregistered\n" + "via `scm_gc_unregister_collectable_memory ()' than " + "registered.\n"); + abort (); + } + scm_mallocated -=3D size; scm_gc_malloc_collected +=3D size; scm_i_pthread_mutex_unlock (&scm_i_gc_admin_mutex); --- orig/libguile/strings.c +++ mod/libguile/strings.c @@ -122,12 +122,12 @@ } } =20 -/* Return a new stringbuf whose underlying storage consists of the LEN o= ctets - 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"); =20 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