なかだです。

ext/tkでは条件コンパイルのためにRUBY_VMというマクロを多用してい
ますが、無関係の判定に流用するのはあまりよろしくないと思います。

stable/が1.8、trunk/が1.9用です。


Index: stable/ext/tk/stubs.c =================================================================== --- stable/ext/tk/stubs.c (revision 17089) +++ stable/ext/tk/stubs.c (working copy) @@ -93,5 +93,5 @@ static DL_HANDLE tk_dll = (DL_HANDLE)0; int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcl_dll(char *appname) #else @@ -180,5 +180,5 @@ ruby_open_tk_dll() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcltk_dll(char *appname) #else @@ -204,5 +204,5 @@ tk_stubs_init_p() Tcl_Interp * -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tcl_create_ip_and_stubs_init(int *st) #else @@ -291,5 +291,5 @@ ruby_tcl_stubs_init() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_init(Tcl_Interp *tcl_ip) #else @@ -331,5 +331,5 @@ ruby_tk_stubs_init(tcl_ip) int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip) #else @@ -422,5 +422,5 @@ static int call_tk_stubs_init = 0; int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcl_dll(char *appname) #else @@ -451,5 +451,5 @@ ruby_open_tk_dll() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcltk_dll(char *appname) #else @@ -474,5 +474,5 @@ tk_stubs_init_p() Tcl_Interp * -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tcl_create_ip_and_stubs_init(int *st) #else @@ -507,5 +507,5 @@ ruby_tcl_stubs_init() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_init(Tcl_Interp *tcl_ip) #else @@ -528,5 +528,5 @@ ruby_tk_stubs_init(tcl_ip) int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip) #else Index: stable/ext/tk/tcltklib.c =================================================================== --- stable/ext/tk/tcltklib.c (revision 17089) +++ stable/ext/tk/tcltklib.c (working copy) @@ -9,8 +9,10 @@ #include "ruby.h" -#ifdef RUBY_VM +#ifdef HAVE_RUBY_RUBY_H /* #include "ruby/ruby.h" */ #include "ruby/signal.h" +#ifdef HAVE_RUBY_ENCODING_H #include "ruby/encoding.h" +#endif #else /* #include "ruby.h" */ @@ -32,4 +34,17 @@ #include <tk.h> +#ifndef HAVE_RUBY_NATIVE_THREAD_P +#define ruby_native_thread_p() is_ruby_native_thread() +#undef RUBY_USE_NATIVE_THREAD +#else +#define RUBY_USE_NATIVE_THREAD 1 +#endif +#ifndef HAVE_RB_ERRINFO +#define rb_errinfo() (ruby_errinfo+0) /* cannot be l-value */ +#endif +#ifndef HAVE_RB_SAFE_LEVEL +#define rb_safe_level() (ruby_safe_level+0) /* cannot be l-value */ +#endif + #include "stubs.h" @@ -111,5 +126,5 @@ static void ip_finalize _((Tcl_Interp*)) static int at_exit = 0; -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H static VALUE cRubyEncoding; @@ -196,5 +211,5 @@ static Tcl_ObjType *Tcl_ObjType_String; /* safe Tcl_Eval and Tcl_GlobalEval */ static int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES tcl_eval(Tcl_Interp *interp, const char *cmd) #else @@ -217,5 +232,5 @@ tcl_eval(interp, cmd) static int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES tcl_global_eval(Tcl_Interp *interp, const char *cmd) #else @@ -394,5 +409,5 @@ call_queue_mark(struct call_queue *q) static VALUE eventloop_thread; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD Tcl_ThreadId tk_eventloop_thread_id; /* native thread ID of Tcl interpreter */ #endif @@ -425,5 +440,5 @@ static int have_rb_thread_waiting_for_va * If 'timer_tick' == 0, then not use the timer for thread scheduling. */ -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD #define DEFAULT_EVENT_LOOP_MAX 800/*counts*/ #define DEFAULT_NO_EVENT_TICK 10/*counts*/ @@ -432,5 +447,5 @@ static int have_rb_thread_waiting_for_va #define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */ #define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 999 ) */ -#else /* ! RUBY_VM */ +#else /* ! RUBY_USE_NATIVE_THREAD */ #define DEFAULT_EVENT_LOOP_MAX 800/*counts*/ #define DEFAULT_NO_EVENT_TICK 10/*counts*/ @@ -674,5 +689,5 @@ struct tcltkip { Tcl_Namespace *default_ns; /* default namespace */ #endif -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD Tcl_ThreadId tk_thread_id; /* native thread ID of Tcl interpreter */ #endif @@ -867,5 +882,5 @@ tcltkip_init_tk(interp) #endif -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr->tk_thread_id = Tcl_GetCurrentThread(); #endif @@ -1139,5 +1154,5 @@ _timer_for_tcl(clientData) } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD #if USE_TOGGLE_WINDOW_MODE_FOR_IDLE static int @@ -1482,5 +1497,5 @@ lib_num_of_mainwindows(self) VALUE self; { -#ifdef RUBY_VM /* Ruby 1.9+ !!! */ +#ifdef RUBY_USE_NATIVE_THREAD /* Ruby 1.9+ !!! */ return tk_funcall(lib_num_of_mainwindows_core, 0, (VALUE*)NULL, self); #else @@ -1490,5 +1505,5 @@ lib_num_of_mainwindows(self) -#ifdef RUBY_VM /* Ruby 1.9+ !!! */ +#ifdef RUBY_USE_NATIVE_THREAD /* Ruby 1.9+ !!! */ static VALUE call_DoOneEvent_core(flag_val) @@ -1539,15 +1554,9 @@ eventloop_sleep(dummy) #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on eventloop_sleep()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on eventloop_sleep()"); - } -#endif #endif @@ -1557,15 +1566,9 @@ eventloop_sleep(dummy) #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on eventloop_sleep()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on eventloop_sleep()"); - } -#endif #endif @@ -1579,5 +1582,5 @@ static int get_thread_alone_check_flag() { -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD return 0; #else @@ -1691,17 +1694,9 @@ lib_eventloop_core(check_root, update_fl switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif if (!NIL_P(rbtk_pending_exception)) { @@ -1718,16 +1713,8 @@ lib_eventloop_core(check_root, update_fl case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); } else { -#ifdef RUBY_VM rb_exc_raise(rb_errinfo()); -#else - rb_exc_raise(ruby_errinfo); -#endif } } @@ -1820,5 +1807,5 @@ lib_eventloop_core(check_root, update_fl int st; int status; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (update_flag) { st = RTEST(rb_protect(call_DoOneEvent, @@ -1856,18 +1843,10 @@ lib_eventloop_core(check_root, update_fl switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif if (!NIL_P(rbtk_pending_exception)) { @@ -1884,16 +1863,8 @@ lib_eventloop_core(check_root, update_fl case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); } else { -#ifdef RUBY_VM rb_exc_raise(rb_errinfo()); -#else - rb_exc_raise(ruby_errinfo); -#endif } } @@ -1945,18 +1916,10 @@ lib_eventloop_core(check_root, update_fl switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif if (!NIL_P(rbtk_pending_exception)) { @@ -1973,17 +1936,9 @@ lib_eventloop_core(check_root, update_fl case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); } else { -#ifdef RUBY_VM rb_exc_raise(rb_errinfo()); -#else - rb_exc_raise(ruby_errinfo); -#endif } } @@ -2046,5 +2001,5 @@ lib_eventloop_core(check_root, update_fl DUMP1("trap check & thread scheduling"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD /* if (update_flag == 0) CHECK_INTS; */ /*XXXXXXXXXXXXX TODO !!!! */ #else @@ -2097,33 +2052,17 @@ lib_eventloop_main(args) switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } return Qnil; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } return Qnil; @@ -2180,5 +2119,5 @@ lib_eventloop_ensure(args) } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (NIL_P(eventloop_thread)) { tk_eventloop_thread_id = (Tcl_ThreadId) 0; @@ -2209,5 +2148,5 @@ lib_eventloop_launcher(check_root, updat eventloop_thread = rb_thread_current(); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD tk_eventloop_thread_id = Tcl_GetCurrentThread(); #endif @@ -2362,5 +2301,5 @@ lib_watchdog_ensure(arg) { eventloop_thread = Qnil; /* stop eventloops */ -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD tk_eventloop_thread_id = (Tcl_ThreadId) 0; #endif @@ -2376,5 +2315,5 @@ lib_mainloop_watchdog(argc, argv, self) VALUE check_rootwidget; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD rb_raise(rb_eNotImpError, "eventloop_watchdog is not implemented on Ruby VM."); @@ -2504,15 +2443,8 @@ lib_thread_callback(argc, argv, self) if (NIL_P(rbtk_pending_exception)) { -#ifdef RUBY_VM /* return rb_errinfo(); */ if (status) { rb_exc_raise(rb_errinfo()); } -#else - /* return ruby_errinfo; */ - if (status) { - rb_exc_raise(ruby_errinfo); - } -#endif } else { VALUE exc = rbtk_pending_exception; @@ -2729,92 +2661,48 @@ tcl_protect_core(interp, proc, data) /* error: str = rb_str_new2("LocalJumpError: "); -#ifdef RUBY_VM rb_str_append(str, rb_obj_as_string(rb_errinfo())); -#else - rb_str_append(str, rb_obj_as_string(ruby_errinfo)); -#endif exc = rb_exc_new3(type, str); break; case TAG_RETRY: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif DUMP1("rb_protect: retry"); exc = rb_exc_new2(eTkCallbackRetry, "retry jump error"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_REDO: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif DUMP1("rb_protect: redo"); exc = rb_exc_new2(eTkCallbackRedo, "redo jump error"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif exc = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif exc = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_THROW: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif DUMP1("rb_protect: throw"); exc = rb_exc_new2(eTkCallbackThrow, "throw jump error"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; @@ -2924,15 +2812,9 @@ tcl_protect(interp, proc, data) #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on tcl_protect()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on tcl_protect()"); - } -#endif #endif @@ -3214,6 +3096,5 @@ ip_ruby_cmd(clientData, interp, argc, ar /* get args */ args = rb_ary_new2(argc - 2); -#ifdef RUBY_VM -#else +#ifdef HAVE_STRUCT_RARRAY_LEN RARRAY(args)->len = 0; #endif @@ -3222,5 +3103,5 @@ ip_ruby_cmd(clientData, interp, argc, ar str = Tcl_GetStringFromObj(argv[i], &len); DUMP2("arg:%s",str); -#ifdef RUBY_VM +#ifndef HAVE_STRUCT_RARRAY_LEN rb_ary_push(args, rb_tainted_str_new(str, len)); #else @@ -3229,5 +3110,5 @@ ip_ruby_cmd(clientData, interp, argc, ar #else /* TCL_MAJOR_VERSION < 8 */ DUMP2("arg:%s",argv[i]); -#ifdef RUBY_VM +#ifndef HAVE_STRUCT_RARRAY_LEN rb_ary_push(args, rb_tainted_str_new2(argv[i])); #else @@ -3430,15 +3311,9 @@ ip_rbUpdateCommand(clientData, interp, o } #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on ip_ruby_eval()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on ip_ruby_eval()"); - } -#endif #endif @@ -3587,15 +3462,9 @@ ip_rb_threadUpdateCommand(clientData, in } #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()"); - } -#endif #endif @@ -3786,15 +3655,9 @@ ip_rbVwaitCommand(clientData, interp, ob Tcl_Preserve(interp); #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on ip_rbVwaitCommand()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on ip_rbVwaitCommand()"); - } -#endif #endif @@ -5545,17 +5408,8 @@ ip_init(argc, argv, self) /* security check */ -#ifdef RUBY_VM if (rb_safe_level() >= 4) { -#else - if (ruby_safe_level >= 4) { -#endif rb_raise(rb_eSecurityError, "Cannot create a TclTkIp object at level %d", -#ifdef RUBY_VM - rb_safe_level() -#else - ruby_safe_level -#endif - ); + rb_safe_level()); } @@ -5565,5 +5419,5 @@ ip_init(argc, argv, self) /* ptr = (struct tcltkip *)ckalloc(sizeof(struct tcltkip)); */ DATA_PTR(self) = ptr; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr->tk_thread_id = 0; #endif @@ -5675,5 +5529,5 @@ ip_init(argc, argv, self) #endif -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD /* set Tk thread ID */ ptr->tk_thread_id = Tcl_GetCurrentThread(); @@ -5797,5 +5651,5 @@ ip_create_slave_core(interp, argc, argv) /* create slave-ip */ -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD /* slave->tk_thread_id = 0; */ slave->tk_thread_id = master->tk_thread_id; /* == current thread */ @@ -6254,5 +6108,5 @@ get_str_from_obj(obj) str = s ? rb_str_new(s, len) : rb_str_new2(""); if (binary) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -6260,5 +6114,5 @@ get_str_from_obj(obj) #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) } else { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_UTF8); #endif @@ -6289,5 +6143,5 @@ get_obj_from_str(str) return Tcl_NewStringObj(s, RSTRING_LEN(str)); } -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) { /* binary string */ @@ -6459,5 +6313,5 @@ tk_funcall(func, argc, argv, obj) } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr) { /* on Tcl interpreter */ @@ -6535,5 +6389,5 @@ tk_funcall(func, argc, argv, obj) /* add the handler to Tcl event queue */ DUMP1("add handler"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr && ptr->tk_thread_id) { /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, @@ -6682,33 +6536,17 @@ ip_eval_real(self, cmd_str, cmd_len) switch(status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } break; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } } @@ -6846,15 +6684,9 @@ eval_queue_handler(evPtr, flags) if (rb_safe_level() != q->safe_level) { #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on eval_queue_handler()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on eval_queue_handler()"); - } -#endif #endif /* q_dat = Data_Wrap_Struct(rb_cData,0,-1,q); */ @@ -6913,5 +6745,5 @@ ip_eval(self, str) { struct eval_queue *evq; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD struct tcltkip *ptr; #endif @@ -6930,10 +6762,10 @@ ip_eval(self, str) rb_thread_critical = thr_crit_bup; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr = get_ip(ip_obj); #endif if ( -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread()) && @@ -6998,5 +6830,5 @@ ip_eval(self, str) /* add the handler to Tcl event queue */ DUMP1("add handler"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr->tk_thread_id) { /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(evq->ev), position); */ @@ -7220,5 +7052,5 @@ lib_toUTF8_core(ip_obj, src, encodename) volatile VALUE enc; -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H enc = rb_funcall(rb_obj_encoding(str), ID_to_s, 0, 0); #else @@ -7250,5 +7082,5 @@ lib_toUTF8_core(ip_obj, src, encodename) StringValue(enc); if (strcmp(RSTRING_PTR(enc), "binary") == 0) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7270,5 +7102,5 @@ lib_toUTF8_core(ip_obj, src, encodename) StringValue(encodename); if (strcmp(RSTRING_PTR(encodename), "binary") == 0) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7307,5 +7139,5 @@ lib_toUTF8_core(ip_obj, src, encodename) /* str = rb_str_new2(Tcl_DStringValue(&dstr)); */ str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr)); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_UTF8); #endif @@ -7400,5 +7232,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam StringValue(enc); if (strcmp(RSTRING_PTR(enc), "binary") == 0) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7407,5 +7239,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam return str; } -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) { rb_enc_associate_index(str, ENCODING_INDEX_BINARY); @@ -7456,5 +7288,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam s = (char*)NULL; Tcl_DecrRefCount(tclstr); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7498,5 +7330,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam /* str = rb_str_new2(Tcl_DStringValue(&dstr)); */ str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr)); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H if (interp) { /* can access encoding_table of TclTkIp */ @@ -7607,5 +7439,5 @@ lib_UTF_backslash_core(self, str, all_bs str = rb_str_new(dst_buf, dst_len); if (taint_flag) OBJ_TAINT(str); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_UTF8); #endif @@ -7912,33 +7744,17 @@ ip_invoke_core(interp, argc, argv) switch(status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } break; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } } @@ -8311,5 +8127,5 @@ ip_invoke_with_position(argc, argv, obj, { struct invoke_queue *ivq; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD struct tcltkip *ptr; #endif @@ -8331,5 +8147,5 @@ ip_invoke_with_position(argc, argv, obj, } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr = get_ip(ip_obj); DUMP2("status: ptr->tk_thread_id %d", ptr->tk_thread_id); @@ -8339,5 +8155,5 @@ ip_invoke_with_position(argc, argv, obj, if ( -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread()) && @@ -8395,5 +8211,5 @@ ip_invoke_with_position(argc, argv, obj, /* add the handler to Tcl event queue */ DUMP1("add handler"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr->tk_thread_id) { /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(ivq->ev), position); */ @@ -8921,5 +8737,5 @@ lib_split_tklist_core(ip_obj, list_str) int idx; int taint_flag = OBJ_TAINTED(list_str); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H int list_enc_idx; volatile VALUE list_ivar_enc; @@ -8939,5 +8755,5 @@ lib_split_tklist_core(ip_obj, list_str) StringValue(list_str); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H list_enc_idx = rb_enc_get_index(list_str); list_ivar_enc = rb_ivar_get(list_str, ID_at_enc); @@ -8981,5 +8797,5 @@ lib_split_tklist_core(ip_obj, list_str) for(idx = 0; idx < objc; idx++) { elem = get_str_from_obj(objv[idx]); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H if (rb_enc_get_index(elem) == ENCODING_INDEX_BINARY) { rb_enc_associate_index(elem, ENCODING_INDEX_BINARY); @@ -9314,5 +9130,5 @@ create_dummy_encoding_for_tk_core(interp #endif -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H if (RTEST(rb_define_dummy_encoding(RSTRING_PTR(name)))) { int idx = rb_enc_find_index(StringValueCStr(name)); @@ -9339,5 +9155,5 @@ create_dummy_encoding_for_tk(interp, nam -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H static int update_encoding_table(table, interp, error_mode) @@ -9513,5 +9329,5 @@ encoding_table_get_obj_core(table, enc, } -#else /* ! RUBY_VM */ +#else /* ! HAVE_RUBY_ENCODING_H */ #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) static int @@ -9640,5 +9456,5 @@ encoding_table_get_obj(table, enc) } -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H static VALUE create_encoding_table(interp) @@ -9730,5 +9546,5 @@ create_encoding_table(interp) } -#else /* ! RUBY_VM */ +#else /* ! HAVE_RUBY_ENCODING_H */ #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) static VALUE @@ -9963,7 +9779,7 @@ Init_tcltklib() /* --------------------------------------------------------------- */ -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_global_variable(&cRubyEncoding); - cRubyEncoding = rb_const_get(rb_cObject, rb_intern("Encoding")); + cRubyEncoding = rb_path2class("Encoding"); ENCODING_INDEX_UTF8 = rb_enc_to_index(rb_utf8_encoding()); @@ -10221,9 +10037,5 @@ Init_tcltklib() /* if ruby->nativethread-supprt and tcltklib->doen't, the following will cause link-error. */ -#ifdef RUBY_VM ruby_native_thread_p(); -#else - is_ruby_native_thread(); -#endif /* --------------------------------------------------------------- */ Index: stable/ext/tk/extconf.rb =================================================================== --- stable/ext/tk/extconf.rb (revision 17089) +++ stable/ext/tk/extconf.rb (working copy) @@ -3,8 +3,15 @@ require 'mkmf' -#is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM) is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM) #is_macosx = (/darwin/ =~ RUBY_PLATFORM) +have_header("ruby/ruby.h") +have_header("ruby/encoding.h") +have_func("ruby_native_thread_p", "ruby.h") +have_func("rb_errinfo", "ruby.h") +have_func("rb_safe_level", "ruby.h") +have_struct_member("struct RArray", "ptr", "ruby.h") +have_struct_member("struct RArray", "len", "ruby.h") + def find_framework(tcl_hdr, tk_hdr) if framework_dir = with_config("tcltk-framework") Index: stable/ext/tk/tkutil/extconf.rb =================================================================== --- stable/ext/tk/tkutil/extconf.rb (revision 17089) +++ stable/ext/tk/tkutil/extconf.rb (working copy) @@ -8,5 +8,7 @@ end if has_tk require 'mkmf' + have_header("ruby/ruby.h") have_func("rb_obj_instance_exec", "ruby.h") + have_func("rb_sym_to_s", "ruby.h") have_func("strndup", "string.h") create_makefile('tkutil') Index: stable/ext/tk/tkutil/tkutil.c =================================================================== --- stable/ext/tk/tkutil/tkutil.c (revision 17089) +++ stable/ext/tk/tkutil/tkutil.c (working copy) @@ -12,5 +12,5 @@ #include "ruby.h" -#ifdef RUBY_VM /* Ruby 1.9 */ +#ifdef HAVE_RUBY_RUBY_H /* #include "ruby/ruby.h" */ #include "ruby/signal.h" @@ -118,6 +118,6 @@ tk_do_callback(argc, argv, self) } -static char *cmd_id_head = "ruby_cmd TkUtil callback "; -static char *cmd_id_prefix = "cmd"; +static const char cmd_id_head[] = "ruby_cmd TkUtil callback "; +static const char cmd_id_prefix[] = "cmd"; static VALUE @@ -792,5 +792,5 @@ get_eval_string_core(obj, enc_flag, self } } else { -#ifdef RUBY_VM +#ifdef HAVE_RB_SYM_TO_S return rb_sym_to_s(obj); #else
Index: trunk/ext/tk/stubs.c =================================================================== --- trunk/ext/tk/stubs.c (revision 17089) +++ trunk/ext/tk/stubs.c (working copy) @@ -93,5 +93,5 @@ static DL_HANDLE tk_dll = (DL_HANDLE)0; int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcl_dll(char *appname) #else @@ -180,5 +180,5 @@ ruby_open_tk_dll() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcltk_dll(char *appname) #else @@ -204,5 +204,5 @@ tk_stubs_init_p() Tcl_Interp * -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tcl_create_ip_and_stubs_init(int *st) #else @@ -291,5 +291,5 @@ ruby_tcl_stubs_init() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_init(Tcl_Interp *tcl_ip) #else @@ -331,5 +331,5 @@ ruby_tk_stubs_init(tcl_ip) int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip) #else @@ -422,5 +422,5 @@ static int call_tk_stubs_init = 0; int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcl_dll(char *appname) #else @@ -451,5 +451,5 @@ ruby_open_tk_dll() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_open_tcltk_dll(char *appname) #else @@ -474,5 +474,5 @@ tk_stubs_init_p() Tcl_Interp * -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tcl_create_ip_and_stubs_init(int *st) #else @@ -507,5 +507,5 @@ ruby_tcl_stubs_init() int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_init(Tcl_Interp *tcl_ip) #else @@ -528,5 +528,5 @@ ruby_tk_stubs_init(tcl_ip) int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip) #else Index: trunk/ext/tk/tcltklib.c =================================================================== --- trunk/ext/tk/tcltklib.c (revision 17089) +++ trunk/ext/tk/tcltklib.c (working copy) @@ -9,8 +9,10 @@ #include "ruby.h" -#ifdef RUBY_VM +#ifdef HAVE_RUBY_RUBY_H /* #include "ruby/ruby.h" */ #include "ruby/signal.h" +#ifdef HAVE_RUBY_ENCODING_H #include "ruby/encoding.h" +#endif #else /* #include "ruby.h" */ @@ -32,4 +34,17 @@ #include <tk.h> +#ifndef HAVE_RUBY_NATIVE_THREAD_P +#define ruby_native_thread_p() is_ruby_native_thread() +#undef RUBY_USE_NATIVE_THREAD +#else +#define RUBY_USE_NATIVE_THREAD 1 +#endif +#ifndef HAVE_RB_ERRINFO +#define rb_errinfo() (ruby_errinfo+0) /* cannot be l-value */ +#endif +#ifndef HAVE_RB_SAFE_LEVEL +#define rb_safe_level() (ruby_safe_level+0) /* cannot be l-value */ +#endif + #include "stubs.h" @@ -102,5 +117,5 @@ fprintf(stderr, ARG1, ARG2, ARG3); fprin /* release date */ -const char tcltklib_release_date[] = TCLTKLIB_RELEASE_DATE; +const const char tcltklib_release_date[] = TCLTKLIB_RELEASE_DATE; /* finalize_proc_name */ @@ -111,5 +126,5 @@ static void ip_finalize _((Tcl_Interp*)) static int at_exit = 0; -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H static VALUE cRubyEncoding; @@ -196,5 +211,5 @@ static Tcl_ObjType *Tcl_ObjType_String; /* safe Tcl_Eval and Tcl_GlobalEval */ static int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES tcl_eval(Tcl_Interp *interp, const char *cmd) #else @@ -217,5 +232,5 @@ tcl_eval(interp, cmd) static int -#ifdef RUBY_VM +#ifdef HAVE_PROTOTYPES tcl_global_eval(Tcl_Interp *interp, const char *cmd) #else @@ -394,5 +409,5 @@ call_queue_mark(struct call_queue *q) static VALUE eventloop_thread; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD Tcl_ThreadId tk_eventloop_thread_id; /* native thread ID of Tcl interpreter */ #endif @@ -425,5 +440,5 @@ static int have_rb_thread_waiting_for_va * If 'timer_tick' == 0, then not use the timer for thread scheduling. */ -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD #define DEFAULT_EVENT_LOOP_MAX 800/*counts*/ #define DEFAULT_NO_EVENT_TICK 10/*counts*/ @@ -432,5 +447,5 @@ static int have_rb_thread_waiting_for_va #define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */ #define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 999 ) */ -#else /* ! RUBY_VM */ +#else /* ! RUBY_USE_NATIVE_THREAD */ #define DEFAULT_EVENT_LOOP_MAX 800/*counts*/ #define DEFAULT_NO_EVENT_TICK 10/*counts*/ @@ -674,5 +689,5 @@ struct tcltkip { Tcl_Namespace *default_ns; /* default namespace */ #endif -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD Tcl_ThreadId tk_thread_id; /* native thread ID of Tcl interpreter */ #endif @@ -867,5 +882,5 @@ tcltkip_init_tk(interp) #endif -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr->tk_thread_id = Tcl_GetCurrentThread(); #endif @@ -1139,5 +1154,5 @@ _timer_for_tcl(clientData) } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD #if USE_TOGGLE_WINDOW_MODE_FOR_IDLE static int @@ -1490,5 +1505,5 @@ lib_num_of_mainwindows(self) -#ifdef RUBY_VM /* Ruby 1.9+ !!! */ +#ifdef RUBY_USE_NATIVE_THREAD /* Ruby 1.9+ !!! */ static VALUE call_DoOneEvent_core(flag_val) @@ -1539,15 +1554,9 @@ eventloop_sleep(dummy) #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on eventloop_sleep()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on eventloop_sleep()"); - } -#endif #endif @@ -1557,15 +1566,9 @@ eventloop_sleep(dummy) #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on eventloop_sleep()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on eventloop_sleep()"); - } -#endif #endif @@ -1579,5 +1582,5 @@ static int get_thread_alone_check_flag() { -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD return 0; #else @@ -1691,17 +1694,9 @@ lib_eventloop_core(check_root, update_fl switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif if (!NIL_P(rbtk_pending_exception)) { @@ -1718,16 +1713,8 @@ lib_eventloop_core(check_root, update_fl case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); } else { -#ifdef RUBY_VM rb_exc_raise(rb_errinfo()); -#else - rb_exc_raise(ruby_errinfo); -#endif } } @@ -1820,5 +1807,5 @@ lib_eventloop_core(check_root, update_fl int st; int status; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (update_flag) { st = RTEST(rb_protect(call_DoOneEvent, @@ -1856,18 +1843,10 @@ lib_eventloop_core(check_root, update_fl switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif if (!NIL_P(rbtk_pending_exception)) { @@ -1884,16 +1863,8 @@ lib_eventloop_core(check_root, update_fl case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); } else { -#ifdef RUBY_VM rb_exc_raise(rb_errinfo()); -#else - rb_exc_raise(ruby_errinfo); -#endif } } @@ -1945,18 +1916,10 @@ lib_eventloop_core(check_root, update_fl switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif if (!NIL_P(rbtk_pending_exception)) { @@ -1973,17 +1936,9 @@ lib_eventloop_core(check_root, update_fl case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); } else { -#ifdef RUBY_VM rb_exc_raise(rb_errinfo()); -#else - rb_exc_raise(ruby_errinfo); -#endif } } @@ -2046,5 +2001,5 @@ lib_eventloop_core(check_root, update_fl DUMP1("trap check & thread scheduling"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD /* if (update_flag == 0) CHECK_INTS; */ /*XXXXXXXXXXXXX TODO !!!! */ #else @@ -2097,33 +2052,17 @@ lib_eventloop_main(args) switch (status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } return Qnil; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } return Qnil; @@ -2183,5 +2122,5 @@ lib_eventloop_ensure(args) } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (NIL_P(eventloop_thread)) { tk_eventloop_thread_id = (Tcl_ThreadId) 0; @@ -2212,5 +2151,5 @@ lib_eventloop_launcher(check_root, updat eventloop_thread = rb_thread_current(); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD tk_eventloop_thread_id = Tcl_GetCurrentThread(); #endif @@ -2365,5 +2304,5 @@ lib_watchdog_ensure(arg) { eventloop_thread = Qnil; /* stop eventloops */ -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD tk_eventloop_thread_id = (Tcl_ThreadId) 0; #endif @@ -2379,5 +2318,5 @@ lib_mainloop_watchdog(argc, argv, self) VALUE check_rootwidget; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD rb_raise(rb_eNotImpError, "eventloop_watchdog is not implemented on Ruby VM."); @@ -2510,15 +2449,8 @@ lib_thread_callback(argc, argv, self) if (NIL_P(rbtk_pending_exception)) { -#ifdef RUBY_VM /* return rb_errinfo(); */ if (status) { rb_exc_raise(rb_errinfo()); } -#else - /* return ruby_errinfo; */ - if (status) { - rb_exc_raise(ruby_errinfo); - } -#endif } else { VALUE exc = rbtk_pending_exception; @@ -2735,92 +2667,48 @@ tcl_protect_core(interp, proc, data) /* error: str = rb_str_new2("LocalJumpError: "); -#ifdef RUBY_VM rb_str_append(str, rb_obj_as_string(rb_errinfo())); -#else - rb_str_append(str, rb_obj_as_string(ruby_errinfo)); -#endif exc = rb_exc_new3(type, str); break; case TAG_RETRY: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif DUMP1("rb_protect: retry"); exc = rb_exc_new2(eTkCallbackRetry, "retry jump error"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_REDO: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif DUMP1("rb_protect: redo"); exc = rb_exc_new2(eTkCallbackRedo, "redo jump error"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif exc = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif exc = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; case TAG_THROW: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif DUMP1("rb_protect: throw"); exc = rb_exc_new2(eTkCallbackThrow, "throw jump error"); } else { -#ifdef RUBY_VM exc = rb_errinfo(); -#else - exc = ruby_errinfo; -#endif } break; @@ -2930,15 +2818,9 @@ tcl_protect(interp, proc, data) #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on tcl_protect()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on tcl_protect()"); - } -#endif #endif @@ -3220,6 +3102,5 @@ ip_ruby_cmd(clientData, interp, argc, ar /* get args */ args = rb_ary_new2(argc - 2); -#ifdef RUBY_VM -#else +#ifdef HAVE_STRUCT_RARRAY_LEN RARRAY(args)->len = 0; #endif @@ -3228,5 +3109,5 @@ ip_ruby_cmd(clientData, interp, argc, ar str = Tcl_GetStringFromObj(argv[i], &len); DUMP2("arg:%s",str); -#ifdef RUBY_VM +#ifndef HAVE_STRUCT_RARRAY_LEN rb_ary_push(args, rb_tainted_str_new(str, len)); #else @@ -3235,5 +3116,5 @@ ip_ruby_cmd(clientData, interp, argc, ar #else /* TCL_MAJOR_VERSION < 8 */ DUMP2("arg:%s",argv[i]); -#ifdef RUBY_VM +#ifndef HAVE_STRUCT_RARRAY_LEN rb_ary_push(args, rb_tainted_str_new2(argv[i])); #else @@ -3436,15 +3317,9 @@ ip_rbUpdateCommand(clientData, interp, o } #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on ip_ruby_eval()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on ip_ruby_eval()"); - } -#endif #endif @@ -3593,15 +3468,9 @@ ip_rb_threadUpdateCommand(clientData, in } #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()"); - } -#endif #endif @@ -3792,15 +3661,9 @@ ip_rbVwaitCommand(clientData, interp, ob Tcl_Preserve(interp); #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on ip_rbVwaitCommand()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on ip_rbVwaitCommand()"); - } -#endif #endif @@ -5551,17 +5414,8 @@ ip_init(argc, argv, self) /* security check */ -#ifdef RUBY_VM if (rb_safe_level() >= 4) { -#else - if (ruby_safe_level >= 4) { -#endif rb_raise(rb_eSecurityError, "Cannot create a TclTkIp object at level %d", -#ifdef RUBY_VM - rb_safe_level() -#else - ruby_safe_level -#endif - ); + rb_safe_level()); } @@ -5571,5 +5425,5 @@ ip_init(argc, argv, self) /* ptr = (struct tcltkip *)ckalloc(sizeof(struct tcltkip)); */ DATA_PTR(self) = ptr; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr->tk_thread_id = 0; #endif @@ -5681,5 +5535,5 @@ ip_init(argc, argv, self) #endif -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD /* set Tk thread ID */ ptr->tk_thread_id = Tcl_GetCurrentThread(); @@ -5803,5 +5657,5 @@ ip_create_slave_core(interp, argc, argv) /* create slave-ip */ -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD /* slave->tk_thread_id = 0; */ slave->tk_thread_id = master->tk_thread_id; /* == current thread */ @@ -6260,5 +6114,5 @@ get_str_from_obj(obj) str = s ? rb_str_new(s, len) : rb_str_new2(""); if (binary) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -6266,5 +6120,5 @@ get_str_from_obj(obj) #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) } else { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_UTF8); #endif @@ -6295,5 +6149,5 @@ get_obj_from_str(str) return Tcl_NewStringObj(s, RSTRING_LEN(str)); } -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) { /* binary string */ @@ -6473,5 +6327,5 @@ tk_funcall(func, argc, argv, obj) } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr) { /* on Tcl interpreter */ @@ -6549,5 +6403,5 @@ tk_funcall(func, argc, argv, obj) /* add the handler to Tcl event queue */ DUMP1("add handler"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr && ptr->tk_thread_id) { /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, @@ -6696,33 +6550,17 @@ ip_eval_real(self, cmd_str, cmd_len) switch(status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } break; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } } @@ -6893,15 +6731,9 @@ eval_queue_handler(evPtr, flags) if (rb_safe_level() != q->safe_level) { #ifdef HAVE_NATIVETHREAD -#ifdef RUBY_VM -#if 0 +#ifndef RUBY_USE_NATIVE_THREAD if (!ruby_native_thread_p()) { rb_bug("cross-thread violation on eval_queue_handler()"); } #endif -#else - if (!is_ruby_native_thread()) { - rb_bug("cross-thread violation on eval_queue_handler()"); - } -#endif #endif /* q_dat = Data_Wrap_Struct(rb_cData,0,-1,q); */ @@ -6963,5 +6795,5 @@ ip_eval(self, str) { struct eval_queue *evq; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD struct tcltkip *ptr; #endif @@ -6980,10 +6812,10 @@ ip_eval(self, str) rb_thread_critical = thr_crit_bup; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr = get_ip(ip_obj); #endif if ( -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread()) && @@ -7048,5 +6880,5 @@ ip_eval(self, str) /* add the handler to Tcl event queue */ DUMP1("add handler"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr->tk_thread_id) { /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(evq->ev), position); */ @@ -7270,5 +7102,5 @@ lib_toUTF8_core(ip_obj, src, encodename) volatile VALUE enc; -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H enc = rb_funcall(rb_obj_encoding(str), ID_to_s, 0, 0); #else @@ -7300,5 +7132,5 @@ lib_toUTF8_core(ip_obj, src, encodename) StringValue(enc); if (strcmp(RSTRING_PTR(enc), "binary") == 0) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7320,5 +7152,5 @@ lib_toUTF8_core(ip_obj, src, encodename) StringValue(encodename); if (strcmp(RSTRING_PTR(encodename), "binary") == 0) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7357,5 +7189,5 @@ lib_toUTF8_core(ip_obj, src, encodename) /* str = rb_str_new2(Tcl_DStringValue(&dstr)); */ str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr)); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_UTF8); #endif @@ -7450,5 +7282,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam StringValue(enc); if (strcmp(RSTRING_PTR(enc), "binary") == 0) { -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7457,5 +7289,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam return str; } -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) { rb_enc_associate_index(str, ENCODING_INDEX_BINARY); @@ -7506,5 +7338,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam s = (char*)NULL; Tcl_DecrRefCount(tclstr); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7548,5 +7380,5 @@ lib_fromUTF8_core(ip_obj, src, encodenam /* str = rb_str_new2(Tcl_DStringValue(&dstr)); */ str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr)); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H if (interp) { /* can access encoding_table of TclTkIp */ @@ -7657,5 +7489,5 @@ lib_UTF_backslash_core(self, str, all_bs str = rb_str_new(dst_buf, dst_len); if (taint_flag) OBJ_TAINT(str); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, ENCODING_INDEX_UTF8); #endif @@ -7962,33 +7794,17 @@ ip_invoke_core(interp, argc, argv) switch(status) { case TAG_RAISE: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eException, "unknown exception"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } break; case TAG_FATAL: -#ifdef RUBY_VM if (NIL_P(rb_errinfo())) { -#else - if (NIL_P(ruby_errinfo)) { -#endif rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); } else { -#ifdef RUBY_VM rbtk_pending_exception = rb_errinfo(); -#else - rbtk_pending_exception = ruby_errinfo; -#endif } } @@ -8382,5 +8198,5 @@ ip_invoke_with_position(argc, argv, obj, { struct invoke_queue *ivq; -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD struct tcltkip *ptr; #endif @@ -8402,5 +8218,5 @@ ip_invoke_with_position(argc, argv, obj, } -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD ptr = get_ip(ip_obj); DUMP2("status: ptr->tk_thread_id %p", ptr->tk_thread_id); @@ -8412,5 +8228,5 @@ ip_invoke_with_position(argc, argv, obj, if ( -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread()) && @@ -8468,5 +8284,5 @@ ip_invoke_with_position(argc, argv, obj, /* add the handler to Tcl event queue */ DUMP1("add handler"); -#ifdef RUBY_VM +#ifdef RUBY_USE_NATIVE_THREAD if (ptr->tk_thread_id) { /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(ivq->ev), position); */ @@ -8994,5 +8810,5 @@ lib_split_tklist_core(ip_obj, list_str) int idx; int taint_flag = OBJ_TAINTED(list_str); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H int list_enc_idx; volatile VALUE list_ivar_enc; @@ -9012,5 +8828,5 @@ lib_split_tklist_core(ip_obj, list_str) StringValue(list_str); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H list_enc_idx = rb_enc_get_index(list_str); list_ivar_enc = rb_ivar_get(list_str, ID_at_enc); @@ -9054,5 +8870,5 @@ lib_split_tklist_core(ip_obj, list_str) for(idx = 0; idx < objc; idx++) { elem = get_str_from_obj(objv[idx]); -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H if (rb_enc_get_index(elem) == ENCODING_INDEX_BINARY) { rb_enc_associate_index(elem, ENCODING_INDEX_BINARY); @@ -9387,5 +9203,5 @@ create_dummy_encoding_for_tk_core(interp #endif -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H if (RTEST(rb_define_dummy_encoding(RSTRING_PTR(name)))) { int idx = rb_enc_find_index(StringValueCStr(name)); @@ -9412,5 +9228,5 @@ create_dummy_encoding_for_tk(interp, nam -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H static int update_encoding_table(table, interp, error_mode) @@ -9586,5 +9402,5 @@ encoding_table_get_obj_core(table, enc, } -#else /* ! RUBY_VM */ +#else /* ! HAVE_RUBY_ENCODING_H */ #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) static int @@ -9713,5 +9529,5 @@ encoding_table_get_obj(table, enc) } -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H static VALUE create_encoding_table(interp) @@ -9803,5 +9619,5 @@ create_encoding_table(interp) } -#else /* ! RUBY_VM */ +#else /* ! HAVE_RUBY_ENCODING_H */ #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) static VALUE @@ -10036,7 +9852,7 @@ Init_tcltklib() /* --------------------------------------------------------------- */ -#ifdef RUBY_VM +#ifdef HAVE_RUBY_ENCODING_H rb_global_variable(&cRubyEncoding); - cRubyEncoding = rb_const_get(rb_cObject, rb_intern("Encoding")); + cRubyEncoding = rb_path2class("Encoding"); ENCODING_INDEX_UTF8 = rb_enc_to_index(rb_utf8_encoding()); @@ -10294,9 +10110,5 @@ Init_tcltklib() /* if ruby->nativethread-supprt and tcltklib->doen't, the following will cause link-error. */ -#ifdef RUBY_VM ruby_native_thread_p(); -#else - is_ruby_native_thread(); -#endif /* --------------------------------------------------------------- */ Index: trunk/ext/tk/extconf.rb =================================================================== --- trunk/ext/tk/extconf.rb (revision 17089) +++ trunk/ext/tk/extconf.rb (working copy) @@ -3,8 +3,15 @@ require 'mkmf' -#is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM) is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM) #is_macosx = (/darwin/ =~ RUBY_PLATFORM) +have_header("ruby/ruby.h") +have_header("ruby/encoding.h") +have_func("ruby_native_thread_p", "ruby.h") +have_func("rb_errinfo", "ruby.h") +have_func("rb_safe_level", "ruby.h") +have_struct_member("struct RArray", "ptr", "ruby.h") +have_struct_member("struct RArray", "len", "ruby.h") + def find_framework(tcl_hdr, tk_hdr) if framework_dir = with_config("tcltk-framework") Index: trunk/ext/tk/tkutil/extconf.rb =================================================================== --- trunk/ext/tk/tkutil/extconf.rb (revision 17089) +++ trunk/ext/tk/tkutil/extconf.rb (working copy) @@ -8,5 +8,7 @@ end if has_tk require 'mkmf' + have_header("ruby/ruby.h") have_func("rb_obj_instance_exec", "ruby.h") + have_func("rb_sym_to_s", "ruby.h") have_func("strndup", "string.h") create_makefile('tkutil') Index: trunk/ext/tk/tkutil/tkutil.c =================================================================== --- trunk/ext/tk/tkutil/tkutil.c (revision 17089) +++ trunk/ext/tk/tkutil/tkutil.c (working copy) @@ -12,5 +12,5 @@ #include "ruby.h" -#ifdef RUBY_VM /* Ruby 1.9 */ +#ifdef HAVE_RUBY_RUBY_H /* #include "ruby/ruby.h" */ #include "ruby/signal.h" @@ -118,6 +118,6 @@ tk_do_callback(argc, argv, self) } -static char *cmd_id_head = "ruby_cmd TkUtil callback "; -static char *cmd_id_prefix = "cmd"; +static const char cmd_id_head[] = "ruby_cmd TkUtil callback "; +static const char cmd_id_prefix[] = "cmd"; static VALUE @@ -792,5 +792,5 @@ get_eval_string_core(obj, enc_flag, self } } else { -#ifdef RUBY_VM +#ifdef HAVE_RB_SYM_TO_S return rb_sym_to_s(obj); #else
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦