unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mike Gran <spk121@yahoo.com>
To: Sun Yijiang <sunyijiang@gmail.com>,
	"guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: Proper way of making a single-pointer smob
Date: Wed, 29 May 2013 07:02:33 -0700 (PDT)	[thread overview]
Message-ID: <1369836153.73399.YahooMailNeo@web120406.mail.ne1.yahoo.com> (raw)
In-Reply-To: <CAL109eOq=yB01kngLLEgFXL8Kj9rOLuvRnXmGJ3CcXcvuHwUFQ@mail.gmail.com>

>Hi guys,


>I'm using a very simple smob which only carries a pointer in the
>immediate word.  It works fine, but what worries me is that the free
>function seems never called.   Am I doing anything wrong?  What's the
>standard way of making such kind of smob?


What you are doing is mostly right, except for this.


> model_smob_t = scm_make_smob_type("model", 0);  // shall I use zero here?

Your "0" should be sizeof(MyModel*)

But that's not the problem.

The problem is either
1. You still have a pointer to the smob somewhere.  You need to make
 sure that there are no pointers anywhere to the smob.
2. The garbage collector isn't being run.  Maybe you never allocate
enough memory to cause the gc to run.  You can fix this by adding
a "scm_gc()" call just before you program exits to force a garbage
collection.
3. Some versions of Guile have a bug where the last smob defined
in your program is never freed, even if you've cleared out the
pointers and called scm_gc.

-Mike



  parent reply	other threads:[~2013-05-29 14:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29  6:16 Proper way of making a single-pointer smob Sun Yijiang
2013-05-29 13:48 ` Panicz Maciej Godek
2013-05-29 14:02 ` Mike Gran [this message]
2013-05-29 21:57   ` Ludovic Courtès
2013-05-30  7:10     ` Mike Gran
2013-05-30 11:56       ` Ludovic Courtès
2013-05-31  3:08   ` Sun Yijiang

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=1369836153.73399.YahooMailNeo@web120406.mail.ne1.yahoo.com \
    --to=spk121@yahoo.com \
    --cc=guile-user@gnu.org \
    --cc=sunyijiang@gmail.com \
    /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).