From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Whitlock, Bradley D" Newsgroups: gmane.lisp.guile.user Subject: RE: Guile 1.8 Garbage Collection Question Date: Tue, 25 Oct 2011 20:36:20 +0000 Message-ID: <1B716C7666FD684A9FDF0FBD5EE5E0A0156F8537@HDXDSP11.us.lmco.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="Boundary_(ID_r875ZZQLb3FcFU6IzR2Ygw)" X-Trace: dough.gmane.org 1319575017 542 80.91.229.12 (25 Oct 2011 20:36:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 25 Oct 2011 20:36:57 +0000 (UTC) To: "guile-user@gnu.org" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Oct 25 22:36:50 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RInjt-0005R0-O7 for guile-user@m.gmane.org; Tue, 25 Oct 2011 22:36:50 +0200 Original-Received: from localhost ([::1]:60684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RInjs-0004ty-To for guile-user@m.gmane.org; Tue, 25 Oct 2011 16:36:48 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:56012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RInjn-0004tW-11 for guile-user@gnu.org; Tue, 25 Oct 2011 16:36:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RInjk-0008OJ-Qt for guile-user@gnu.org; Tue, 25 Oct 2011 16:36:42 -0400 Original-Received: from mailfo01.lmco.com ([192.31.106.12]:46794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RInjk-0008OF-JJ for guile-user@gnu.org; Tue, 25 Oct 2011 16:36:40 -0400 Original-Received: from mailgw1a.lmco.com (ppalertrelay.lmco.com [192.31.106.7]) by mailfo01.lmco.com (8.14.3/8.14.3) with ESMTP id p9PKadMJ013399 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 25 Oct 2011 21:36:39 +0100 Original-Received: from emss02g01.ems.lmco.com (relay2.ems.lmco.com [166.29.2.54])by mailgw1a.lmco.com (LM-6) with ESMTP id p9PKacTN021410for ; Tue, 25 Oct 2011 14:36:39 -0600 (MDT) Original-Received: from CONVERSION2-DAEMON.lmco.com by lmco.com (PMDF V6.4 #31805) id <0LTN00E012KJGA@lmco.com> for guile-user@gnu.org; Tue, 25 Oct 2011 20:36:38 +0000 (GMT) Original-Received: from HDXHTPN6.us.lmco.com ([158.188.83.13]) by lmco.com (PMDF V6.4 #31805) with ESMTP id <0LTN004142KLRU@lmco.com> for guile-user@gnu.org; Tue, 25 Oct 2011 20:36:21 +0000 (GMT) Original-Received: from HDXDSP11.us.lmco.com ([fe80::c04a:c222:3486:3e3]) by HDXHTPN6.us.lmco.com ([fe80::1db3:a00c:a3c9:9df6%14]) with mapi id 14.01.0289.001; Tue, 25 Oct 2011 14:36:21 -0600 X-Originating-IP: [158.188.95.12] Content-language: en-US Thread-Topic: Guile 1.8 Garbage Collection Question Thread-Index: AcyTVWq2ojPqdoNQSzSK7EYaLvUVuAAAD1Og Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.4.6813, 1.0.211, 0.0.0000 definitions=2011-10-25_07:2011-10-25, 2011-10-25, 1970-01-01 signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.31.106.12 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8905 Archived-At: --Boundary_(ID_r875ZZQLb3FcFU6IzR2Ygw) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT I had a copy-paste error in the second function listing, it should be this: SCM_DEFINE (libguile_fst_writer_emit_value, "libguile-fst-writer-emit-value", 3,0,0, (SCM scm_ctx, SCM scm_fsthandle, SCM scm_val), "Write a change on fstHandle") { // Storage for temporary string char s_buf [1024]; scm_to_locale_stringbuf (scm_val, s_buf, 1024); fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx), SCM_TO_FSTHANDLE (scm_fsthandle), s_buf); return SCM_UNSPECIFIED; } -Brad From: Whitlock, Bradley D Sent: Tuesday, October 25, 2011 2:34 PM To: 'guile-user@gnu.org' Subject: Guile 1.8 Garbage Collection Question I have built Guile 1.8.8.2 on MinGW. I have wrapped some gtkwave code with Guile and have a memory issue. The following code apparently never frees 's', but I am not sure why. SCM_DEFINE (libguile_fst_writer_emit_value, "libguile-fst-writer-emit-value", 3,0,0, (SCM scm_ctx, SCM scm_fsthandle, SCM scm_val), "Write a change on fstHandle") { // Storage for temporary string char* s = NULL; scm_dynwind_begin (0); scm_dynwind_unwind_handler (free, s, SCM_F_WIND_EXPLICITLY); s = scm_to_locale_string (scm_val); fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx), SCM_TO_FSTHANDLE (scm_fsthandle), s_buf); scm_dynwind_end(); return SCM_UNSPECIFIED; } The code is called from Scheme land in the following loop: (let loop ((n 0)) (if (eq? n 10000000) #t (begin ;; Emit some changes on the signal (fst-emit-value ctx s (number->string (modulo n 2))) (fst-emit-value ctx s1 (number->string (modulo (1+ n) 2))) (fst-emit-time-change ctx n) (loop (1+ n)) ))) It seems to me that the garbage collector never gets a chance to run, so how do I make sure that the gc gets a turn? If I define my function like the following, the leak disappears, but it's a less desirable solution: SCM_DEFINE (libguile_fst_writer_emit_value, "libguile-fst-writer-emit-value", 3,0,0, (SCM scm_ctx, SCM scm_fsthandle, SCM scm_val), "Write a change on fstHandle") { // Storage for temporary string char s_buf [1024]; scm_to_locale_stringbuf (scm_val, s_buf, 1024); s = scm_to_locale_string (scm_val); fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx), SCM_TO_FSTHANDLE (scm_fsthandle), s_buf); return SCM_UNSPECIFIED; } Any suggestion? Thanks, Brad --Boundary_(ID_r875ZZQLb3FcFU6IzR2Ygw) Content-type: text/html; charset=us-ascii Content-transfer-encoding: quoted-printable

I had a copy-paste err= or in the second function listing, it should be this:

 

SCM_DEFINE (libguile_fst_writer_emit_value, "li= bguile-fst-writer-emit-value",

        &nbs= p;           3,0,0,=

        &nbs= p;           (SCM scm_ctx, SCM= scm_fsthandle, SCM scm_val),

        &nbs= p;           "Write = a change on fstHandle")

{

  // Storage for temporary string

  char s_buf [1024];

  scm_to_locale_stringbuf (scm_val, s_buf, 1024= );

 

  fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx)= ,

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    SCM_TO_FSTHANDLE (scm_fsthandle),

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    s_buf);

 

  return SCM_UNSPECIFIED;

}

 

-Brad

 

From: Whitlock= , Bradley D
Sent: Tuesday, October 25, 2011 2:34 PM
To: 'guile-user@gnu.org'
Subject: Guile 1.8 Garbage Collection Question

 

I have built Guile 1.8.8.2 on MinGW.

 

I have wrapped some gtkwave code with Guile and have= a memory issue. The following code apparently never frees ‘s’,= but I am not sure why.

 

SCM_DEFINE (libguile_fst_writer_emit_value, "li= bguile-fst-writer-emit-value",

        &nbs= p;           3,0,0,=

        &nbs= p;           (SCM scm_ctx, SCM= scm_fsthandle, SCM scm_val),

        &nbs= p;           "Write = a change on fstHandle")

{

  // Storage for temporary string

  char* s =3D NULL;

  scm_dynwind_begin (0);

  scm_dynwind_unwind_handler (free, s, SCM_F_WI= ND_EXPLICITLY);

 

  s =3D scm_to_locale_string (scm_val);

 

  fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx)= ,

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    SCM_TO_FSTHANDLE (scm_fsthandle),

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    s_buf);

 

  scm_dynwind_end();

 

  return SCM_UNSPECIFIED;

}

 

The code is called from Scheme land in the following= loop:

 

(let loop ((n 0))

  (if (eq? n 10000000) #t

      (begin

 

        &nbs= p;       ;; Emit some changes on the signal

        &nbs= p;       (fst-emit-value ctx s (number->st= ring (modulo n 2)))

        &nbs= p;       (fst-emit-value ctx s1 (number->s= tring (modulo (1+ n) 2)))

        &nbs= p;       (fst-emit-time-change ctx n)

 

        &nbs= p;       (loop (1+ n))

        &nbs= p;       )))

 

It seems to me that the garbage collector never gets= a chance to run, so how do I make sure that the gc gets a turn?

 

If I define my function like the following, the leak= disappears, but it’s a less desirable solution:

 

SCM_DEFINE (libguile_fst_writer_emit_value, "li= bguile-fst-writer-emit-value",

        &nbs= p;           3,0,0,=

        &nbs= p;           (SCM scm_ctx, SCM= scm_fsthandle, SCM scm_val),

        &nbs= p;           "Write = a change on fstHandle")

{

  // Storage for temporary string

  char s_buf [1024];

  scm_to_locale_stringbuf (scm_val, s_buf, 1024= );

  s =3D scm_to_locale_string (scm_val);

 

  fstWriterEmitValueChange(SCM_TO_CTX (scm_ctx)= ,

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    SCM_TO_FSTHANDLE (scm_fsthandle),

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    s_buf);

 

  return SCM_UNSPECIFIED;

}

 

Any suggestion?

 

Thanks,

Brad

--Boundary_(ID_r875ZZQLb3FcFU6IzR2Ygw)--