summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authoreban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-08-08 05:06:24 +0000
committereban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-08-08 05:06:24 +0000
commitce799ec3eabd2437e7cc7c64580668d239e74b7a (patch)
tree91b13ae1c00a67138eaba842466d59be9d83abb2 /ext
parent5093c0496e4ddbb86d5a190163f54b21a4b60e39 (diff)
eban
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/tcltklib/MANIFEST1
-rw-r--r--ext/tcltklib/extconf.rb16
-rw-r--r--ext/tcltklib/stubs.c86
-rw-r--r--ext/tcltklib/tcltklib.c7
4 files changed, 103 insertions, 7 deletions
diff --git a/ext/tcltklib/MANIFEST b/ext/tcltklib/MANIFEST
index b5e8827..4e37fb9 100644
--- a/ext/tcltklib/MANIFEST
+++ b/ext/tcltklib/MANIFEST
@@ -2,6 +2,7 @@ MANIFEST
README.euc
MANUAL.euc
tcltklib.c
+stubs.c
depend
extconf.rb
lib/tcltk.rb
diff --git a/ext/tcltklib/extconf.rb b/ext/tcltklib/extconf.rb
index 5f56d42..acc75b8 100644
--- a/ext/tcltklib/extconf.rb
+++ b/ext/tcltklib/extconf.rb
@@ -2,7 +2,7 @@
require 'mkmf'
-if RUBY_PLATFORM !~ /mswin32|mingw/
+if RUBY_PLATFORM !~ /mswin32|mingw|cygwin/
have_library("nsl", "t_open")
have_library("socket", "socket")
have_library("dl", "dlopen")
@@ -15,10 +15,11 @@ dir_config("X11")
tklib = with_config("tklib")
tcllib = with_config("tcllib")
+stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs")
-def find_tcl(tcllib)
+def find_tcl(tcllib, stubs)
paths = ["/usr/local/lib", "/usr/pkg"]
- func = "Tcl_FindExecutable"
+ func = stubs ? "Tcl_InitStubs" : "Tcl_FindExecutable"
if tcllib
find_library(tcllib, func, *paths)
else
@@ -30,9 +31,9 @@ def find_tcl(tcllib)
end
end
-def find_tk(tklib)
+def find_tk(tklib, stubs)
paths = ["/usr/local/lib", "/usr/pkg"]
- func = "Tk_Init"
+ func = stubs ? "Tk_InitStubs" : "Tk_Init"
if tklib
find_library(tklib, func, *paths)
else
@@ -47,7 +48,8 @@ end
if have_header("tcl.h") && have_header("tk.h") &&
(/mswin32|mingw|cygwin/ =~ RUBY_PLATFORM || find_library("X11", "XOpenDisplay",
"/usr/X11/lib", "/usr/X11R6/lib", "/usr/openwin/lib")) &&
- find_tcl(tcllib) &&
- find_tk(tklib)
+ find_tcl(tcllib, stubs) &&
+ find_tk(tklib, stubs)
+ $CFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs
create_makefile("tcltklib")
end
diff --git a/ext/tcltklib/stubs.c b/ext/tcltklib/stubs.c
new file mode 100644
index 0000000..537ca74
--- /dev/null
+++ b/ext/tcltklib/stubs.c
@@ -0,0 +1,86 @@
+#if defined USE_TCL_STUBS && defined USE_TK_STUBS
+#include <tcl.h>
+#include <tk.h>
+#include "ruby.h"
+
+#if defined _WIN32
+# include <windows.h>
+ typedef HINSTANCE DL_HANDLE;
+# define DL_OPEN LoadLibrary
+# define DL_SYM GetProcAddress
+# define TCL_INDEX 4
+# define TK_INDEX 3
+# define TCL_NAME "tcl89%s"
+# define TK_NAME "tk89%s"
+# undef DLEXT
+# define DLEXT ".dll"
+#elif defined HAVE_DLOPEN
+# include <dlfcn.h>
+ typedef void *DL_HANDLE;
+# define DL_OPEN(file) dlopen(file, RTLD_LAZY|RTLD_GLOBAL)
+# define DL_SYM dlsym
+# define TCL_INDEX 8
+# define TK_INDEX 7
+# define TCL_NAME "libtcl8.9%s"
+# define TK_NAME "libtk8.9%s"
+#endif
+
+int
+ruby_tcltk_stubs()
+{
+ DL_HANDLE tcl_dll;
+ DL_HANDLE tk_dll;
+ Tcl_Interp *(*p_Tcl_CreateInterp)();
+ int (*p_Tk_Init) _((Tcl_Interp *));
+ Tcl_Interp *tcl_ip;
+ int n;
+ char *ruby_tcl_dll;
+ char *ruby_tk_dll;
+ char tcl_name[20];
+ char tk_name[20];
+
+ ruby_tcl_dll = getenv("RUBY_TCL_DLL");
+ ruby_tk_dll = getenv("RUBY_TK_DLL");
+ if (ruby_tcl_dll && ruby_tk_dll) {
+ tcl_dll = (DL_HANDLE)DL_OPEN(ruby_tcl_dll);
+ tk_dll = (DL_HANDLE)DL_OPEN(ruby_tk_dll);
+ } else {
+ snprintf(tcl_name, sizeof tcl_name, TCL_NAME, DLEXT);
+ snprintf(tk_name, sizeof tk_name, TK_NAME, DLEXT);
+ /* examin from 8.9 to 8.1 */
+ for (n = '9'; n > '0'; n--) {
+ tcl_name[TCL_INDEX] = n;
+ tk_name[TK_INDEX] = n;
+ tcl_dll = (DL_HANDLE)DL_OPEN(tcl_name);
+ tk_dll = (DL_HANDLE)DL_OPEN(tk_name);
+ if (tcl_dll && tk_dll)
+ break;
+ }
+ }
+
+ if (!tcl_dll || !tk_dll)
+ return -1;
+
+ p_Tcl_CreateInterp = (Tcl_Interp *(*)())DL_SYM(tcl_dll, "Tcl_CreateInterp");
+ if (!p_Tcl_CreateInterp)
+ return -2;
+
+ tcl_ip = (*p_Tcl_CreateInterp)();
+ if (!tcl_ip)
+ return -3;
+
+ p_Tk_Init = (int (*) _((Tcl_Interp *)))DL_SYM(tk_dll, "Tk_Init");
+ if (!p_Tk_Init)
+ return -4;
+ (*p_Tk_Init)(tcl_ip);
+
+ if (!Tcl_InitStubs(tcl_ip, "8.1", 0))
+ return -5;
+ if (!Tk_InitStubs(tcl_ip, "8.1", 0))
+ return -6;
+
+ Tcl_DeleteInterp(tcl_ip);
+
+ return 0;
+}
+#endif
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
index f2e4a22..b0a4880 100644
--- a/ext/tcltklib/tcltklib.c
+++ b/ext/tcltklib/tcltklib.c
@@ -493,6 +493,13 @@ Init_tcltklib()
VALUE lib = rb_define_module("TclTkLib");
VALUE ip = rb_define_class("TclTkIp", rb_cObject);
+#if defined USE_TCL_STUBS && defined USE_TK_STUBS
+ extern int ruby_tcltk_stubs();
+ int ret = ruby_tcltk_stubs();
+ if (ret)
+ rb_raise(rb_eLoadError, "tcltklib: tcltk_stubs init error(%d)", ret);
+#endif
+
eTkCallbackBreak = rb_define_class("TkCallbackBreak", rb_eStandardError);
eTkCallbackContinue = rb_define_class("TkCallbackContinue",rb_eStandardError);