1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Can't load Ruby dynamically on Unix.
12 Solution: Adjust the configure script. (James Vega)
13 Files: src/Makefile, src/config.h.in, src/configure.in,
14 src/auto/configure, src/if_ruby.c
17 *** ../vim-7.3.042/src/Makefile 2010-08-16 21:59:00.000000000 +0200
18 --- src/Makefile 2010-10-27 16:46:41.000000000 +0200
22 # However, this may still cause problems, such as "import termios" failing.
23 # Build two separate versions of Vim in that case.
24 #CONF_OPT_PYTHON = --enable-pythoninterp
25 + #CONF_OPT_PYTHON = --enable-pythoninterp=dynamic
26 #CONF_OPT_PYTHON3 = --enable-python3interp
27 + #CONF_OPT_PYTHON3 = --enable-python3interp=dynamic
30 # Uncomment this when you want to include the Ruby interface.
31 + # First one for static linking, second one for loading when used.
32 # Note: you need the development package (e.g., ruby1.9.1-dev on Ubuntu).
33 #CONF_OPT_RUBY = --enable-rubyinterp
34 + #CONF_OPT_RUBY = --enable-rubyinterp=dynamic
35 #CONF_OPT_RUBY = --enable-rubyinterp --with-ruby-command=ruby1.9.1
41 INSTALL_DATA_R = cp -r
43 ! ### Program to run on installed binary
46 ### Permissions for binaries {{{1
50 INSTALL_DATA_R = cp -r
52 ! ### Program to run on installed binary. Use the second one to disable strip.
56 ### Permissions for binaries {{{1
62 PRE_DEFS = -Iproto $(DEFS) $(GUI_DEFS) $(GUI_IPATH) $(CPPFLAGS) $(EXTRA_IPATHS)
63 ! POST_DEFS = $(X_CFLAGS) $(MZSCHEME_CFLAGS) $(TCL_CFLAGS) $(RUBY_CFLAGS) $(EXTRA_DEFS)
65 ALL_CFLAGS = $(PRE_DEFS) $(CFLAGS) $(PROFILE_CFLAGS) $(POST_DEFS)
70 PRE_DEFS = -Iproto $(DEFS) $(GUI_DEFS) $(GUI_IPATH) $(CPPFLAGS) $(EXTRA_IPATHS)
71 ! POST_DEFS = $(X_CFLAGS) $(MZSCHEME_CFLAGS) $(TCL_CFLAGS) $(EXTRA_DEFS)
73 ALL_CFLAGS = $(PRE_DEFS) $(CFLAGS) $(PROFILE_CFLAGS) $(POST_DEFS)
78 OSDEF_CFLAGS = $(PRE_DEFS) $(POST_DEFS)
80 ! LINT_CFLAGS = -DLINT -I. $(PRE_DEFS) $(POST_DEFS) $(LUA_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) -Dinline= -D__extension__= -Dalloca=alloca
82 LINT_EXTRA = -DUSE_SNIFF -DHANGUL_INPUT -D"__attribute__(x)="
86 OSDEF_CFLAGS = $(PRE_DEFS) $(POST_DEFS)
88 ! LINT_CFLAGS = -DLINT -I. $(PRE_DEFS) $(POST_DEFS) $(RUBY_CFLAGS) $(LUA_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) -Dinline= -D__extension__= -Dalloca=alloca
90 LINT_EXTRA = -DUSE_SNIFF -DHANGUL_INPUT -D"__attribute__(x)="
94 $(CCC) $(PYTHON3_CFLAGS) $(PYTHON3_CFLAGS_EXTRA) -o $@ if_python3.c
96 objects/if_ruby.o: if_ruby.c
97 ! $(CCC) -o $@ if_ruby.c
99 objects/if_sniff.o: if_sniff.c
100 $(CCC) -o $@ if_sniff.c
102 $(CCC) $(PYTHON3_CFLAGS) $(PYTHON3_CFLAGS_EXTRA) -o $@ if_python3.c
104 objects/if_ruby.o: if_ruby.c
105 ! $(CCC) $(RUBY_CFLAGS) -o $@ if_ruby.c
107 objects/if_sniff.o: if_sniff.c
108 $(CCC) -o $@ if_sniff.c
109 *** ../vim-7.3.042/src/config.h.in 2010-08-15 21:57:32.000000000 +0200
110 --- src/config.h.in 2010-10-27 16:21:24.000000000 +0200
114 /* Define if you want to include the Ruby interpreter. */
117 + /* Define for linking via dlopen() or LoadLibrary() */
118 + #undef DYNAMIC_RUBY
120 /* Define if you want to include the Tcl interpreter. */
123 *** ../vim-7.3.042/src/configure.in 2010-08-15 21:57:28.000000000 +0200
124 --- src/configure.in 2010-10-27 16:20:53.000000000 +0200
128 AC_MSG_CHECKING(--enable-rubyinterp argument)
129 AC_ARG_ENABLE(rubyinterp,
130 ! [ --enable-rubyinterp Include Ruby interpreter.], ,
131 [enable_rubyinterp="no"])
132 AC_MSG_RESULT($enable_rubyinterp)
133 ! if test "$enable_rubyinterp" = "yes"; then
134 AC_MSG_CHECKING(--with-ruby-command argument)
135 AC_ARG_WITH(ruby-command, [ --with-ruby-command=RUBY name of the Ruby command (default: ruby)],
136 RUBY_CMD="$withval"; AC_MSG_RESULT($RUBY_CMD),
139 AC_MSG_CHECKING(--enable-rubyinterp argument)
140 AC_ARG_ENABLE(rubyinterp,
141 ! [ --enable-rubyinterp[=OPTS] Include Ruby interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
142 [enable_rubyinterp="no"])
143 AC_MSG_RESULT($enable_rubyinterp)
144 ! if test "$enable_rubyinterp" = "yes" -o "$enable_rubyinterp" = "dynamic"; then
145 AC_MSG_CHECKING(--with-ruby-command argument)
146 AC_ARG_WITH(ruby-command, [ --with-ruby-command=RUBY name of the Ruby command (default: ruby)],
147 RUBY_CMD="$withval"; AC_MSG_RESULT($RUBY_CMD),
151 RUBY_OBJ="objects/if_ruby.o"
152 RUBY_PRO="if_ruby.pro"
154 + if test "$enable_rubyinterp" = "dynamic"; then
155 + libruby=`$vi_cv_path_ruby -r rbconfig -e 'printf "lib%s.%s\n", Config::CONFIG[["RUBY_SO_NAME"]], Config::CONFIG[["DLEXT"]]'`
156 + AC_DEFINE(DYNAMIC_RUBY)
157 + RUBY_CFLAGS="-DDYNAMIC_RUBY_DLL=\\\"$libruby\\\" -DDYNAMIC_RUBY_VER=$rubyversion $RUBY_CFLAGS"
161 AC_MSG_RESULT(not found; disabling Ruby)
163 *** ../vim-7.3.042/src/auto/configure 2010-08-15 21:57:27.000000000 +0200
164 --- src/auto/configure 2010-10-27 16:28:10.000000000 +0200
167 --enable-pythoninterp=OPTS Include Python interpreter. default=no OPTS=no/yes/dynamic
168 --enable-python3interp=OPTS Include Python3 interpreter. default=no OPTS=no/yes/dynamic
169 --enable-tclinterp Include Tcl interpreter.
170 ! --enable-rubyinterp Include Ruby interpreter.
171 --enable-cscope Include cscope interface.
172 --enable-workshop Include Sun Visual Workshop support.
173 --disable-netbeans Disable NetBeans integration support.
175 --enable-pythoninterp=OPTS Include Python interpreter. default=no OPTS=no/yes/dynamic
176 --enable-python3interp=OPTS Include Python3 interpreter. default=no OPTS=no/yes/dynamic
177 --enable-tclinterp Include Tcl interpreter.
178 ! --enable-rubyinterp=OPTS Include Ruby interpreter. default=no OPTS=no/yes/dynamic
179 --enable-cscope Include cscope interface.
180 --enable-workshop Include Sun Visual Workshop support.
181 --disable-netbeans Disable NetBeans integration support.
185 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_rubyinterp" >&5
186 $as_echo "$enable_rubyinterp" >&6; }
187 ! if test "$enable_rubyinterp" = "yes"; then
188 { $as_echo "$as_me:${as_lineno-$LINENO}: checking --with-ruby-command argument" >&5
189 $as_echo_n "checking --with-ruby-command argument... " >&6; }
193 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_rubyinterp" >&5
194 $as_echo "$enable_rubyinterp" >&6; }
195 ! if test "$enable_rubyinterp" = "yes" -o "$enable_rubyinterp" = "dynamic"; then
196 { $as_echo "$as_me:${as_lineno-$LINENO}: checking --with-ruby-command argument" >&5
197 $as_echo_n "checking --with-ruby-command argument... " >&6; }
202 RUBY_PRO="if_ruby.pro"
203 $as_echo "#define FEAT_RUBY 1" >>confdefs.h
205 + if test "$enable_rubyinterp" = "dynamic"; then
206 + libruby=`$vi_cv_path_ruby -r rbconfig -e 'printf "lib%s.%s\n", Config::CONFIG["RUBY_SO_NAME"], Config::CONFIG["DLEXT"]'`
207 + $as_echo "#define DYNAMIC_RUBY 1" >>confdefs.h
209 + RUBY_CFLAGS="-DDYNAMIC_RUBY_DLL=\\\"$libruby\\\" -DDYNAMIC_RUBY_VER=$rubyversion $RUBY_CFLAGS"
213 { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found; disabling Ruby" >&5
214 $as_echo "not found; disabling Ruby" >&6; }
215 *** ../vim-7.3.042/src/if_ruby.c 2010-10-23 14:02:48.000000000 +0200
216 --- src/if_ruby.c 2010-10-27 16:40:27.000000000 +0200
223 + #include "auto/config.h"
226 # if !defined(DYNAMIC_RUBY_VER) || (DYNAMIC_RUBY_VER < 18)
233 ! #if !(defined(WIN32) || defined(_WIN64))
235 ! # define HANDLE void*
236 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
237 # define symbol_from_dll dlsym
238 # define close_dll dlclose
240 # define load_dll vimLoadLib
241 # define symbol_from_dll GetProcAddress
242 # define close_dll FreeLibrary
249 ! # define HINSTANCE void*
250 ! # define RUBY_PROC void*
251 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
252 # define symbol_from_dll dlsym
253 # define close_dll dlclose
255 + # define RUBY_PROC FARPROC
256 # define load_dll vimLoadLib
257 # define symbol_from_dll GetProcAddress
258 # define close_dll FreeLibrary
262 #define rb_lastline_get dll_rb_lastline_get
263 #define rb_lastline_set dll_rb_lastline_set
264 #define rb_load_protect dll_rb_load_protect
265 + #ifndef RUBY19_OR_LATER
266 #define rb_num2long dll_rb_num2long
268 #define rb_num2ulong dll_rb_num2ulong
269 #define rb_obj_alloc dll_rb_obj_alloc
270 #define rb_obj_as_string dll_rb_obj_as_string
275 /* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */
276 # define need_rb_str_new_cstr 1
277 + /* Ruby's headers #define rb_str_new_cstr to make use of GCC's
278 + * __builtin_constant_p extension. */
279 + # undef rb_str_new_cstr
280 # define rb_str_new_cstr dll_rb_str_new_cstr
282 # define rb_str_new2 dll_rb_str_new2
286 #define ruby_init dll_ruby_init
287 #define ruby_init_loadpath dll_ruby_init_loadpath
288 ! #define NtInitialize dll_NtInitialize
289 ! #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
290 ! # define rb_w32_snprintf dll_rb_w32_snprintf
293 #ifdef RUBY19_OR_LATER
296 #define ruby_init dll_ruby_init
297 #define ruby_init_loadpath dll_ruby_init_loadpath
299 ! # define NtInitialize dll_NtInitialize
300 ! # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
301 ! # define rb_w32_snprintf dll_rb_w32_snprintf
305 #ifdef RUBY19_OR_LATER
310 static void (*dll_ruby_init) (void);
311 static void (*dll_ruby_init_loadpath) (void);
313 static void (*dll_NtInitialize) (int*, char***);
314 + # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
315 + static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
318 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
319 static char * (*dll_rb_string_value_ptr) (volatile VALUE*);
320 static VALUE (*dll_rb_float_new) (double);
323 #ifdef RUBY19_OR_LATER
324 static VALUE (*dll_rb_int2big)(SIGNED_VALUE);
326 - #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
327 - static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
330 #ifdef RUBY19_OR_LATER
331 static void (*dll_ruby_script) (const char*);
338 ! static HINSTANCE hinstRuby = 0; /* Instance of ruby.dll */
341 * Table of name to function pointer of ruby.
343 - #define RUBY_PROC FARPROC
351 ! static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */
354 * Table of name to function pointer of ruby.
362 {"ruby_init", (RUBY_PROC*)&dll_ruby_init},
363 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath},
365 ! #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 19
370 (RUBY_PROC*)&dll_NtInitialize},
371 ! #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
372 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf},
374 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
375 {"rb_string_value_ptr", (RUBY_PROC*)&dll_rb_string_value_ptr},
378 {"ruby_init", (RUBY_PROC*)&dll_ruby_init},
379 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath},
382 ! # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 19
387 (RUBY_PROC*)&dll_NtInitialize},
388 ! # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
389 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf},
392 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
393 {"rb_string_value_ptr", (RUBY_PROC*)&dll_rb_string_value_ptr},
398 close_dll(hinstRuby);
406 close_dll(hinstRuby);
413 ruby_funcname_table[i].name)))
415 close_dll(hinstRuby);
418 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
421 ruby_funcname_table[i].name)))
423 close_dll(hinstRuby);
426 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
430 return line ? vim_str2rb_enc_str(line) : Qnil;
432 rb_raise(rb_eIndexError, "line number %ld out of range", (long)n);
434 return Qnil; /* For stop warning */
438 static VALUE buffer_aref(VALUE self, VALUE num)
440 *** ../vim-7.3.042/src/version.c 2010-10-27 16:17:56.000000000 +0200
441 --- src/version.c 2010-10-27 16:45:28.000000000 +0200
445 { /* Add new patch number below this line */
451 ARTHUR: A scratch? Your arm's off!
452 BLACK KNIGHT: No, it isn't.
453 ARTHUR: Well, what's that then?
454 BLACK KNIGHT: I've had worse.
455 The Quest for the Holy Grail (Monty Python)
457 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
458 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
459 \\\ download, build and distribute -- http://www.A-A-P.org ///
460 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///