1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/tk: check proper conditions. [ruby-dev:35047]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-06-11 15:56:22 +00:00
parent a999490fe3
commit cf508bfeda
6 changed files with 108 additions and 283 deletions

View file

@ -1,3 +1,7 @@
Thu Jun 12 00:56:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/tk: check proper conditions. [ruby-dev:35047]
Wed Jun 11 23:33:13 2008 Yukihiro Matsumoto <matz@ruby-lang.org> Wed Jun 11 23:33:13 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_fread): bypass buffered read if reading buffer is empty. * io.c (io_fread): bypass buffered read if reading buffer is empty.

View file

@ -2,10 +2,17 @@
require 'mkmf' require 'mkmf'
#is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM)
is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM) is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ 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) def find_framework(tcl_hdr, tk_hdr)
if framework_dir = with_config("tcltk-framework") if framework_dir = with_config("tcltk-framework")
paths = [framework_dir] paths = [framework_dir]

View file

@ -92,7 +92,7 @@ static DL_HANDLE tcl_dll = (DL_HANDLE)0;
static DL_HANDLE tk_dll = (DL_HANDLE)0; static DL_HANDLE tk_dll = (DL_HANDLE)0;
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_open_tcl_dll(char *appname) ruby_open_tcl_dll(char *appname)
#else #else
ruby_open_tcl_dll(appname) ruby_open_tcl_dll(appname)
@ -179,7 +179,7 @@ ruby_open_tk_dll()
} }
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_open_tcltk_dll(char *appname) ruby_open_tcltk_dll(char *appname)
#else #else
ruby_open_tcltk_dll(appname) ruby_open_tcltk_dll(appname)
@ -203,7 +203,7 @@ tk_stubs_init_p()
Tcl_Interp * Tcl_Interp *
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_tcl_create_ip_and_stubs_init(int *st) ruby_tcl_create_ip_and_stubs_init(int *st)
#else #else
ruby_tcl_create_ip_and_stubs_init(st) ruby_tcl_create_ip_and_stubs_init(st)
@ -290,7 +290,7 @@ ruby_tcl_stubs_init()
} }
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_tk_stubs_init(Tcl_Interp *tcl_ip) ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
#else #else
ruby_tk_stubs_init(tcl_ip) ruby_tk_stubs_init(tcl_ip)
@ -330,7 +330,7 @@ ruby_tk_stubs_init(tcl_ip)
} }
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip) ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
#else #else
ruby_tk_stubs_safeinit(tcl_ip) ruby_tk_stubs_safeinit(tcl_ip)
@ -421,7 +421,7 @@ static int open_tcl_dll = 0;
static int call_tk_stubs_init = 0; static int call_tk_stubs_init = 0;
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_open_tcl_dll(char *appname) ruby_open_tcl_dll(char *appname)
#else #else
ruby_open_tcl_dll(appname) ruby_open_tcl_dll(appname)
@ -450,7 +450,7 @@ ruby_open_tk_dll()
} }
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_open_tcltk_dll(char *appname) ruby_open_tcltk_dll(char *appname)
#else #else
ruby_open_tcltk_dll(appname) ruby_open_tcltk_dll(appname)
@ -473,7 +473,7 @@ tk_stubs_init_p()
} }
Tcl_Interp * Tcl_Interp *
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_tcl_create_ip_and_stubs_init(int *st) ruby_tcl_create_ip_and_stubs_init(int *st)
#else #else
ruby_tcl_create_ip_and_stubs_init(st) ruby_tcl_create_ip_and_stubs_init(st)
@ -506,7 +506,7 @@ ruby_tcl_stubs_init()
} }
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_tk_stubs_init(Tcl_Interp *tcl_ip) ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
#else #else
ruby_tk_stubs_init(tcl_ip) ruby_tk_stubs_init(tcl_ip)
@ -527,7 +527,7 @@ ruby_tk_stubs_init(tcl_ip)
} }
int int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip) ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
#else #else
ruby_tk_stubs_safeinit(tcl_ip) ruby_tk_stubs_safeinit(tcl_ip)

View file

@ -8,10 +8,12 @@
#include "ruby.h" #include "ruby.h"
#ifdef RUBY_VM #ifdef HAVE_RUBY_RUBY_H
/* #include "ruby/ruby.h" */ /* #include "ruby/ruby.h" */
#include "ruby/signal.h" #include "ruby/signal.h"
#ifdef HAVE_RUBY_ENCODING_H
#include "ruby/encoding.h" #include "ruby/encoding.h"
#endif
#else #else
/* #include "ruby.h" */ /* #include "ruby.h" */
#include "rubysig.h" #include "rubysig.h"
@ -31,6 +33,19 @@
#include <tcl.h> #include <tcl.h>
#include <tk.h> #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" #include "stubs.h"
#ifndef TCL_ALPHA_RELEASE #ifndef TCL_ALPHA_RELEASE
@ -101,7 +116,7 @@ fprintf(stderr, ARG1, ARG2, ARG3); fprintf(stderr, "\n"); fflush(stderr); }
*/ */
/* release date */ /* release date */
const char tcltklib_release_date[] = TCLTKLIB_RELEASE_DATE; const const char tcltklib_release_date[] = TCLTKLIB_RELEASE_DATE;
/* finalize_proc_name */ /* finalize_proc_name */
static char *finalize_hook_name = "INTERP_FINALIZE_HOOK"; static char *finalize_hook_name = "INTERP_FINALIZE_HOOK";
@ -110,7 +125,7 @@ static void ip_finalize _((Tcl_Interp*));
static int at_exit = 0; static int at_exit = 0;
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
static VALUE cRubyEncoding; static VALUE cRubyEncoding;
/* encoding */ /* encoding */
@ -195,7 +210,7 @@ static Tcl_ObjType *Tcl_ObjType_String;
/* safe Tcl_Eval and Tcl_GlobalEval */ /* safe Tcl_Eval and Tcl_GlobalEval */
static int static int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
tcl_eval(Tcl_Interp *interp, const char *cmd) tcl_eval(Tcl_Interp *interp, const char *cmd)
#else #else
tcl_eval(interp, cmd) tcl_eval(interp, cmd)
@ -216,7 +231,7 @@ tcl_eval(interp, cmd)
#define Tcl_Eval tcl_eval #define Tcl_Eval tcl_eval
static int static int
#ifdef RUBY_VM #ifdef HAVE_PROTOTYPES
tcl_global_eval(Tcl_Interp *interp, const char *cmd) tcl_global_eval(Tcl_Interp *interp, const char *cmd)
#else #else
tcl_global_eval(interp, cmd) tcl_global_eval(interp, cmd)
@ -393,7 +408,7 @@ call_queue_mark(struct call_queue *q)
static VALUE eventloop_thread; static VALUE eventloop_thread;
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
Tcl_ThreadId tk_eventloop_thread_id; /* native thread ID of Tcl interpreter */ Tcl_ThreadId tk_eventloop_thread_id; /* native thread ID of Tcl interpreter */
#endif #endif
static VALUE eventloop_stack; static VALUE eventloop_stack;
@ -424,14 +439,14 @@ static int have_rb_thread_waiting_for_value = 0;
* 'timer_tick' is a limit of one term of thread scheduling. * 'timer_tick' is a limit of one term of thread scheduling.
* If 'timer_tick' == 0, then not use the timer for thread scheduling. * 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_EVENT_LOOP_MAX 800/*counts*/
#define DEFAULT_NO_EVENT_TICK 10/*counts*/ #define DEFAULT_NO_EVENT_TICK 10/*counts*/
#define DEFAULT_NO_EVENT_WAIT 10/*milliseconds ( 1 -- 999 ) */ #define DEFAULT_NO_EVENT_WAIT 10/*milliseconds ( 1 -- 999 ) */
#define WATCHDOG_INTERVAL 10/*milliseconds ( 1 -- 999 ) */ #define WATCHDOG_INTERVAL 10/*milliseconds ( 1 -- 999 ) */
#define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */ #define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */
#define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 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_EVENT_LOOP_MAX 800/*counts*/
#define DEFAULT_NO_EVENT_TICK 10/*counts*/ #define DEFAULT_NO_EVENT_TICK 10/*counts*/
#define DEFAULT_NO_EVENT_WAIT 20/*milliseconds ( 1 -- 999 ) */ #define DEFAULT_NO_EVENT_WAIT 20/*milliseconds ( 1 -- 999 ) */
@ -673,7 +688,7 @@ struct tcltkip {
#if TCL_NAMESPACE_DEBUG #if TCL_NAMESPACE_DEBUG
Tcl_Namespace *default_ns; /* default namespace */ Tcl_Namespace *default_ns; /* default namespace */
#endif #endif
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
Tcl_ThreadId tk_thread_id; /* native thread ID of Tcl interpreter */ Tcl_ThreadId tk_thread_id; /* native thread ID of Tcl interpreter */
#endif #endif
int has_orig_exit; /* has original 'exit' command ? */ int has_orig_exit; /* has original 'exit' command ? */
@ -866,7 +881,7 @@ tcltkip_init_tk(interp)
} }
#endif #endif
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
ptr->tk_thread_id = Tcl_GetCurrentThread(); ptr->tk_thread_id = Tcl_GetCurrentThread();
#endif #endif
@ -1138,7 +1153,7 @@ _timer_for_tcl(clientData)
/* tick_counter += event_loop_max; */ /* tick_counter += event_loop_max; */
} }
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
#if USE_TOGGLE_WINDOW_MODE_FOR_IDLE #if USE_TOGGLE_WINDOW_MODE_FOR_IDLE
static int static int
toggle_eventloop_window_mode_for_idle() toggle_eventloop_window_mode_for_idle()
@ -1489,7 +1504,7 @@ lib_num_of_mainwindows(self)
} }
#ifdef RUBY_VM /* Ruby 1.9+ !!! */ #ifdef RUBY_USE_NATIVE_THREAD /* Ruby 1.9+ !!! */
static VALUE static VALUE
call_DoOneEvent_core(flag_val) call_DoOneEvent_core(flag_val)
VALUE flag_val; VALUE flag_val;
@ -1538,17 +1553,11 @@ eventloop_sleep(dummy)
t.tv_usec = (time_t)(no_event_wait*1000.0); t.tv_usec = (time_t)(no_event_wait*1000.0);
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
#ifdef RUBY_VM #ifndef RUBY_USE_NATIVE_THREAD
#if 0
if (!ruby_native_thread_p()) { if (!ruby_native_thread_p()) {
rb_bug("cross-thread violation on eventloop_sleep()"); rb_bug("cross-thread violation on eventloop_sleep()");
} }
#endif #endif
#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on eventloop_sleep()");
}
#endif
#endif #endif
DUMP2("eventloop_sleep: rb_thread_wait_for() at thread : %lx", rb_thread_current()); DUMP2("eventloop_sleep: rb_thread_wait_for() at thread : %lx", rb_thread_current());
@ -1556,17 +1565,11 @@ eventloop_sleep(dummy)
DUMP2("eventloop_sleep: finish at thread : %lx", rb_thread_current()); DUMP2("eventloop_sleep: finish at thread : %lx", rb_thread_current());
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
#ifdef RUBY_VM #ifndef RUBY_USE_NATIVE_THREAD
#if 0
if (!ruby_native_thread_p()) { if (!ruby_native_thread_p()) {
rb_bug("cross-thread violation on eventloop_sleep()"); rb_bug("cross-thread violation on eventloop_sleep()");
} }
#endif #endif
#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on eventloop_sleep()");
}
#endif
#endif #endif
return Qnil; return Qnil;
@ -1578,7 +1581,7 @@ eventloop_sleep(dummy)
static int static int
get_thread_alone_check_flag() get_thread_alone_check_flag()
{ {
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
return 0; return 0;
#else #else
set_tcltk_version(); set_tcltk_version();
@ -1690,19 +1693,11 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
if (status) { if (status) {
switch (status) { switch (status) {
case TAG_RAISE: case TAG_RAISE:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception rbtk_pending_exception
= rb_exc_new2(rb_eException, "unknown exception"); = rb_exc_new2(rb_eException, "unknown exception");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
if (!NIL_P(rbtk_pending_exception)) { if (!NIL_P(rbtk_pending_exception)) {
if (rbtk_eventloop_depth == 0) { if (rbtk_eventloop_depth == 0) {
@ -1717,18 +1712,10 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
break; break;
case TAG_FATAL: case TAG_FATAL:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL"));
} else { } else {
#ifdef RUBY_VM
rb_exc_raise(rb_errinfo()); rb_exc_raise(rb_errinfo());
#else
rb_exc_raise(ruby_errinfo);
#endif
} }
} }
} }
@ -1819,7 +1806,7 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
if (NIL_P(eventloop_thread) || current == eventloop_thread) { if (NIL_P(eventloop_thread) || current == eventloop_thread) {
int st; int st;
int status; int status;
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
if (update_flag) { if (update_flag) {
st = RTEST(rb_protect(call_DoOneEvent, st = RTEST(rb_protect(call_DoOneEvent,
INT2FIX(event_flag), &status)); INT2FIX(event_flag), &status));
@ -1855,20 +1842,12 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
if (status) { if (status) {
switch (status) { switch (status) {
case TAG_RAISE: case TAG_RAISE:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception rbtk_pending_exception
= rb_exc_new2(rb_eException, = rb_exc_new2(rb_eException,
"unknown exception"); "unknown exception");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
if (!NIL_P(rbtk_pending_exception)) { if (!NIL_P(rbtk_pending_exception)) {
if (rbtk_eventloop_depth == 0) { if (rbtk_eventloop_depth == 0) {
@ -1883,18 +1862,10 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
break; break;
case TAG_FATAL: case TAG_FATAL:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL")); rb_exc_raise(rb_exc_new2(rb_eFatal, "FATAL"));
} else { } else {
#ifdef RUBY_VM
rb_exc_raise(rb_errinfo()); rb_exc_raise(rb_errinfo());
#else
rb_exc_raise(ruby_errinfo);
#endif
} }
} }
} }
@ -1944,20 +1915,12 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
if (status) { if (status) {
switch (status) { switch (status) {
case TAG_RAISE: case TAG_RAISE:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception rbtk_pending_exception
= rb_exc_new2(rb_eException, = rb_exc_new2(rb_eException,
"unknown exception"); "unknown exception");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
if (!NIL_P(rbtk_pending_exception)) { if (!NIL_P(rbtk_pending_exception)) {
if (rbtk_eventloop_depth == 0) { if (rbtk_eventloop_depth == 0) {
@ -1972,19 +1935,11 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
break; break;
case TAG_FATAL: case TAG_FATAL:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rb_exc_raise(rb_exc_new2(rb_eFatal, rb_exc_raise(rb_exc_new2(rb_eFatal,
"FATAL")); "FATAL"));
} else { } else {
#ifdef RUBY_VM
rb_exc_raise(rb_errinfo()); rb_exc_raise(rb_errinfo());
#else
rb_exc_raise(ruby_errinfo);
#endif
} }
} }
} }
@ -2045,7 +2000,7 @@ lib_eventloop_core(check_root, update_flag, check_var, interp)
} }
DUMP1("trap check & thread scheduling"); DUMP1("trap check & thread scheduling");
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
/* if (update_flag == 0) CHECK_INTS; */ /*XXXXXXXXXXXXX TODO !!!! */ /* if (update_flag == 0) CHECK_INTS; */ /*XXXXXXXXXXXXX TODO !!!! */
#else #else
if (update_flag == 0) CHECK_INTS; if (update_flag == 0) CHECK_INTS;
@ -2096,35 +2051,19 @@ lib_eventloop_main(args)
switch (status) { switch (status) {
case TAG_RAISE: case TAG_RAISE:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception rbtk_pending_exception
= rb_exc_new2(rb_eException, "unknown exception"); = rb_exc_new2(rb_eException, "unknown exception");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
} }
return Qnil; return Qnil;
case TAG_FATAL: case TAG_FATAL:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
} }
return Qnil; return Qnil;
} }
@ -2182,7 +2121,7 @@ lib_eventloop_ensure(args)
} }
} }
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
if (NIL_P(eventloop_thread)) { if (NIL_P(eventloop_thread)) {
tk_eventloop_thread_id = (Tcl_ThreadId) 0; tk_eventloop_thread_id = (Tcl_ThreadId) 0;
} }
@ -2211,7 +2150,7 @@ lib_eventloop_launcher(check_root, update_flag, check_var, interp)
tcl_stubs_check(); tcl_stubs_check();
eventloop_thread = rb_thread_current(); eventloop_thread = rb_thread_current();
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
tk_eventloop_thread_id = Tcl_GetCurrentThread(); tk_eventloop_thread_id = Tcl_GetCurrentThread();
#endif #endif
@ -2364,7 +2303,7 @@ lib_watchdog_ensure(arg)
VALUE arg; VALUE arg;
{ {
eventloop_thread = Qnil; /* stop eventloops */ eventloop_thread = Qnil; /* stop eventloops */
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
tk_eventloop_thread_id = (Tcl_ThreadId) 0; tk_eventloop_thread_id = (Tcl_ThreadId) 0;
#endif #endif
return Qnil; return Qnil;
@ -2378,7 +2317,7 @@ lib_mainloop_watchdog(argc, argv, self)
{ {
VALUE check_rootwidget; VALUE check_rootwidget;
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
rb_raise(rb_eNotImpError, rb_raise(rb_eNotImpError,
"eventloop_watchdog is not implemented on Ruby VM."); "eventloop_watchdog is not implemented on Ruby VM.");
#endif #endif
@ -2509,17 +2448,10 @@ lib_thread_callback(argc, argv, self)
/* ckfree((char*)q); */ /* ckfree((char*)q); */
if (NIL_P(rbtk_pending_exception)) { if (NIL_P(rbtk_pending_exception)) {
#ifdef RUBY_VM
/* return rb_errinfo(); */ /* return rb_errinfo(); */
if (status) { if (status) {
rb_exc_raise(rb_errinfo()); rb_exc_raise(rb_errinfo());
} }
#else
/* return ruby_errinfo; */
if (status) {
rb_exc_raise(ruby_errinfo);
}
#endif
} else { } else {
VALUE exc = rbtk_pending_exception; VALUE exc = rbtk_pending_exception;
rbtk_pending_exception = Qnil; rbtk_pending_exception = Qnil;
@ -2734,94 +2666,50 @@ tcl_protect_core(interp, proc, data) /* should not raise exception */
goto error; goto error;
error: error:
str = rb_str_new2("LocalJumpError: "); str = rb_str_new2("LocalJumpError: ");
#ifdef RUBY_VM
rb_str_append(str, rb_obj_as_string(rb_errinfo())); 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); exc = rb_exc_new3(type, str);
break; break;
case TAG_RETRY: case TAG_RETRY:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
DUMP1("rb_protect: retry"); DUMP1("rb_protect: retry");
exc = rb_exc_new2(eTkCallbackRetry, "retry jump error"); exc = rb_exc_new2(eTkCallbackRetry, "retry jump error");
} else { } else {
#ifdef RUBY_VM
exc = rb_errinfo(); exc = rb_errinfo();
#else
exc = ruby_errinfo;
#endif
} }
break; break;
case TAG_REDO: case TAG_REDO:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
DUMP1("rb_protect: redo"); DUMP1("rb_protect: redo");
exc = rb_exc_new2(eTkCallbackRedo, "redo jump error"); exc = rb_exc_new2(eTkCallbackRedo, "redo jump error");
} else { } else {
#ifdef RUBY_VM
exc = rb_errinfo(); exc = rb_errinfo();
#else
exc = ruby_errinfo;
#endif
} }
break; break;
case TAG_RAISE: case TAG_RAISE:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
exc = rb_exc_new2(rb_eException, "unknown exception"); exc = rb_exc_new2(rb_eException, "unknown exception");
} else { } else {
#ifdef RUBY_VM
exc = rb_errinfo(); exc = rb_errinfo();
#else
exc = ruby_errinfo;
#endif
} }
break; break;
case TAG_FATAL: case TAG_FATAL:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
exc = rb_exc_new2(rb_eFatal, "FATAL"); exc = rb_exc_new2(rb_eFatal, "FATAL");
} else { } else {
#ifdef RUBY_VM
exc = rb_errinfo(); exc = rb_errinfo();
#else
exc = ruby_errinfo;
#endif
} }
break; break;
case TAG_THROW: case TAG_THROW:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
DUMP1("rb_protect: throw"); DUMP1("rb_protect: throw");
exc = rb_exc_new2(eTkCallbackThrow, "throw jump error"); exc = rb_exc_new2(eTkCallbackThrow, "throw jump error");
} else { } else {
#ifdef RUBY_VM
exc = rb_errinfo(); exc = rb_errinfo();
#else
exc = ruby_errinfo;
#endif
} }
break; break;
@ -2929,17 +2817,11 @@ tcl_protect(interp, proc, data)
int code; int code;
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
#ifdef RUBY_VM #ifndef RUBY_USE_NATIVE_THREAD
#if 0
if (!ruby_native_thread_p()) { if (!ruby_native_thread_p()) {
rb_bug("cross-thread violation on tcl_protect()"); rb_bug("cross-thread violation on tcl_protect()");
} }
#endif #endif
#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on tcl_protect()");
}
#endif
#endif #endif
rb_trap_immediate = 0; rb_trap_immediate = 0;
@ -3219,22 +3101,21 @@ ip_ruby_cmd(clientData, interp, argc, argv)
/* get args */ /* get args */
args = rb_ary_new2(argc - 2); args = rb_ary_new2(argc - 2);
#ifdef RUBY_VM #ifdef HAVE_STRUCT_RARRAY_LEN
#else
RARRAY(args)->len = 0; RARRAY(args)->len = 0;
#endif #endif
for(i = 3; i < argc; i++) { for(i = 3; i < argc; i++) {
#if TCL_MAJOR_VERSION >= 8 #if TCL_MAJOR_VERSION >= 8
str = Tcl_GetStringFromObj(argv[i], &len); str = Tcl_GetStringFromObj(argv[i], &len);
DUMP2("arg:%s",str); DUMP2("arg:%s",str);
#ifdef RUBY_VM #ifndef HAVE_STRUCT_RARRAY_LEN
rb_ary_push(args, rb_tainted_str_new(str, len)); rb_ary_push(args, rb_tainted_str_new(str, len));
#else #else
RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new(str, len); RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new(str, len);
#endif #endif
#else /* TCL_MAJOR_VERSION < 8 */ #else /* TCL_MAJOR_VERSION < 8 */
DUMP2("arg:%s",argv[i]); DUMP2("arg:%s",argv[i]);
#ifdef RUBY_VM #ifndef HAVE_STRUCT_RARRAY_LEN
rb_ary_push(args, rb_tainted_str_new2(argv[i])); rb_ary_push(args, rb_tainted_str_new2(argv[i]));
#else #else
RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new2(argv[i]); RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new2(argv[i]);
@ -3435,17 +3316,11 @@ ip_rbUpdateCommand(clientData, interp, objc, objv)
return TCL_ERROR; return TCL_ERROR;
} }
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
#ifdef RUBY_VM #ifndef RUBY_USE_NATIVE_THREAD
#if 0
if (!ruby_native_thread_p()) { if (!ruby_native_thread_p()) {
rb_bug("cross-thread violation on ip_ruby_eval()"); rb_bug("cross-thread violation on ip_ruby_eval()");
} }
#endif #endif
#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on ip_ruby_eval()");
}
#endif
#endif #endif
Tcl_ResetResult(interp); Tcl_ResetResult(interp);
@ -3592,17 +3467,11 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv)
return TCL_ERROR; return TCL_ERROR;
} }
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
#ifdef RUBY_VM #ifndef RUBY_USE_NATIVE_THREAD
#if 0
if (!ruby_native_thread_p()) { if (!ruby_native_thread_p()) {
rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()"); rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()");
} }
#endif #endif
#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on ip_rb_threadUpdateCommand()");
}
#endif
#endif #endif
if (rb_thread_alone() if (rb_thread_alone()
@ -3791,17 +3660,11 @@ ip_rbVwaitCommand(clientData, interp, objc, objv)
Tcl_Preserve(interp); Tcl_Preserve(interp);
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
#ifdef RUBY_VM #ifndef RUBY_USE_NATIVE_THREAD
#if 0
if (!ruby_native_thread_p()) { if (!ruby_native_thread_p()) {
rb_bug("cross-thread violation on ip_rbVwaitCommand()"); rb_bug("cross-thread violation on ip_rbVwaitCommand()");
} }
#endif #endif
#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on ip_rbVwaitCommand()");
}
#endif
#endif #endif
Tcl_ResetResult(interp); Tcl_ResetResult(interp);
@ -5550,19 +5413,10 @@ ip_init(argc, argv, self)
Tk_Window mainWin = (Tk_Window)NULL; Tk_Window mainWin = (Tk_Window)NULL;
/* security check */ /* security check */
#ifdef RUBY_VM
if (rb_safe_level() >= 4) { if (rb_safe_level() >= 4) {
#else
if (ruby_safe_level >= 4) {
#endif
rb_raise(rb_eSecurityError, rb_raise(rb_eSecurityError,
"Cannot create a TclTkIp object at level %d", "Cannot create a TclTkIp object at level %d",
#ifdef RUBY_VM rb_safe_level());
rb_safe_level()
#else
ruby_safe_level
#endif
);
} }
/* create object */ /* create object */
@ -5570,7 +5424,7 @@ ip_init(argc, argv, self)
ptr = ALLOC(struct tcltkip); ptr = ALLOC(struct tcltkip);
/* ptr = (struct tcltkip *)ckalloc(sizeof(struct tcltkip)); */ /* ptr = (struct tcltkip *)ckalloc(sizeof(struct tcltkip)); */
DATA_PTR(self) = ptr; DATA_PTR(self) = ptr;
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
ptr->tk_thread_id = 0; ptr->tk_thread_id = 0;
#endif #endif
ptr->ref_count = 0; ptr->ref_count = 0;
@ -5680,7 +5534,7 @@ ip_init(argc, argv, self)
(Tcl_PackageInitProc *) NULL); (Tcl_PackageInitProc *) NULL);
#endif #endif
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
/* set Tk thread ID */ /* set Tk thread ID */
ptr->tk_thread_id = Tcl_GetCurrentThread(); ptr->tk_thread_id = Tcl_GetCurrentThread();
#endif #endif
@ -5802,7 +5656,7 @@ ip_create_slave_core(interp, argc, argv)
#endif #endif
/* create slave-ip */ /* create slave-ip */
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
/* slave->tk_thread_id = 0; */ /* slave->tk_thread_id = 0; */
slave->tk_thread_id = master->tk_thread_id; /* == current thread */ slave->tk_thread_id = master->tk_thread_id; /* == current thread */
#endif #endif
@ -6259,13 +6113,13 @@ get_str_from_obj(obj)
#endif #endif
str = s ? rb_str_new(s, len) : rb_str_new2(""); str = s ? rb_str_new(s, len) : rb_str_new2("");
if (binary) { if (binary) {
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, ENCODING_INDEX_BINARY); rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
} else { } else {
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, ENCODING_INDEX_UTF8); rb_enc_associate_index(str, ENCODING_INDEX_UTF8);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8);
@ -6294,7 +6148,7 @@ get_obj_from_str(str)
/* text string */ /* text string */
return Tcl_NewStringObj(s, RSTRING_LEN(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) { } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) {
/* binary string */ /* binary string */
return Tcl_NewByteArrayObj(s, RSTRING_LEN(str)); return Tcl_NewByteArrayObj(s, RSTRING_LEN(str));
@ -6472,7 +6326,7 @@ tk_funcall(func, argc, argv, obj)
ptr = (struct tcltkip *)NULL; ptr = (struct tcltkip *)NULL;
} }
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
if (ptr) { if (ptr) {
/* on Tcl interpreter */ /* on Tcl interpreter */
is_tk_evloop_thread = (ptr->tk_thread_id == (Tcl_ThreadId) 0 is_tk_evloop_thread = (ptr->tk_thread_id == (Tcl_ThreadId) 0
@ -6548,7 +6402,7 @@ tk_funcall(func, argc, argv, obj)
/* add the handler to Tcl event queue */ /* add the handler to Tcl event queue */
DUMP1("add handler"); DUMP1("add handler");
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
if (ptr && ptr->tk_thread_id) { if (ptr && ptr->tk_thread_id) {
/* Tcl_ThreadQueueEvent(ptr->tk_thread_id, /* Tcl_ThreadQueueEvent(ptr->tk_thread_id,
&(callq->ev), TCL_QUEUE_HEAD); */ &(callq->ev), TCL_QUEUE_HEAD); */
@ -6695,35 +6549,19 @@ ip_eval_real(self, cmd_str, cmd_len)
ret = rb_protect(call_tcl_eval, (VALUE)&inf, &status); ret = rb_protect(call_tcl_eval, (VALUE)&inf, &status);
switch(status) { switch(status) {
case TAG_RAISE: case TAG_RAISE:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception = rb_exc_new2(rb_eException, rbtk_pending_exception = rb_exc_new2(rb_eException,
"unknown exception"); "unknown exception");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
} }
break; break;
case TAG_FATAL: case TAG_FATAL:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
} }
} }
#endif #endif
@ -6892,17 +6730,11 @@ eval_queue_handler(evPtr, flags)
/* check safe-level */ /* check safe-level */
if (rb_safe_level() != q->safe_level) { if (rb_safe_level() != q->safe_level) {
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
#ifdef RUBY_VM #ifndef RUBY_USE_NATIVE_THREAD
#if 0
if (!ruby_native_thread_p()) { if (!ruby_native_thread_p()) {
rb_bug("cross-thread violation on eval_queue_handler()"); rb_bug("cross-thread violation on eval_queue_handler()");
} }
#endif #endif
#else
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on eval_queue_handler()");
}
#endif
#endif #endif
/* q_dat = Data_Wrap_Struct(rb_cData,0,-1,q); */ /* q_dat = Data_Wrap_Struct(rb_cData,0,-1,q); */
q_dat = Data_Wrap_Struct(rb_cData,eval_queue_mark,-1,q); q_dat = Data_Wrap_Struct(rb_cData,eval_queue_mark,-1,q);
@ -6962,7 +6794,7 @@ ip_eval(self, str)
VALUE str; VALUE str;
{ {
struct eval_queue *evq; struct eval_queue *evq;
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
struct tcltkip *ptr; struct tcltkip *ptr;
#endif #endif
char *eval_str; char *eval_str;
@ -6979,12 +6811,12 @@ ip_eval(self, str)
StringValue(str); StringValue(str);
rb_thread_critical = thr_crit_bup; rb_thread_critical = thr_crit_bup;
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
ptr = get_ip(ip_obj); ptr = get_ip(ip_obj);
#endif #endif
if ( if (
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
(ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread()) (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread())
&& &&
#endif #endif
@ -7047,7 +6879,7 @@ ip_eval(self, str)
/* add the handler to Tcl event queue */ /* add the handler to Tcl event queue */
DUMP1("add handler"); DUMP1("add handler");
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
if (ptr->tk_thread_id) { if (ptr->tk_thread_id) {
/* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(evq->ev), position); */ /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(evq->ev), position); */
Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)evq, position); Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)evq, position);
@ -7269,7 +7101,7 @@ lib_toUTF8_core(ip_obj, src, encodename)
if (TYPE(str) == T_STRING) { if (TYPE(str) == T_STRING) {
volatile VALUE enc; volatile VALUE enc;
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
enc = rb_funcall(rb_obj_encoding(str), ID_to_s, 0, 0); enc = rb_funcall(rb_obj_encoding(str), ID_to_s, 0, 0);
#else #else
enc = rb_attr_get(str, ID_at_enc); enc = rb_attr_get(str, ID_at_enc);
@ -7299,7 +7131,7 @@ lib_toUTF8_core(ip_obj, src, encodename)
} else { } else {
StringValue(enc); StringValue(enc);
if (strcmp(RSTRING_PTR(enc), "binary") == 0) { if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, ENCODING_INDEX_BINARY); rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
@ -7319,7 +7151,7 @@ lib_toUTF8_core(ip_obj, src, encodename)
} else { } else {
StringValue(encodename); StringValue(encodename);
if (strcmp(RSTRING_PTR(encodename), "binary") == 0) { if (strcmp(RSTRING_PTR(encodename), "binary") == 0) {
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, ENCODING_INDEX_BINARY); rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
@ -7356,7 +7188,7 @@ lib_toUTF8_core(ip_obj, src, encodename)
/* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */ /* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */
/* str = rb_str_new2(Tcl_DStringValue(&dstr)); */ /* str = rb_str_new2(Tcl_DStringValue(&dstr)); */
str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&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); rb_enc_associate_index(str, ENCODING_INDEX_UTF8);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8);
@ -7449,14 +7281,14 @@ lib_fromUTF8_core(ip_obj, src, encodename)
if (!NIL_P(enc)) { if (!NIL_P(enc)) {
StringValue(enc); StringValue(enc);
if (strcmp(RSTRING_PTR(enc), "binary") == 0) { if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, ENCODING_INDEX_BINARY); rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
rb_thread_critical = thr_crit_bup; rb_thread_critical = thr_crit_bup;
return str; return str;
} }
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
} else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) { } else if (rb_enc_get_index(str) == ENCODING_INDEX_BINARY) {
rb_enc_associate_index(str, ENCODING_INDEX_BINARY); rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
@ -7505,7 +7337,7 @@ lib_fromUTF8_core(ip_obj, src, encodename)
str = rb_tainted_str_new(s, len); str = rb_tainted_str_new(s, len);
s = (char*)NULL; s = (char*)NULL;
Tcl_DecrRefCount(tclstr); Tcl_DecrRefCount(tclstr);
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, ENCODING_INDEX_BINARY); rb_enc_associate_index(str, ENCODING_INDEX_BINARY);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_BINARY);
@ -7547,7 +7379,7 @@ lib_fromUTF8_core(ip_obj, src, encodename)
/* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */ /* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */
/* str = rb_str_new2(Tcl_DStringValue(&dstr)); */ /* str = rb_str_new2(Tcl_DStringValue(&dstr)); */
str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr)); str = rb_str_new(Tcl_DStringValue(&dstr), Tcl_DStringLength(&dstr));
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
if (interp) { if (interp) {
/* can access encoding_table of TclTkIp */ /* can access encoding_table of TclTkIp */
/* -> try to use encoding_table */ /* -> try to use encoding_table */
@ -7656,7 +7488,7 @@ lib_UTF_backslash_core(self, str, all_bs)
str = rb_str_new(dst_buf, dst_len); str = rb_str_new(dst_buf, dst_len);
if (taint_flag) OBJ_TAINT(str); if (taint_flag) OBJ_TAINT(str);
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, ENCODING_INDEX_UTF8); rb_enc_associate_index(str, ENCODING_INDEX_UTF8);
#endif #endif
rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8); rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8);
@ -7961,35 +7793,19 @@ ip_invoke_core(interp, argc, argv)
ret = rb_protect(invoke_tcl_proc, (VALUE)&inf, &status); ret = rb_protect(invoke_tcl_proc, (VALUE)&inf, &status);
switch(status) { switch(status) {
case TAG_RAISE: case TAG_RAISE:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception = rb_exc_new2(rb_eException, rbtk_pending_exception = rb_exc_new2(rb_eException,
"unknown exception"); "unknown exception");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
} }
break; break;
case TAG_FATAL: case TAG_FATAL:
#ifdef RUBY_VM
if (NIL_P(rb_errinfo())) { if (NIL_P(rb_errinfo())) {
#else
if (NIL_P(ruby_errinfo)) {
#endif
rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL"); rbtk_pending_exception = rb_exc_new2(rb_eFatal, "FATAL");
} else { } else {
#ifdef RUBY_VM
rbtk_pending_exception = rb_errinfo(); rbtk_pending_exception = rb_errinfo();
#else
rbtk_pending_exception = ruby_errinfo;
#endif
} }
} }
@ -8381,7 +8197,7 @@ ip_invoke_with_position(argc, argv, obj, position)
Tcl_QueuePosition position; Tcl_QueuePosition position;
{ {
struct invoke_queue *ivq; struct invoke_queue *ivq;
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
struct tcltkip *ptr; struct tcltkip *ptr;
#endif #endif
int *alloc_done; int *alloc_done;
@ -8401,7 +8217,7 @@ ip_invoke_with_position(argc, argv, obj, position)
rb_raise(rb_eArgError, "command name missing"); rb_raise(rb_eArgError, "command name missing");
} }
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
ptr = get_ip(ip_obj); ptr = get_ip(ip_obj);
DUMP2("status: ptr->tk_thread_id %p", ptr->tk_thread_id); DUMP2("status: ptr->tk_thread_id %p", ptr->tk_thread_id);
DUMP2("status: Tcl_GetCurrentThread %p", Tcl_GetCurrentThread()); DUMP2("status: Tcl_GetCurrentThread %p", Tcl_GetCurrentThread());
@ -8411,7 +8227,7 @@ ip_invoke_with_position(argc, argv, obj, position)
DUMP2("status: eventloopt_thread %lx", eventloop_thread); DUMP2("status: eventloopt_thread %lx", eventloop_thread);
if ( if (
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
(ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread()) (ptr->tk_thread_id == 0 || ptr->tk_thread_id == Tcl_GetCurrentThread())
&& &&
#endif #endif
@ -8467,7 +8283,7 @@ ip_invoke_with_position(argc, argv, obj, position)
/* add the handler to Tcl event queue */ /* add the handler to Tcl event queue */
DUMP1("add handler"); DUMP1("add handler");
#ifdef RUBY_VM #ifdef RUBY_USE_NATIVE_THREAD
if (ptr->tk_thread_id) { if (ptr->tk_thread_id) {
/* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(ivq->ev), position); */ /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(ivq->ev), position); */
Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)ivq, position); Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)ivq, position);
@ -8993,7 +8809,7 @@ lib_split_tklist_core(ip_obj, list_str)
volatile VALUE ary, elem; volatile VALUE ary, elem;
int idx; int idx;
int taint_flag = OBJ_TAINTED(list_str); int taint_flag = OBJ_TAINTED(list_str);
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
int list_enc_idx; int list_enc_idx;
volatile VALUE list_ivar_enc; volatile VALUE list_ivar_enc;
#endif #endif
@ -9011,7 +8827,7 @@ lib_split_tklist_core(ip_obj, list_str)
} }
StringValue(list_str); StringValue(list_str);
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
list_enc_idx = rb_enc_get_index(list_str); list_enc_idx = rb_enc_get_index(list_str);
list_ivar_enc = rb_ivar_get(list_str, ID_at_enc); list_ivar_enc = rb_ivar_get(list_str, ID_at_enc);
#endif #endif
@ -9053,7 +8869,7 @@ lib_split_tklist_core(ip_obj, list_str)
for(idx = 0; idx < objc; idx++) { for(idx = 0; idx < objc; idx++) {
elem = get_str_from_obj(objv[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) { if (rb_enc_get_index(elem) == ENCODING_INDEX_BINARY) {
rb_enc_associate_index(elem, ENCODING_INDEX_BINARY); rb_enc_associate_index(elem, ENCODING_INDEX_BINARY);
rb_ivar_set(elem, ID_at_enc, ENCODING_NAME_BINARY); rb_ivar_set(elem, ID_at_enc, ENCODING_NAME_BINARY);
@ -9386,7 +9202,7 @@ create_dummy_encoding_for_tk_core(interp, name, error_mode)
} }
#endif #endif
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
if (RTEST(rb_define_dummy_encoding(RSTRING_PTR(name)))) { if (RTEST(rb_define_dummy_encoding(RSTRING_PTR(name)))) {
int idx = rb_enc_find_index(StringValueCStr(name)); int idx = rb_enc_find_index(StringValueCStr(name));
return rb_enc_from_encoding(rb_enc_from_index(idx)); return rb_enc_from_encoding(rb_enc_from_index(idx));
@ -9411,7 +9227,7 @@ create_dummy_encoding_for_tk(interp, name)
} }
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
static int static int
update_encoding_table(table, interp, error_mode) update_encoding_table(table, interp, error_mode)
VALUE table; VALUE table;
@ -9585,7 +9401,7 @@ encoding_table_get_obj_core(table, enc, error_mode)
} }
} }
#else /* ! RUBY_VM */ #else /* ! HAVE_RUBY_ENCODING_H */
#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
static int static int
update_encoding_table(table, interp, error_mode) update_encoding_table(table, interp, error_mode)
@ -9712,7 +9528,7 @@ encoding_table_get_obj(table, enc)
return encoding_table_get_obj_core(table, enc, Qtrue); return encoding_table_get_obj_core(table, enc, Qtrue);
} }
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
static VALUE static VALUE
create_encoding_table(interp) create_encoding_table(interp)
VALUE interp; VALUE interp;
@ -9802,7 +9618,7 @@ create_encoding_table(interp)
return table; return table;
} }
#else /* ! RUBY_VM */ #else /* ! HAVE_RUBY_ENCODING_H */
#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)
static VALUE static VALUE
create_encoding_table(interp) create_encoding_table(interp)
@ -10035,9 +9851,9 @@ Init_tcltklib()
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
#ifdef RUBY_VM #ifdef HAVE_RUBY_ENCODING_H
rb_global_variable(&cRubyEncoding); 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()); ENCODING_INDEX_UTF8 = rb_enc_to_index(rb_utf8_encoding());
ENCODING_INDEX_BINARY = rb_enc_find_index("binary"); ENCODING_INDEX_BINARY = rb_enc_find_index("binary");
@ -10293,11 +10109,7 @@ Init_tcltklib()
/* if ruby->nativethread-supprt and tcltklib->doen't, /* if ruby->nativethread-supprt and tcltklib->doen't,
the following will cause link-error. */ the following will cause link-error. */
#ifdef RUBY_VM
ruby_native_thread_p(); ruby_native_thread_p();
#else
is_ruby_native_thread();
#endif
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */

View file

@ -7,7 +7,9 @@ end
if has_tk if has_tk
require 'mkmf' require 'mkmf'
have_header("ruby/ruby.h")
have_func("rb_obj_instance_exec", "ruby.h") have_func("rb_obj_instance_exec", "ruby.h")
have_func("rb_sym_to_s", "ruby.h")
have_func("strndup", "string.h") have_func("strndup", "string.h")
create_makefile('tkutil') create_makefile('tkutil')
end end

View file

@ -11,7 +11,7 @@
#include "ruby.h" #include "ruby.h"
#ifdef RUBY_VM /* Ruby 1.9 */ #ifdef HAVE_RUBY_RUBY_H
/* #include "ruby/ruby.h" */ /* #include "ruby/ruby.h" */
#include "ruby/signal.h" #include "ruby/signal.h"
#include "ruby/st.h" #include "ruby/st.h"
@ -117,8 +117,8 @@ tk_do_callback(argc, argv, self)
ID_call, argc - 1, argv + 1); ID_call, argc - 1, argv + 1);
} }
static char *cmd_id_head = "ruby_cmd TkUtil callback "; static const char cmd_id_head[] = "ruby_cmd TkUtil callback ";
static char *cmd_id_prefix = "cmd"; static const char cmd_id_prefix[] = "cmd";
static VALUE static VALUE
tk_install_cmd_core(cmd) tk_install_cmd_core(cmd)
@ -791,7 +791,7 @@ get_eval_string_core(obj, enc_flag, self)
return fromDefaultEnc_toUTF8(rb_str_new2(rb_id2name(SYM2ID(obj))), self); return fromDefaultEnc_toUTF8(rb_str_new2(rb_id2name(SYM2ID(obj))), self);
} }
} else { } else {
#ifdef RUBY_VM #ifdef HAVE_RB_SYM_TO_S
return rb_sym_to_s(obj); return rb_sym_to_s(obj);
#else #else
return rb_str_new2(rb_id2name(SYM2ID(obj))); return rb_str_new2(rb_id2name(SYM2ID(obj)));