From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: behaviour of scm_run_hook Date: Sat, 03 Sep 2005 20:53:31 +0100 Message-ID: <87k6hyapxg.fsf@ossau.uklinux.net> References: <60073.24.150.125.164.1125692241.squirrel@www.math.mcmaster.ca> <87oe7ab4f2.fsf@ossau.uklinux.net> <63627.24.150.125.164.1125767053.squirrel@www.math.mcmaster.ca> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1125777345 16554 80.91.229.2 (3 Sep 2005 19:55:45 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 3 Sep 2005 19:55:45 +0000 (UTC) Cc: Guile Users Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Sep 03 21:55:43 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EBe6B-0005sh-Q2 for guile-user@m.gmane.org; Sat, 03 Sep 2005 21:54:48 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EBeAX-0005eT-DT for guile-user@m.gmane.org; Sat, 03 Sep 2005 15:59:17 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EBeAP-0005dV-3C for guile-user@gnu.org; Sat, 03 Sep 2005 15:59:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EBeAK-0005au-6Q for guile-user@gnu.org; Sat, 03 Sep 2005 15:59:05 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EBeAJ-0005aX-RY for guile-user@gnu.org; Sat, 03 Sep 2005 15:59:03 -0400 Original-Received: from [80.84.72.33] (helo=mail3.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EBe8Q-0004TU-SF for guile-user@gnu.org; Sat, 03 Sep 2005 15:57:07 -0400 Original-Received: from laruns (host81-130-141-16.in-addr.btopenworld.com [81.130.141.16]) by mail3.uklinux.net (Postfix) with ESMTP id 40E98409FA9; Sat, 3 Sep 2005 19:53:37 +0000 (UTC) Original-Received: from laruns (laruns [127.0.0.1]) by laruns (Postfix) with ESMTP id 484356F71B; Sat, 3 Sep 2005 20:53:31 +0100 (BST) Original-To: alberj@math.mcmaster.ca In-Reply-To: <63627.24.150.125.164.1125767053.squirrel@www.math.mcmaster.ca> (alberj@math.mcmaster.ca's message of "Sat, 3 Sep 2005 13:04:13 -0400 (EDT)") User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:4712 Archived-At: alberj@math.mcmaster.ca writes: > ok, the code is quite long, so I'll try to isolate the parts that use > scheme hooks. Thanks. > Here is the definition of the structure which houses a > hook: > > typedef struct _menu_item_s > { > menu_item_type_t type; > char* title; > char* name; > int mouse_state; > int item_width; > SDL_Surface* icon;// > void (*action)(menu_t* menu, struct _menu_item_s* item); > SCM guile_action_hook; > menu_t* sub_menu; > }menu_item_t; > > and it is initialized with this function : > > menu_item_t* new_menu_item(const char* title, const char* name) > { > menu_item_t* new_item; > static unsigned int item_number = 0; > char default_name[16]; > > new_item = (menu_item_t*)malloc(sizeof(menu_item_t)); > > new_item->type = MENU_ITEM; > new_item->mouse_state = MOUSE_OUT; > new_item->icon = NULL; > > if(name == NULL) > { > sprintf(default_name,"item%u", item_number++); > new_item->name = strdup(default_name); > } > else > { > new_item->name = strdup(name); > } > > ////XXX > new_item->guile_action_hook = scm_make_hook(SCM_MAKINUM(0));//SCM_BOOL_F; > > new_item->sub_menu = NULL; > new_item->title = title ? strdup(title) : NULL; > > return new_item; > } I wonder if the problem is that the hook is being GC'd? There's nothing in this code that would protect the hook from that. All you need to do to fix this is call scm_gc_protect_object(new_item->guile_action_hook) when allocating the menu item (after the scm_make_hook line), and scm_gc_unprotect_object(menu_item->guile_action_hook) when freeing menu_item. Please let us know if this fixes the problem. Neil _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user