[Top][All Lists]

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

smob pointer moving

From: Noah Roberts
Subject: smob pointer moving
Date: Sat, 01 Feb 2003 19:51:58 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020605

I have been trying to figure out how to get a C++ class working in guile through smobs. I have suceeded in getting it to create an instance, and the print call works appropriately. However, when I am calling a specific method (only one tried so far) the pointer to the object has been altered so that it no longer points at the correct 'this'. Here is some relevant pieces of code:

class Database
 char *filename;
 Database(char *name); // prints filename
 ~Database() { printf("Database freed.\n"); }
 void open(); // prints filename

#define DB(X) ((Database*)(SCM_CDR(X)))

int print_db(SCM obj, SCM port, scm_print_state *pstate)
 char string[32];
 sprintf(string, "#<db %p>", DB(obj));
 scm_puts(string, port);
 return 1;
SCM db_create_new(SCM filename)
 Database *db;
 SCM smob_blob;
 printf("db_create_new called.\n");
 if (SCM_STRINGP(filename))
     db = new Database(SCM_STRING_CHARS(filename));
     SCM_SETCAR(smob_blob, db_id);
     SCM_SETCDR(smob_blob, (SCM)(db));
return smob_blob;
 else return SCM_BOOL_F;

SCM db_open(SCM obj)
 Database *db = DB(db);
printf("Database is at %p\n", db); db->open();
 printf("db_open called.\n");
 return SCM_EOL;

 scm_c_define_gsubr("db-create-new", 1, 0, 0, (SCM (*)(...))db_create_new);
 scm_c_define_gsubr("db-open", 1, 0, 0, (SCM (*)(...))db_open);

 scm_set_smob_print(db_id, print_db);

Right now, Database simply prints out some information. When db-open is called from guile I get a crash or "frm" is the filename spit out by Database.

Here is some sample output:
guile> (define d (db-create-new "SNTH"))
db_create_new called.
Database SNTH requested at 0x809d210.
guile> d
#<db 0x809d210>
guile> (db-open d)
Database is at 0x805ed78
db_open called.
guile> d
#<db 0x809d210>

as you can see, when db-open is called the pointer returned by the DB macro is not correct, why?

Thanks for any help,

reply via email to

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