unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Need for scm_remember_upto_here_* in guile-2.0
@ 2015-09-12 12:27 Chris Vine
  2015-09-22 14:54 ` Ludovic Courtès
  0 siblings, 1 reply; 14+ messages in thread
From: Chris Vine @ 2015-09-12 12:27 UTC (permalink / raw)
  To: guile-user

Hi,

The guile manual suggests (section 5.5.5) that  if a smob's internals
are referenced in a function after the last time that the SCM variable
representing the smob is accessed in the function,
scm_remember_upto_here_* should be used.  Otherwise the suggestion is
made that the optimizer may treat the smob as expended after the last
access to its variable is made in the function, with the result that
the collector may reclaim its memory, including any internals (in the
case of the example in section 5.5.5, the smob's 'image' struct).

scm_remember_upto_here_1() does this by the simple expedient of taking
the SCM object as an argument and doing nothing, so the garbage
collector still thinks the smob is in use until then.  (This is fine as
far as it goes although could perhaps be tripped up by
link-time-optimization).

However I am finding difficulty in understanding why that should be the
case, because in that example all the smob's internals are allocated
using scm_gc_malloc()/GC_MALLOC or scm_gc_malloc_pointerless()/
GC_MALLOC_ATOMIC.  The garbage collector should therefore be fully
aware of those internals and be able to mark them for survival if still
in use, without any help from the programmer.

Is the point here that the example code contains an unnecessary (and
ill-advised) free function for the smob, which calls scm_gc_free() on
its internals?  If so, is the point that the scm_remember_upto_here_*
functions are in practice only needed for smobs which provide their own
free function?

If so, that would further imply (in relation to the 'image' example)
that finding a live managed pointer allocated by scm_gc_malloc() in the
smob's data field (as passed when calling scm_new_smob()) does not save
the smob from collection by the garbage collector (and so its free
function being invoked by guile).  Is that really the case?

Regards,

Chris



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-09-23 16:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-12 12:27 Need for scm_remember_upto_here_* in guile-2.0 Chris Vine
2015-09-22 14:54 ` Ludovic Courtès
2015-09-22 15:26   ` David Kastrup
2015-09-22 16:24     ` Mark H Weaver
2015-09-22 17:08       ` David Kastrup
2015-09-22 21:13       ` Ludovic Courtès
2015-09-22 23:35         ` Chris Vine
2015-09-22 23:48           ` Chris Vine
2015-09-23  7:26             ` David Kastrup
2015-09-23  8:41               ` Chris Vine
2015-09-23  8:54                 ` David Kastrup
2015-09-23  9:40                   ` Chris Vine
2015-09-23 12:27                     ` David Kastrup
2015-09-23 16:45                       ` Chris Vine

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).