[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper way of making a single-pointer smob

From: Panicz Maciej Godek
Subject: Re: Proper way of making a single-pointer smob
Date: Wed, 29 May 2013 15:48:39 +0200

2013/5/29 Sun Yijiang <address@hidden>
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);


I bet you meant scm_set_smob_free(model_smob_t, free_model).
In scm_make_smob_type you should use sizeof(void *) instead of 0 (at leats that's what works for me)
If you still don't get any messages, try replacing cout with cerr, or at least flush the buffer.
You can also try to invoke (gc) manually.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]