From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Noah Roberts Newsgroups: gmane.lisp.guile.user Subject: smob pointer moving Date: Sat, 01 Feb 2003 19:51:58 -0800 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <3E3C95DE.8030705@reachone.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1044158327 30037 80.91.224.249 (2 Feb 2003 03:58:47 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 2 Feb 2003 03:58:47 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18fBHJ-0007oJ-00 for ; Sun, 02 Feb 2003 04:58:45 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18fBIP-00086C-08 for guile-user@m.gmane.org; Sat, 01 Feb 2003 22:59:53 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18fBHz-0007tq-00 for guile-user@gnu.org; Sat, 01 Feb 2003 22:59:27 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18fBHu-0007gd-00 for guile-user@gnu.org; Sat, 01 Feb 2003 22:59:25 -0500 Original-Received: from mail-front2.reachone.com ([216.177.224.13]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18fBHt-0007dx-00 for guile-user@gnu.org; Sat, 01 Feb 2003 22:59:22 -0500 Original-Received: from reachone.com (dialup-228-73.reachone.net [216.177.228.73]) by mail-front2.reachone.com (Postfix) with ESMTP id F1CC247A24 for ; Sat, 1 Feb 2003 20:06:50 -0800 (PST) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020605 X-Accept-Language: en-us, en Original-To: guile-user@gnu.org X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General Guile related discussions List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:1590 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:1590 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(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 # guile> (db-open d) Database is at 0x805ed78 DB frm OPEN db_open called. () guile> d # 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