From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Doug Evans Newsgroups: gmane.lisp.guile.user Subject: smob gc protection, and inheritance Date: Tue, 03 Sep 2013 12:27:51 -0700 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1378247973 6247 80.91.229.3 (3 Sep 2013 22:39:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 3 Sep 2013 22:39:33 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Sep 04 00:39:36 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VGzG4-0001s6-MC for guile-user@m.gmane.org; Wed, 04 Sep 2013 00:39:36 +0200 Original-Received: from localhost ([::1]:49483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGzG4-0007qV-9k for guile-user@m.gmane.org; Tue, 03 Sep 2013 18:39:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGwzT-0000V9-JM for guile-user@gnu.org; Tue, 03 Sep 2013 16:14:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VGwzS-0002Iv-FU for guile-user@gnu.org; Tue, 03 Sep 2013 16:14:19 -0400 Original-Received: from [2002:ad0d:b232:0:52e5:49ff:fee6:8e33] (port=39575 helo=seba.sebabeach.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGwzS-0002Ir-1I for guile-user@gnu.org; Tue, 03 Sep 2013 16:14:18 -0400 Original-Received: from seba.sebabeach.org (localhost [127.0.0.1]) by seba.sebabeach.org (8.14.7/8.14.7) with ESMTP id r83JRps0014089 for ; Tue, 3 Sep 2013 12:27:51 -0700 Original-Received: (from dje@localhost) by seba.sebabeach.org (8.14.7/8.14.7/Submit) id r83JRpbZ014088; Tue, 3 Sep 2013 12:27:51 -0700 X-Authentication-Warning: seba.sebabeach.org: dje set sender to dje@sebabeach.org using -f X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2002:ad0d:b232:0:52e5:49ff:fee6:8e33 X-Mailman-Approved-At: Tue, 03 Sep 2013 18:39:22 -0400 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10747 Archived-At: Hi. I have a few questions about smobs: 1) Suppose I have some C code that creates a smob and its containing SCM, but does not always expose the SCM to Scheme. E.g. struct foo_object { int bar; SCM baz; } static SCM make_foo_smob (void) { struct foo_object *foo_smob = (struct foo_object *) scm_gc_malloc (sizeof (struct foo_object), "foo"); SCM foo_scm; foo_smob->bar = -1; foo_smob->baz = SCM_BOOL_F; foo_scm = scm_new_smob (foo_smob_tag, (scm_t_bits) foo_smob); return foo_scm; } If the caller stores foo_smob in the heap somewhere, and not foo_scm, is that enough to prevent the object from being garbage collected? Or should the caller be saving foo_scm? e.g. void caller (struct another_struct *s) { SCM foo_scm = make_foo_smob (); #ifdef SAVE_foo_smob struct foo_object *foo_smob = (struct foo_object *) SCM_SMOB_DATA (foo_scm); s->xyz = foo_smob; #endif #ifdef SAVE_foo_scm s->xyz = foo_scm; #endif } IOW, if I use SAVE_foo_smob, will my object get accidentally gc'd? 2) Is it possible to inherit, e.g., with goops, a smob? IOW, can I extend a smob through inheritance? Or must I store the smob in a class, and provide accessors? [kinda like the "is a" vs "has a" relationship] 3) The docs aren't as clear as they could be on whether the "smob" free function needs to scm_gc_free all results of calls to scm_gc_malloc made when constructing the smob. IIUC, this is not necessary. However, why does the image example do this? ref: libguile-smobs.texi: size_t free_image (SCM image_smob) { struct image *image = (struct image *) SCM_SMOB_DATA (image_smob); scm_gc_free (image->pixels, image->width * image->height, "image pixels"); scm_gc_free (image, sizeof (struct image), "image"); <<<<<<<<<<<< return 0; } TIA