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: [PATCH] Fixed `scm_i_take_stringbufn ()' Date: Mon, 13 Feb 2006 17:38:46 +0100 Organization: LAAS-CNRS Message-ID: <877j7zb4dl.fsf@laas.fr> 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 1139849926 4032 80.91.229.2 (13 Feb 2006 16:58:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 13 Feb 2006 16:58:46 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Feb 13 17:58:45 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 1F8h1Q-0002If-0i for guile-devel@m.gmane.org; Mon, 13 Feb 2006 17:57:57 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F8h1P-0002oX-5w for guile-devel@m.gmane.org; Mon, 13 Feb 2006 11:57:55 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F8gj3-0003iZ-Uf for guile-devel@gnu.org; Mon, 13 Feb 2006 11:38:58 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F8gj1-0003gl-VU for guile-devel@gnu.org; Mon, 13 Feb 2006 11:38:57 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F8gj1-0003gP-GZ for guile-devel@gnu.org; Mon, 13 Feb 2006 11:38:55 -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 1F8gnU-0007m5-Rc for guile-devel@gnu.org; Mon, 13 Feb 2006 11:43:33 -0500 Original-Received: by laas.laas.fr (8.13.1/8.13.4) with SMTP id k1DGco7q026517; Mon, 13 Feb 2006 17:38:52 +0100 (CET) Original-To: guile-devel@gnu.org X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 25 =?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 User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) X-Spam-Score: 0 () X-Scanned-By: MIMEDefang at CNRS-LAAS X-MIME-Autoconverted: from 8bit to quoted-printable by laas.laas.fr id k1DGco7q026517 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:5689 Archived-At: Hi, The patch below fixes `scm_i_take_stringbufn ()' so that it registers the right amount of collectable memory. Failing to do so, an underflow was triggered in `decrease_mtrigger ()' (when decreasing SCM_MALLOCATED), resulting in a weird behavior (typically: fast increase in memory consumption quickly followed by the memory overflow error in `increase_mtrigger ()'). The problem can be reproduced using the program found at the end of this post. It could hardly be turned into a test case, however. Note: I'm not sure what to do with `assert ()'. Perhaps we should define our own macro somewhere? Thanks, Ludovic. 2006-02-13 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,10 @@ #include #endif =20 +#ifdef HAVE_ASSERT_H +#include +#endif + /* INIT_MALLOC_LIMIT is the initial amount of malloc usage which will trigger a GC. @@ -184,6 +188,14 @@ decrease_mtrigger (size_t size, const char * what) { scm_i_pthread_mutex_lock (&scm_i_gc_admin_mutex); + +#ifdef HAVE_ASSERT_H + assert (size <=3D scm_mallocated); +#else + if (size > scm_mallocated) + abort (); +#endif + 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); =0C /* Copyright (C) 1996,1997,2000,2001 Free Software Foundation, Inc. *=20 * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-13= 01 USA */ /* This is the 'main' function for the `guile' executable. It is not included in libguile.a. Eventually, we hope this file will be automatically generated, based on the list of installed, statically linked libraries on the system. For now, please don't put interesting code in here. */ #if HAVE_CONFIG_H # include #endif #include #ifdef HAVE_CONFIG_H #include #endif #include #include #include static void inner_main (void *closure SCM_UNUSED, int argc, char **argv) { static unsigned long long i =3D 0; while (1) { SCM str; i++; if ((i && !(i % 1000)) || (i > 82100)) /* At some point you will witness the underflow of SCM_MALLOCATED. */ printf ("i=3D%llu mallocated: %lu\n", i, scm_mallocated); #if 0 if (i =3D=3D 82112) /* Stop just before the underflow to attach GDB. */ kill (getpid (), SIGTSTP); #endif str =3D scm_take_locale_string (strdup ("csdfsdfsfsdfsldfkslkdfnlsk= df")); } } int main (int argc, char **argv) { scm_boot_guile (argc, argv, inner_main, 0); return 0; /* never reached */ } _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel