unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* smob pointer moving
@ 2003-02-02  3:51 Noah Roberts
  2003-02-02  6:38 ` Steve Tell
  0 siblings, 1 reply; 3+ messages in thread
From: Noah Roberts @ 2003-02-02  3:51 UTC (permalink / raw)


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;
 public:
  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_NEWCELL(smob_blob);
      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 frm OPEN
db_open called.
()
guile> d
#<db 0x809d210>
guile>

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

Thanks for any help,
NR



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

end of thread, other threads:[~2003-02-02  6:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-02  3:51 smob pointer moving Noah Roberts
2003-02-02  6:38 ` Steve Tell
2003-02-02  6:56   ` Noah Roberts

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