From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Thamer Al-Harbash Newsgroups: gmane.lisp.guile.devel Subject: The GC and Guardians Date: Mon, 7 Jul 2003 17:50:47 -0400 (EDT) Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: main.gmane.org 1057615887 16207 80.91.224.249 (7 Jul 2003 22:11:27 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 7 Jul 2003 22:11:27 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jul 08 00:11:25 2003 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 19ZeCj-0004DG-00 for ; Tue, 08 Jul 2003 00:11:25 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19ZeAz-0003tx-6C for guile-devel@m.gmane.org; Mon, 07 Jul 2003 18:09:37 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19Ze9K-0002ff-BN for guile-devel@gnu.org; Mon, 07 Jul 2003 18:07:54 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19Ze7p-0001py-KO for guile-devel@gnu.org; Mon, 07 Jul 2003 18:06:22 -0400 Original-Received: from helena.whitefang.com ([216.254.175.50]) by monty-python.gnu.org with smtp (Exim 4.20) id 19ZdsU-0005FV-FD for guile-devel@gnu.org; Mon, 07 Jul 2003 17:50:30 -0400 Original-Received: (qmail 85914 invoked from network); 7 Jul 2003 21:50:47 -0000 Original-Received: from helena.whitefang.com (216.254.175.50) by 0 with SMTP; 7 Jul 2003 21:50:47 -0000 X-X-Sender: shadows@helena.whitefang.com Original-To: guile-devel@gnu.org X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2599 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2599 I've read through the explanation of how the garbage collector works. I understand that the gc uses the stack as a list of pointers to the heap, and if a two word header is found on the heap via the pointers then the garbage collector assumes that that is a valid non-immediate datum which should not be released. (Well it's a tad more complicated than that -- the gc checks a known heap segment and alignment) This works fine insofar as I always return the SCM data from my C functions, and once I exit the C function which placed the scheme data pointer on the stack, I no longer reference that data anymore. Unfortunately this isn't good enough due to the way a certain program is designed. I used this kludge to get around it, and would like to know if I'm getting myself in trouble: int foo(...) { SCM mysmob; mysmob = create_mysmob(...); scm_define(scm_str2symbol(...), mysmob); return; } My understanding is that since the SMOB bound to the top level environment, the garbage collector should not destroy it since its referenced by the top root. I do later undefine it when I no longer care about it. Also, on an unrelated problem, I want to be able to create a C structure and have it reference non-immediate SCM data, but I cannot turn this C structure into a SMOB. Unfortunately the folks using my code may not be happy dealing with guile directly. Should I use a guardian on the SCM data like so? foo_t *foo_create(void) { foo_t *foo = create_foo(); SCM guardian; foo->mylist = SCM_EOL; guardian = scm_make_guardian(...); scm_apply(....); /* protect foo->mylist with the guardian procedure */ return foo; } I understand that this will work because the guardian can be referenced by the gc from a list of guardians until it is explicitly removed. Should I define a top level guardian and just use it to protect non-immediate SCM data? How are guardians intended to be used from C code when the functions creating them return and no longer reference them. If I'm way off could someone point me to C source code that uses guardians to get around the above problem. -- Thamer Al-Harbash _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel