Karsten Hopp 487812
To: vim-dev@vim.org
Karsten Hopp 487812
Subject: Patch 7.3.013
Karsten Hopp 487812
Fcc: outbox
Karsten Hopp 487812
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 487812
Mime-Version: 1.0
Karsten Hopp 487812
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 487812
Content-Transfer-Encoding: 8bit
Karsten Hopp 487812
------------
Karsten Hopp 487812
Karsten Hopp 487812
Patch 7.3.013
Karsten Hopp 487812
Problem:    Dynamic loading with Ruby doesn't work for 1.9.2.
Karsten Hopp 487812
Solution:   Handle rb_str2cstr differently.  Also support dynamic loading on
Karsten Hopp 487812
	    Unix. (Jon Maken)
Karsten Hopp 487812
Files:	    src/if_ruby.c
Karsten Hopp 487812
Karsten Hopp 487812
Karsten Hopp 487812
*** ../vim-7.3.012/src/if_ruby.c	2010-08-15 21:57:25.000000000 +0200
Karsten Hopp 487812
--- src/if_ruby.c	2010-09-29 12:49:50.000000000 +0200
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 4,9 ****
Karsten Hopp 487812
--- 4,10 ----
Karsten Hopp 487812
   *
Karsten Hopp 487812
   * Ruby interface by Shugo Maeda
Karsten Hopp 487812
   *   with improvements by SegPhault (Ryan Paul)
Karsten Hopp 487812
+  *   with improvements by Jon Maken
Karsten Hopp 487812
   *
Karsten Hopp 487812
   * Do ":help uganda"  in Vim to read copying and usage conditions.
Karsten Hopp 487812
   * Do ":help credits" in Vim to see a list of people who contributed.
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 26,37 ****
Karsten Hopp 487812
  # define RUBYEXTERN extern
Karsten Hopp 487812
  #endif
Karsten Hopp 487812
  
Karsten Hopp 487812
  /*
Karsten Hopp 487812
   * This is tricky.  In ruby.h there is (inline) function rb_class_of()
Karsten Hopp 487812
   * definition.  This function use these variables.  But we want function to
Karsten Hopp 487812
   * use dll_* variables.
Karsten Hopp 487812
   */
Karsten Hopp 487812
- #ifdef DYNAMIC_RUBY
Karsten Hopp 487812
  # define rb_cFalseClass		(*dll_rb_cFalseClass)
Karsten Hopp 487812
  # define rb_cFixnum		(*dll_rb_cFixnum)
Karsten Hopp 487812
  # define rb_cNilClass		(*dll_rb_cNilClass)
Karsten Hopp 487812
--- 27,38 ----
Karsten Hopp 487812
  # define RUBYEXTERN extern
Karsten Hopp 487812
  #endif
Karsten Hopp 487812
  
Karsten Hopp 487812
+ #ifdef DYNAMIC_RUBY
Karsten Hopp 487812
  /*
Karsten Hopp 487812
   * This is tricky.  In ruby.h there is (inline) function rb_class_of()
Karsten Hopp 487812
   * definition.  This function use these variables.  But we want function to
Karsten Hopp 487812
   * use dll_* variables.
Karsten Hopp 487812
   */
Karsten Hopp 487812
  # define rb_cFalseClass		(*dll_rb_cFalseClass)
Karsten Hopp 487812
  # define rb_cFixnum		(*dll_rb_cFixnum)
Karsten Hopp 487812
  # define rb_cNilClass		(*dll_rb_cNilClass)
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 46,53 ****
Karsten Hopp 487812
--- 47,67 ----
Karsten Hopp 487812
   */
Karsten Hopp 487812
  #  define RUBY_EXPORT
Karsten Hopp 487812
  # endif
Karsten Hopp 487812
+ 
Karsten Hopp 487812
+ #if !(defined(WIN32) || defined(_WIN64))
Karsten Hopp 487812
+ # include <dlfcn.h>
Karsten Hopp 487812
+ # define HANDLE void*
Karsten Hopp 487812
+ # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
Karsten Hopp 487812
+ # define symbol_from_dll dlsym
Karsten Hopp 487812
+ # define close_dll dlclose
Karsten Hopp 487812
+ #else
Karsten Hopp 487812
+ # define load_dll LoadLibrary
Karsten Hopp 487812
+ # define symbol_from_dll GetProcAddress
Karsten Hopp 487812
+ # define close_dll FreeLibrary
Karsten Hopp 487812
  #endif
Karsten Hopp 487812
  
Karsten Hopp 487812
+ #endif  /* ifdef DYNAMIC_RUBY */
Karsten Hopp 487812
+ 
Karsten Hopp 487812
  /* suggested by Ariya Mizutani */
Karsten Hopp 487812
  #if (_MSC_VER == 1200)
Karsten Hopp 487812
  # undef _WIN32_WINNT
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 166,172 ****
Karsten Hopp 487812
  #define rb_obj_as_string		dll_rb_obj_as_string
Karsten Hopp 487812
  #define rb_obj_id			dll_rb_obj_id
Karsten Hopp 487812
  #define rb_raise			dll_rb_raise
Karsten Hopp 487812
- #define rb_str2cstr			dll_rb_str2cstr
Karsten Hopp 487812
  #define rb_str_cat			dll_rb_str_cat
Karsten Hopp 487812
  #define rb_str_concat			dll_rb_str_concat
Karsten Hopp 487812
  #define rb_str_new			dll_rb_str_new
Karsten Hopp 487812
--- 180,185 ----
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 178,187 ****
Karsten Hopp 487812
--- 191,203 ----
Karsten Hopp 487812
  # define rb_str_new2			dll_rb_str_new2
Karsten Hopp 487812
  #endif
Karsten Hopp 487812
  #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
Karsten Hopp 487812
+ # define rb_string_value		dll_rb_string_value
Karsten Hopp 487812
  # define rb_string_value_ptr		dll_rb_string_value_ptr
Karsten Hopp 487812
  # define rb_float_new			dll_rb_float_new
Karsten Hopp 487812
  # define rb_ary_new			dll_rb_ary_new
Karsten Hopp 487812
  # define rb_ary_push			dll_rb_ary_push
Karsten Hopp 487812
+ #else
Karsten Hopp 487812
+ # define rb_str2cstr			dll_rb_str2cstr
Karsten Hopp 487812
  #endif
Karsten Hopp 487812
  #ifdef RUBY19_OR_LATER
Karsten Hopp 487812
  # define rb_errinfo			dll_rb_errinfo
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 246,252 ****
Karsten Hopp 487812
--- 262,272 ----
Karsten Hopp 487812
  static VALUE (*dll_rb_obj_as_string) (VALUE);
Karsten Hopp 487812
  static VALUE (*dll_rb_obj_id) (VALUE);
Karsten Hopp 487812
  static void (*dll_rb_raise) (VALUE, const char*, ...);
Karsten Hopp 487812
+ #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
Karsten Hopp 487812
+ static VALUE (*dll_rb_string_value) (volatile VALUE*);
Karsten Hopp 487812
+ #else
Karsten Hopp 487812
  static char *(*dll_rb_str2cstr) (VALUE,int*);
Karsten Hopp 487812
+ #endif
Karsten Hopp 487812
  static VALUE (*dll_rb_str_cat) (VALUE, const char*, long);
Karsten Hopp 487812
  static VALUE (*dll_rb_str_concat) (VALUE, VALUE);
Karsten Hopp 487812
  static VALUE (*dll_rb_str_new) (const char*, long);
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 347,353 ****
Karsten Hopp 487812
--- 367,377 ----
Karsten Hopp 487812
      {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string},
Karsten Hopp 487812
      {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id},
Karsten Hopp 487812
      {"rb_raise", (RUBY_PROC*)&dll_rb_raise},
Karsten Hopp 487812
+ #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
Karsten Hopp 487812
+     {"rb_string_value", (RUBY_PROC*)&dll_rb_string_value},
Karsten Hopp 487812
+ #else
Karsten Hopp 487812
      {"rb_str2cstr", (RUBY_PROC*)&dll_rb_str2cstr},
Karsten Hopp 487812
+ #endif
Karsten Hopp 487812
      {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat},
Karsten Hopp 487812
      {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat},
Karsten Hopp 487812
      {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new},
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 399,405 ****
Karsten Hopp 487812
  {
Karsten Hopp 487812
      if (hinstRuby)
Karsten Hopp 487812
      {
Karsten Hopp 487812
! 	FreeLibrary(hinstRuby);
Karsten Hopp 487812
  	hinstRuby = 0;
Karsten Hopp 487812
      }
Karsten Hopp 487812
  }
Karsten Hopp 487812
--- 423,429 ----
Karsten Hopp 487812
  {
Karsten Hopp 487812
      if (hinstRuby)
Karsten Hopp 487812
      {
Karsten Hopp 487812
! 	close_dll(hinstRuby);
Karsten Hopp 487812
  	hinstRuby = 0;
Karsten Hopp 487812
      }
Karsten Hopp 487812
  }
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 416,422 ****
Karsten Hopp 487812
  
Karsten Hopp 487812
      if (hinstRuby)
Karsten Hopp 487812
  	return OK;
Karsten Hopp 487812
!     hinstRuby = LoadLibrary(libname);
Karsten Hopp 487812
      if (!hinstRuby)
Karsten Hopp 487812
      {
Karsten Hopp 487812
  	if (verbose)
Karsten Hopp 487812
--- 440,446 ----
Karsten Hopp 487812
  
Karsten Hopp 487812
      if (hinstRuby)
Karsten Hopp 487812
  	return OK;
Karsten Hopp 487812
!     hinstRuby = load_dll(libname);
Karsten Hopp 487812
      if (!hinstRuby)
Karsten Hopp 487812
      {
Karsten Hopp 487812
  	if (verbose)
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 426,435 ****
Karsten Hopp 487812
  
Karsten Hopp 487812
      for (i = 0; ruby_funcname_table[i].ptr; ++i)
Karsten Hopp 487812
      {
Karsten Hopp 487812
! 	if (!(*ruby_funcname_table[i].ptr = GetProcAddress(hinstRuby,
Karsten Hopp 487812
  			ruby_funcname_table[i].name)))
Karsten Hopp 487812
  	{
Karsten Hopp 487812
! 	    FreeLibrary(hinstRuby);
Karsten Hopp 487812
  	    hinstRuby = 0;
Karsten Hopp 487812
  	    if (verbose)
Karsten Hopp 487812
  		EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
Karsten Hopp 487812
--- 450,459 ----
Karsten Hopp 487812
  
Karsten Hopp 487812
      for (i = 0; ruby_funcname_table[i].ptr; ++i)
Karsten Hopp 487812
      {
Karsten Hopp 487812
! 	if (!(*ruby_funcname_table[i].ptr = symbol_from_dll(hinstRuby,
Karsten Hopp 487812
  			ruby_funcname_table[i].name)))
Karsten Hopp 487812
  	{
Karsten Hopp 487812
! 	    close_dll(hinstRuby);
Karsten Hopp 487812
  	    hinstRuby = 0;
Karsten Hopp 487812
  	    if (verbose)
Karsten Hopp 487812
  		EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
Karsten Hopp 487812
*** ../vim-7.3.012/src/version.c	2010-09-29 12:37:53.000000000 +0200
Karsten Hopp 487812
--- src/version.c	2010-09-29 13:00:42.000000000 +0200
Karsten Hopp 487812
***************
Karsten Hopp 487812
*** 716,717 ****
Karsten Hopp 487812
--- 716,719 ----
Karsten Hopp 487812
  {   /* Add new patch number below this line */
Karsten Hopp 487812
+ /**/
Karsten Hopp 487812
+     13,
Karsten Hopp 487812
  /**/
Karsten Hopp 487812
Karsten Hopp 487812
-- 
Karsten Hopp 487812
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 487812
223. You set up a web-cam as your home's security system.
Karsten Hopp 487812
Karsten Hopp 487812
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 487812
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 487812
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 487812
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///