Hi,

At Tue, 14 May 2002 22:37:03 +0900,
ts wrote:
> m> +    *px = NUM2INT(rb_ary_entry(arr, 0));
> m> +    *py = NUM2INT(rb_ary_entry(arr, 1));
> 
> 
>   best to write it, in your case
> 
>        *px = NUM2INT(RARRAY(arr)->ptr[0]);
>        *py = NUM2INT(RARRAY(arr)->ptr[1]);
> 
>  NUM2INT() is a macro and you can call many times rb_ary_entry()

To use RARRAY(arr)->ptr, you need check RARRAY(arr)->len.  And
the method id to rb_funcall() was missing.


Index: rbgtkmenu.c =================================================================== RCS file: /cvsroot/ruby-gnome/ruby-gnome/gtk/src/rbgtkmenu.c,v retrieving revision 1.2 diff -u -2 -p -r1.2 rbgtkmenu.c --- rbgtkmenu.c 14 Dec 2001 23:45:45 -0000 1.2 +++ rbgtkmenu.c 15 May 2002 02:48:39 -0000 @@ -14,4 +14,6 @@ #include "global.h" +static ID call; + static VALUE menu_initialize(self) @@ -48,12 +50,19 @@ menu_insert(self, child, pos) static void -menu_pos_func(menu, x, y, data) +menu_pos_func(menu, px, py, data) GtkMenu *menu; - gint x, y; + gint *px, *py; gpointer data; { + VALUE arr; VALUE m = get_value_from_gobject(GTK_OBJECT(menu)); - rb_funcall((VALUE)data, 3, m, INT2FIX(x), INT2FIX(y)); + arr = rb_funcall((VALUE)data, call, 3, m, INT2FIX(*px), INT2FIX(*py)); + Check_Type(arr, T_ARRAY); + if (RARRAY(arr)->len != 2) { + rb_raise(rb_eTypeError, "wrong number of result (%d for 2)", RARRAY(arr)->len); + } + *px = NUM2INT(RARRAY(arr)->ptr[0]); + *py = NUM2INT(RARRAY(arr)->ptr[1]); } @@ -125,3 +134,5 @@ void Init_gtk_menu() rb_define_method(gMenu, "get_active", menu_get_active, 0); rb_define_method(gMenu, "set_active", menu_set_active, 1); + + call = rb_intern("call"); }
-- Nobu Nakada