From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: smob gc protection, and inheritance
Date: Fri, 06 Sep 2013 14:19:31 +0200 [thread overview]
Message-ID: <87sixi16ss.fsf@gnu.org> (raw)
In-Reply-To: 5228DEFA.4030700@computer.org
Hi,
Andrew Gaylard <ag@computer.org> skribis:
> On 09/04/13 23:13, Ludovic Courtès wrote:
>> Hi Doug,
>>
>> Doug Evans <dje@sebabeach.org> 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
<http://www.hpl.hp.com/personal/Hans_Boehm/gc/>.
HTH,
Ludo’.
next prev parent reply other threads:[~2013-09-06 12:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-03 19:27 smob gc protection, and inheritance Doug Evans
2013-09-04 21:13 ` Ludovic Courtès
2013-09-05 19:43 ` Andrew Gaylard
2013-09-06 12:19 ` Ludovic Courtès [this message]
2013-09-07 8:22 ` Andy Wingo
2013-09-07 14:17 ` Ludovic Courtès
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=87sixi16ss.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guile-user@gnu.org \
/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).