From: Neil Jerram <neil@ossau.uklinux.net>
Cc: Guile Users <guile-user@gnu.org>
Subject: Re: behaviour of scm_run_hook
Date: Sat, 03 Sep 2005 20:53:31 +0100 [thread overview]
Message-ID: <87k6hyapxg.fsf@ossau.uklinux.net> (raw)
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)")
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
next prev parent reply other threads:[~2005-09-03 19:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-02 20:17 behaviour of scm_run_hook alberj
2005-09-03 14:40 ` Neil Jerram
[not found] ` <63627.24.150.125.164.1125767053.squirrel@www.math.mcmaster.ca>
2005-09-03 19:53 ` Neil Jerram [this message]
[not found] ` <60845.24.150.125.164.1125784894.squirrel@www.math.mcmaster.ca>
2005-09-04 9:49 ` Neil Jerram
[not found] ` <62195.24.150.125.164.1125847306.squirrel@www.math.mcmaster.ca>
2005-09-04 16:54 ` Neil Jerram
[not found] ` <62537.24.150.125.164.1125854774.squirrel@www.math.mcmaster.ca>
2005-09-05 22:14 ` Neil Jerram
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=87k6hyapxg.fsf@ossau.uklinux.net \
--to=neil@ossau.uklinux.net \
--cc=guile-user@gnu.org \
/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).