unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Sun Yijiang <sunyijiang@gmail.com>
To: guile-user@gnu.org
Subject: Proper way of making a single-pointer smob
Date: Wed, 29 May 2013 14:16:06 +0800	[thread overview]
Message-ID: <CAL109eOq=yB01kngLLEgFXL8Kj9rOLuvRnXmGJ3CcXcvuHwUFQ@mail.gmail.com> (raw)

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?

C++ code listed below:

--------------------------------------
static scm_t_bits model_smob_t;

static SCM make_model() {
    return scm_new_smob(model_smob_t, (scm_t_bits)(new MyModel()));
}

static size_t free_model(SCM smob) {
    cout << "free_model" << endl;
    void* ptr = (void*)SCM_SMOB_DATA(smob);
    delete (MyModel*)ptr;
}

...

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

...

--------------------------------------

Regards,
Sun Yijiang



             reply	other threads:[~2013-05-29  6:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29  6:16 Sun Yijiang [this message]
2013-05-29 13:48 ` Proper way of making a single-pointer smob Panicz Maciej Godek
2013-05-29 14:02 ` Mike Gran
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='CAL109eOq=yB01kngLLEgFXL8Kj9rOLuvRnXmGJ3CcXcvuHwUFQ@mail.gmail.com' \
    --to=sunyijiang@gmail.com \
    --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).