* behaviour of scm_run_hook
@ 2005-09-02 20:17 alberj
2005-09-03 14:40 ` Neil Jerram
0 siblings, 1 reply; 6+ messages in thread
From: alberj @ 2005-09-02 20:17 UTC (permalink / raw)
Hi,
I have a problem using scm_run_hook: it throws me a stack overflow each
time I call it on a hook defined in a C program. However, if I access the
hook in scheme and run it using run-hook, it works fine. I am wondering
what I am doing wrong.
Thanks,
J-M
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: behaviour of scm_run_hook
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>
0 siblings, 1 reply; 6+ messages in thread
From: Neil Jerram @ 2005-09-03 14:40 UTC (permalink / raw)
Cc: guile-user
alberj@math.mcmaster.ca writes:
> Hi,
>
> I have a problem using scm_run_hook: it throws me a stack overflow each
> time I call it on a hook defined in a C program. However, if I access the
> hook in scheme and run it using run-hook, it works fine. I am wondering
> what I am doing wrong.
I think we'll need to see your code ...
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: behaviour of scm_run_hook
[not found] ` <63627.24.150.125.164.1125767053.squirrel@www.math.mcmaster.ca>
@ 2005-09-03 19:53 ` Neil Jerram
[not found] ` <60845.24.150.125.164.1125784894.squirrel@www.math.mcmaster.ca>
0 siblings, 1 reply; 6+ messages in thread
From: Neil Jerram @ 2005-09-03 19:53 UTC (permalink / raw)
Cc: Guile Users
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: behaviour of scm_run_hook
[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>
0 siblings, 1 reply; 6+ messages in thread
From: Neil Jerram @ 2005-09-04 9:49 UTC (permalink / raw)
Cc: Guile Users
alberj@math.mcmaster.ca writes:
> Unfortunately, it didn't work. I'm quite sure GC was not the problem, I
> checked using
>
> (add-hook! after-gc-hook (lambda () (display "Garbage
> collection\n")))
You mean that GC was not the problem because a GC never happened?
Fair enough, but you will still need the protection in future, of
course (unless your application is _very_ short lived :-)).
>
> and nothing was displayed.
OK, in that case can you show us the code which you use in C to run
the hook (which you say doesn't work) and the corresponding Scheme
code (which does work).
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: behaviour of scm_run_hook
[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>
0 siblings, 1 reply; 6+ messages in thread
From: Neil Jerram @ 2005-09-04 16:54 UTC (permalink / raw)
Cc: Guile Users
alberj@math.mcmaster.ca writes:
> Certainly. Somehow the e-mail I sent yesterday which had these portions
> of code didn't make it past my computer. So here it is: [...]
I'm sorry but I can't see anything wrong here which might account what
you are seeing. The only other thoughts I have are
- whether your code is calling scm_boot_guile() or scm_init_guile()
correctly
- whether there might be multiple threads involved, with the C
scm_c_run_hook() being on a different thread from the Scheme call
but to be honest these are just vague guesses, and I don't even know
whether getting details wrong in these areas can lead to your symptom.
Otherwise, I think the next step would be to try to use GDB to find
out why the stack overflow occurs. The stack overflow error
originates from scm_report_stack_overflow in libguile, so if you set a
breakpoint on that function, we will at least be able to see the stack
trace at the point of the error, which may help.
Finally, please be sure to CC your subsequent emails to guile-user as
well as to me; you'll probably get a lot more help that way!
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: behaviour of scm_run_hook
[not found] ` <62537.24.150.125.164.1125854774.squirrel@www.math.mcmaster.ca>
@ 2005-09-05 22:14 ` Neil Jerram
0 siblings, 0 replies; 6+ messages in thread
From: Neil Jerram @ 2005-09-05 22:14 UTC (permalink / raw)
Cc: guile-users
alberj@math.mcmaster.ca writes:
> Indeed, scm_c_run_hook() is being called from a separate thread which
> processes all events, I had forgotten about that, but I can see why that
> can be a problem. Is there a way to synchronize the Scheme shell with
> other threads in the program ?
If you're using Guile 1.7, please see section 5.3 of the manual, which
describes how to use scm_with_guile.
If Guile 1.6, I'm afraid I don't know - can anyone else help in this
case?
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-09-05 22:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
[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
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).