unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Proper way of making a single-pointer smob
@ 2013-05-29  6:16 Sun Yijiang
  2013-05-29 13:48 ` Panicz Maciej Godek
  2013-05-29 14:02 ` Mike Gran
  0 siblings, 2 replies; 7+ messages in thread
From: Sun Yijiang @ 2013-05-29  6:16 UTC (permalink / raw)
  To: guile-user

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



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

end of thread, other threads:[~2013-05-31  3:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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