From 9e48333190cb95ecd4d8a49eed103518457e8ace Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 27 Apr 1998 10:04:11 +0000 Subject: tcltklib/gtk git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/gtk/gtk.c | 40 +++++++++++++++++----------------------- ext/gtk/test2.rb | 4 ++-- ext/tcltklib/tcltklib.c | 21 +++++++++++---------- 3 files changed, 30 insertions(+), 35 deletions(-) (limited to 'ext') diff --git a/ext/gtk/gtk.c b/ext/gtk/gtk.c index b72620de80..41e6874e19 100644 --- a/ext/gtk/gtk.c +++ b/ext/gtk/gtk.c @@ -1105,7 +1105,7 @@ signal_callback(widget, data, nparams, params) { VALUE self = get_value_from_gobject(GTK_OBJECT(widget)); VALUE proc = RARRAY(data)->ptr[0]; - VALUE a = RARRAY(data)->ptr[3]; + VALUE a = RARRAY(data)->ptr[2]; ID id = NUM2INT(RARRAY(data)->ptr[1]); VALUE result = Qnil; VALUE args = ary_new2(nparams+1+RARRAY(a)->len); @@ -1152,7 +1152,7 @@ gobj_smethod_added(self, id) char *name = rb_id2name(NUM2INT(id)); if (gtk_signal_lookup(name, GTK_OBJECT_TYPE(obj))) { - VALUE data = assoc_new(Qnil, id); + VALUE data = ary_new3(3, Qnil, id, ary_new2(0)); add_relative(self, data); gtk_signal_connect_interp(obj, name, @@ -5729,6 +5729,9 @@ static gint idle() { CHECK_INTS; +#ifdef THREAD + if (!thread_critical) thread_schedule(); +#endif return TRUE; } @@ -5740,20 +5743,13 @@ exec_interval(proc) } static VALUE -timeout_add(argc, argv, self) - int argc; - VALUE *argv; - VALUE self; +timeout_add(self, interval) + VALUE self, interval; { - VALUE interval, func; int id; - rb_scan_args(argc, argv, "11", &interval, &func); - if (NIL_P(func)) { - func = f_lambda(); - } id = gtk_timeout_add_interp(NUM2INT(interval), exec_interval, - (gpointer)func, 0); + (gpointer)f_lambda(), 0); return INT2FIX(id); } @@ -5766,19 +5762,12 @@ timeout_remove(self, id) } static VALUE -idle_add(argc, argv, self) - int argc; - VALUE *argv; +idle_add(self) VALUE self; { - VALUE func; int id; - rb_scan_args(argc, argv, "01", &func); - if (NIL_P(func)) { - func = f_lambda(); - } - id = gtk_idle_add_interp(exec_interval, (gpointer)func, 0); + id = gtk_idle_add_interp(exec_interval, (gpointer)f_lambda(), 0); return INT2FIX(id); } @@ -6624,9 +6613,9 @@ Init_gtk() /* Gtk module */ rb_define_module_function(mGtk, "main", gtk_m_main, 0); - rb_define_module_function(mGtk, "timeout_add", timeout_add, -1); + rb_define_module_function(mGtk, "timeout_add", timeout_add, 1); rb_define_module_function(mGtk, "timeout_remove", timeout_remove, 1); - rb_define_module_function(mGtk, "idle_add", idle_add, -1); + rb_define_module_function(mGtk, "idle_add", idle_add, 0); rb_define_module_function(mGtk, "idle_remove", idle_remove, 1); rb_define_module_function(mGtk, "set_warning_handler", @@ -6839,7 +6828,12 @@ Init_gtk() id_call = rb_intern("call"); id_gtkdata = rb_intern("gtkdata"); id_relatives = rb_intern("relatives"); +#if 0 gtk_idle_add((GtkFunction)idle, 0); +#else + /* use timeout to avoid busy wait */ + gtk_timeout_add(1, (GtkFunction)idle, 0); +#endif g_set_error_handler(gtkerr); g_set_warning_handler(gtkerr); diff --git a/ext/gtk/test2.rb b/ext/gtk/test2.rb index 170de96185..33215b7f7a 100644 --- a/ext/gtk/test2.rb +++ b/ext/gtk/test2.rb @@ -58,8 +58,8 @@ button.set_flags(Gtk::CAN_FOCUS); button.signal_connect("clicked") do tmp_list = list.selection list.remove_items(tmp_list) - for i in tmp_list - i.destroy + for w in tmp_list + w.destroy end end box2.pack_start(button, FALSE, TRUE, 0) diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index b63b1d06dd..6cb017a398 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -37,12 +37,12 @@ int *tclDummyMathPtr = (int *) matherr; typedef struct { Tcl_TimerToken token; int flag; -} Tk_ThreadTimerData; +} Tk_TimerData; /* timer callback */ -void _timer_for_thread (ClientData clientData) +void _timer_for_tcl (ClientData clientData) { - Tk_ThreadTimerData *timer = (Tk_ThreadTimerData *) clientData; + Tk_TimerData *timer = (Tk_TimerData*)clientData; timer->flag = 0; CHECK_INTS; @@ -50,8 +50,8 @@ void _timer_for_thread (ClientData clientData) if (!thread_critical) thread_schedule(); #endif - timer->token = Tk_CreateTimerHandler(200, _timer_for_thread, - (ClientData) timer); + timer->token = Tk_CreateTimerHandler(200, _timer_for_tcl, + (ClientData)timer); timer->flag = 1; } @@ -59,12 +59,12 @@ void _timer_for_thread (ClientData clientData) static VALUE lib_mainloop(VALUE self) { - Tk_ThreadTimerData *timer; + Tk_TimerData *timer; - timer = (Tk_ThreadTimerData *) ckalloc(sizeof(Tk_ThreadTimerData)); + timer = (Tk_TimerData *) ckalloc(sizeof(Tk_TimerData)); timer->flag = 0; - timer->token = Tk_CreateTimerHandler(200, _timer_for_thread, - (ClientData) timer); + timer->token = Tk_CreateTimerHandler(200, _timer_for_tcl, + (ClientData)timer); timer->flag = 1; DUMP1("start Tk_Mainloop"); @@ -219,7 +219,7 @@ ip_invoke(int argc, VALUE *argv, VALUE obj) av = (char **)ALLOCA_N(char **, argc+1); for (i = 0; i < argc; ++i) { - char *s = CTR2CSTR(argv[i]); + char *s = STR2CSTR(argv[i]); av[i] = ALLOCA_N(char, strlen(s)+1); strcpy(av[i], s); @@ -230,6 +230,7 @@ ip_invoke(int argc, VALUE *argv, VALUE obj) NameError("invalid command name `%s'", av[0]); } + Tcl_ResetResult(ptr->ip); ptr->return_value = (*info.proc)(info.clientData, ptr->ip, argc, av); if (ptr->return_value == TCL_ERROR) { -- cgit v1.2.3