4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Dynamic loading with Ruby doesn't work for 1.9.2.
12 Solution: Handle rb_str2cstr differently. Also support dynamic loading on
17 *** ../vim-7.3.012/src/if_ruby.c 2010-08-15 21:57:25.000000000 +0200
18 --- src/if_ruby.c 2010-09-29 12:49:50.000000000 +0200
23 * Ruby interface by Shugo Maeda
24 * with improvements by SegPhault (Ryan Paul)
25 + * with improvements by Jon Maken
27 * Do ":help uganda" in Vim to read copying and usage conditions.
28 * Do ":help credits" in Vim to see a list of people who contributed.
31 # define RUBYEXTERN extern
35 * This is tricky. In ruby.h there is (inline) function rb_class_of()
36 * definition. This function use these variables. But we want function to
37 * use dll_* variables.
40 # define rb_cFalseClass (*dll_rb_cFalseClass)
41 # define rb_cFixnum (*dll_rb_cFixnum)
42 # define rb_cNilClass (*dll_rb_cNilClass)
44 # define RUBYEXTERN extern
49 * This is tricky. In ruby.h there is (inline) function rb_class_of()
50 * definition. This function use these variables. But we want function to
51 * use dll_* variables.
53 # define rb_cFalseClass (*dll_rb_cFalseClass)
54 # define rb_cFixnum (*dll_rb_cFixnum)
55 # define rb_cNilClass (*dll_rb_cNilClass)
63 + #if !(defined(WIN32) || defined(_WIN64))
65 + # define HANDLE void*
66 + # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
67 + # define symbol_from_dll dlsym
68 + # define close_dll dlclose
70 + # define load_dll LoadLibrary
71 + # define symbol_from_dll GetProcAddress
72 + # define close_dll FreeLibrary
75 + #endif /* ifdef DYNAMIC_RUBY */
77 /* suggested by Ariya Mizutani */
78 #if (_MSC_VER == 1200)
82 #define rb_obj_as_string dll_rb_obj_as_string
83 #define rb_obj_id dll_rb_obj_id
84 #define rb_raise dll_rb_raise
85 - #define rb_str2cstr dll_rb_str2cstr
86 #define rb_str_cat dll_rb_str_cat
87 #define rb_str_concat dll_rb_str_concat
88 #define rb_str_new dll_rb_str_new
93 # define rb_str_new2 dll_rb_str_new2
95 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
96 + # define rb_string_value dll_rb_string_value
97 # define rb_string_value_ptr dll_rb_string_value_ptr
98 # define rb_float_new dll_rb_float_new
99 # define rb_ary_new dll_rb_ary_new
100 # define rb_ary_push dll_rb_ary_push
102 + # define rb_str2cstr dll_rb_str2cstr
104 #ifdef RUBY19_OR_LATER
105 # define rb_errinfo dll_rb_errinfo
109 static VALUE (*dll_rb_obj_as_string) (VALUE);
110 static VALUE (*dll_rb_obj_id) (VALUE);
111 static void (*dll_rb_raise) (VALUE, const char*, ...);
112 + #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
113 + static VALUE (*dll_rb_string_value) (volatile VALUE*);
115 static char *(*dll_rb_str2cstr) (VALUE,int*);
117 static VALUE (*dll_rb_str_cat) (VALUE, const char*, long);
118 static VALUE (*dll_rb_str_concat) (VALUE, VALUE);
119 static VALUE (*dll_rb_str_new) (const char*, long);
123 {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string},
124 {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id},
125 {"rb_raise", (RUBY_PROC*)&dll_rb_raise},
126 + #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
127 + {"rb_string_value", (RUBY_PROC*)&dll_rb_string_value},
129 {"rb_str2cstr", (RUBY_PROC*)&dll_rb_str2cstr},
131 {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat},
132 {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat},
133 {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new},
139 ! FreeLibrary(hinstRuby);
147 ! close_dll(hinstRuby);
156 ! hinstRuby = LoadLibrary(libname);
164 ! hinstRuby = load_dll(libname);
171 for (i = 0; ruby_funcname_table[i].ptr; ++i)
173 ! if (!(*ruby_funcname_table[i].ptr = GetProcAddress(hinstRuby,
174 ruby_funcname_table[i].name)))
176 ! FreeLibrary(hinstRuby);
179 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
182 for (i = 0; ruby_funcname_table[i].ptr; ++i)
184 ! if (!(*ruby_funcname_table[i].ptr = symbol_from_dll(hinstRuby,
185 ruby_funcname_table[i].name)))
187 ! close_dll(hinstRuby);
190 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
191 *** ../vim-7.3.012/src/version.c 2010-09-29 12:37:53.000000000 +0200
192 --- src/version.c 2010-09-29 13:00:42.000000000 +0200
196 { /* Add new patch number below this line */
202 hundred-and-one symptoms of being an internet addict:
203 223. You set up a web-cam as your home's security system.
205 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
206 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
207 \\\ download, build and distribute -- http://www.A-A-P.org ///
208 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///