···
From: Kevin Walzer <kw@codebykevin.com>
Subject: Re: Ruby-Tk and Tk 8.6
Date: Fri, 10 Oct 2014 09:06:58 -0400
Message-ID: <5437D9F2.7090007@codebykevin.com>
On 10/8/14, 6:29 PM, Hidetoshi NAGAI wrote:
I know that some kind rubyists provide patches for Tcl8.6.
Indeed, and I went to the trouble to clean up and apply the patch I
referenced earlier in this thread (removing the Ubuntu-specific
bits). I was able to build Ruby 2.1.3, and it could even load a simple
Tk script ("hello world"), but anything more complex raised a runtime
error because Ruby didn't understand Tcl's "namespace" command.
The following is an experimental patch for Ruby-2.1.3 with Tcl/Tk-8.6.2.
It will fix the "namespace" trouble only.
I've committed it to trunk also.
--------------------------------------------------------------
diff -urN ruby-2.1.3.orig/ext/tk/extconf.rb ruby-2.1.3.mod/ext/tk/extconf.rb
--- ruby-2.1.3.orig/ext/tk/extconf.rb 2013-11-30 11:46:47.000000000 +0900
+++ ruby-2.1.3.mod/ext/tk/extconf.rb 2014-10-14 02:26:29.875902167 +0900
@@ -9,10 +9,10 @@
# %w[8.9 8.8 8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6 4.2]
# %w[8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0]
# %w[8.7 8.6 8.5 8.4 8.0] # to shorten search steps
- %w[8.5 8.4] # At present, Tcl/Tk8.6 is not supported.
+ %w[8.5 8.4 8.6] # Tcl/Tk8.6 support is experimental.
TkLib_Config['unsupported_versions'] =
- %w[8.8 8.7 8.6] # At present, Tcl/Tk8.6 is not supported.
+ %w[8.8 8.7] # Tcl/Tk8.6 support is experimental.
TkLib_Config['major_nums'] = '87'
diff -urN ruby-2.1.3.orig/ext/tk/tcltklib.c ruby-2.1.3.mod/ext/tk/tcltklib.c
--- ruby-2.1.3.orig/ext/tk/tcltklib.c 2014-02-10 20:45:14.000000000 +0900
+++ ruby-2.1.3.mod/ext/tk/tcltklib.c 2014-10-14 01:31:09.757932244 +0900
@@ -6012,7 +6012,12 @@
Tcl_CmdInfo info;
int ret;
+ DUMP1("call ip_rbNamespaceObjCmd");
+ DUMP2("objc = %d", objc);
+ DUMP2("objv[0] = '%s'", Tcl_GetString(objv[0]));
+ DUMP2("objv[1] = '%s'", Tcl_GetString(objv[1]));
if (!Tcl_GetCommandInfo(interp, "__orig_namespace_command__", &(info))) {
+ DUMP1("fail to get __orig_namespace_command__");
Tcl_ResetResult(interp);
Tcl_AppendResult(interp,
"invalid command name \"namespace\"", (char*)NULL);
@@ -6020,15 +6025,37 @@
}
rbtk_eventloop_depth++;
- /* DUMP2("namespace wrapper enter depth == %d", rbtk_eventloop_depth); */
+ DUMP2("namespace wrapper enter depth == %d", rbtk_eventloop_depth);
if (info.isNativeObjectProc) {
+#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION < 6
+ DUMP1("call a native-object-proc");
ret = (*(info.objProc))(info.objClientData, interp, objc, objv);
+#else
+ /* Tcl8.6 or later */
+ int i;
+ Tcl_Obj **cp_objv;
+ char org_ns_cmd_name = "__orig_namespace_command__";
+
+ DUMP1("call a native-object-proc for tcl8.6 or later");
+ cp_objv = RbTk_ALLOC_N(Tcl_Obj *, (objc + 1));
+
+ cp_objv[0] = Tcl_NewStringObj(org_ns_cmd_name, strlen(org_ns_cmd_name));
+ for(i = 1; i < objc; i++) {
+ cp_objv[i] = objv[i];
+ }
+ cp_objv[objc] = (Tcl_Obj *)NULL;
+
+ ret = Tcl_EvalObjv(interp, objc, cp_objv, TCL_EVAL_DIRECT);
+
+ ckfree((char*)cp_objv);
+#endif
} else {
/* string interface */
int i;
char **argv;
+ DUMP1("call with the string-interface");
/* argv = (char **)Tcl_Alloc(sizeof(char *) * (objc + 1)); */
argv = RbTk_ALLOC_N(char *, (objc + 1));
#if 0 /* use Tcl_Preserve/Release */
@@ -6056,9 +6083,10 @@
#endif
}
- /* DUMP2("namespace wrapper exit depth == %d", rbtk_eventloop_depth); */
+ DUMP2("namespace wrapper exit depth == %d", rbtk_eventloop_depth);
rbtk_eventloop_depth--;
+ DUMP1("end of ip_rbNamespaceObjCmd");
return ret;
}
#endif
@@ -6068,6 +6096,8 @@
Tcl_Interp *interp;
{
#if TCL_MAJOR_VERSION >= 8
+
+#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION < 6
Tcl_CmdInfo orig_info;
if (!Tcl_GetCommandInfo(interp, "namespace", &(orig_info))) {
@@ -6084,6 +6114,11 @@
orig_info.deleteProc);
}
+#else /* tcl8.6 or later */
+ Tcl_Eval(interp, "rename namespace __orig_namespace_command__");
+
+#endif
+
Tcl_CreateObjCommand(interp, "namespace", ip_rbNamespaceObjCmd,
(ClientData) 0, (Tcl_CmdDeleteProc *)NULL);
#endif
@@ -8454,9 +8489,12 @@
char **argv = (char **)NULL;
#endif
+ DUMP1("call invoke_tcl_proc");
+
/* memory allocation for arguments of this command */
#if TCL_MAJOR_VERSION >= 8
if (!inf->cmdinfo.isNativeObjectProc) {
+ DUMP1("called proc is not a native-obj-proc");
/* string interface */
/* argv = (char **)ALLOC_N(char *, argc+1);*/ /* XXXXXXXXXX */
argv = RbTk_ALLOC_N(char *, (argc+1));
@@ -8470,11 +8508,13 @@
}
#endif
+ DUMP1("reset result of tcl-interp");
Tcl_ResetResult(inf->ptr->ip);
/* Invoke the C procedure */
#if TCL_MAJOR_VERSION >= 8
if (inf->cmdinfo.isNativeObjectProc) {
+ DUMP1("call tcl_proc as a native-obj-proc");
inf->ptr->return_value
= (*(inf->cmdinfo.objProc))(inf->cmdinfo.objClientData,
inf->ptr->ip, inf->objc, inf->objv);
@@ -8483,6 +8523,7 @@
#endif
{
#if TCL_MAJOR_VERSION >= 8
+ DUMP1("call tcl_proc as not a native-obj-proc");
inf->ptr->return_value
= (*(inf->cmdinfo.proc))(inf->cmdinfo.clientData, inf->ptr->ip,
argc, (CONST84 char **)argv);
@@ -8505,6 +8546,7 @@
#endif
}
+ DUMP1("end of invoke_tcl_proc");
return Qnil;
}
@@ -8644,7 +8686,9 @@
#endif
/* invoke tcl-proc */
+ DUMP1("invoke tcl-proc");
rb_protect(invoke_tcl_proc, (VALUE)&inf, &status);
+ DUMP2("status of tcl-proc, %d", status);
switch(status) {
case TAG_RAISE:
if (NIL_P(rb_errinfo())) {
--------------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
Department of Artificial Intelligence, Kyushu Institute of Technology