From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: smob gc protection, and inheritance Date: Fri, 06 Sep 2013 14:19:31 +0200 Message-ID: <87sixi16ss.fsf@gnu.org> References: <87y57c70js.fsf@gnu.org> <5228DEFA.4030700@computer.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1378476095 28173 80.91.229.3 (6 Sep 2013 14:01:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Sep 2013 14:01:35 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Sep 06 16:01:39 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VHwbR-0003ir-1M for guile-user@m.gmane.org; Fri, 06 Sep 2013 16:01:37 +0200 Original-Received: from localhost ([::1]:37815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHwbQ-0001wR-Ms for guile-user@m.gmane.org; Fri, 06 Sep 2013 10:01:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHv0y-0004Ve-0p for guile-user@gnu.org; Fri, 06 Sep 2013 08:19:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHv0r-000358-8b for guile-user@gnu.org; Fri, 06 Sep 2013 08:19:51 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:58666) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHv0r-00034Z-12 for guile-user@gnu.org; Fri, 06 Sep 2013 08:19:45 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VHv0m-00084N-VK for guile-user@gnu.org; Fri, 06 Sep 2013 14:19:40 +0200 Original-Received: from 193.50.110.150 ([193.50.110.150]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 06 Sep 2013 14:19:40 +0200 Original-Received: from ludo by 193.50.110.150 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 06 Sep 2013 14:19:40 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 61 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 193.50.110.150 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 20 Fructidor an 221 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:lZAtwuzyYc9cjKD1LJIuyb4csqw= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-Mailman-Approved-At: Fri, 06 Sep 2013 10:01:24 -0400 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:10755 Archived-At: Hi, Andrew Gaylard skribis: > On 09/04/13 23:13, Ludovic Courtès wrote: >> Hi Doug, >> >> Doug Evans skribis: >>> 3) The docs aren't as clear as they could be on whether the "smob" >>> free function needs to scm_gc_free all results of calls to scm_gc_malloc >>> made when constructing the smob. IIUC, this is not necessary. >> The ‘scm_gc_free’ function doesn’t need to be called nowadays, because >> the GC automatically frees ‘scm_gc_malloc’ regions when they are no >> longer referenced. >> >> So chances are you don’t even need a SMOB ‘free’ function. >> >>> However, why does the image example do this? >> Indeed, the ‘mark’ and ‘free’ functions in that example could be removed >> altogether, since the only resources associated with the SMOB is memory >> returned by ‘scm_gc_malloc’. > Hi Ludo', > > Thanks for this information -- it helps answer my guile-dbi question > (http://lists.gnu.org/archive/html/guile-user/2013-08/msg00133.html). > > You say "chances are" -- so when does one need a free() function? When some of the resources associated with a SMOB are not under GC’s control, and thus need to be freed explicitly by some other means. Examples of such resources include malloc’d memory, file descriptors, and opaque objects managed by an external library. > I suspect that guile-dbi does require one, because it has to close > the DB handle; right? In the case of GDBM, for instance, ‘gdbm_open’ returns an opaque GDBM_FILE, and that has to be explicitly freed via ‘gdbm_close’. So yes, in that case a SMOB ‘free’ function is required. > Since the SMOB was allocated with scm_gc_malloc, and since the > things it mark()s are all SCM types, does it follow that it's safe not to > mark() it at all? Yes. Quoting the manual (info "(guile) Smobs"): Defining a marking procedure may sometimes be unnecessary because large parts of the process’ memory (with the exception of ‘scm_gc_malloc_pointerless’ regions, and ‘malloc’- or ‘scm_malloc’-allocated memory) are scanned for live pointers(1). > Where can I find more information about how guile and its GC work? > In particular, is there a FAQ guide to debugging GC problems? The manual has some info under “Smobs” and “Memory Blocks”. Guile’s GC is the BDW-GC, whose documentation is available from . HTH, Ludo’.