unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Noah Roberts <nroberts@reachone.com>
Subject: smob pointer moving
Date: Sat, 01 Feb 2003 19:51:58 -0800	[thread overview]
Message-ID: <3E3C95DE.8030705@reachone.com> (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


             reply	other threads:[~2003-02-02  3:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-02  3:51 Noah Roberts [this message]
2003-02-02  6:38 ` smob pointer moving Steve Tell
2003-02-02  6:56   ` Noah Roberts

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=3E3C95DE.8030705@reachone.com \
    --to=nroberts@reachone.com \
    /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).