bb6a72a
To: vim-dev@vim.org
bb6a72a
Subject: Patch 7.2.361
bb6a72a
Fcc: outbox
bb6a72a
From: Bram Moolenaar <Bram@moolenaar.net>
bb6a72a
Mime-Version: 1.0
bb6a72a
Content-Type: text/plain; charset=UTF-8
bb6a72a
Content-Transfer-Encoding: 8bit
bb6a72a
------------
bb6a72a
bb6a72a
Patch 7.2.361
bb6a72a
Problem:    Ruby 1.9 is not supported.
bb6a72a
Solution:   Add Ruby 1.9 support. (Msaki Suketa)
bb6a72a
Files:	    src/Makefile, src/auto/configure, src/configure.in, src/if_ruby.c
bb6a72a
bb6a72a
bb6a72a
*** ../vim-7.2.360/src/Makefile	2010-02-17 15:12:22.000000000 +0100
bb6a72a
--- src/Makefile	2010-02-17 16:21:01.000000000 +0100
bb6a72a
***************
bb6a72a
*** 395,401 ****
bb6a72a
  
bb6a72a
  # RUBY
bb6a72a
  # Uncomment this when you want to include the Ruby interface.
bb6a72a
! #CONF_OPT_RUBY = --enable-rubyinterp
bb6a72a
  
bb6a72a
  # MZSCHEME
bb6a72a
  # Uncomment this when you want to include the MzScheme interface.
bb6a72a
--- 395,403 ----
bb6a72a
  
bb6a72a
  # RUBY
bb6a72a
  # Uncomment this when you want to include the Ruby interface.
bb6a72a
! # Note: you need the development package (e.g., ruby1.9.1-dev on Ubuntu).
bb6a72a
! # CONF_OPT_RUBY = --enable-rubyinterp
bb6a72a
! # CONF_OPT_RUBY = --enable-rubyinterp --with-ruby-command=ruby1.9.1
bb6a72a
  
bb6a72a
  # MZSCHEME
bb6a72a
  # Uncomment this when you want to include the MzScheme interface.
bb6a72a
*** ../vim-7.2.360/src/auto/configure	2009-12-16 17:14:08.000000000 +0100
bb6a72a
--- src/auto/configure	2010-02-17 16:08:59.000000000 +0100
bb6a72a
***************
bb6a72a
*** 793,798 ****
bb6a72a
--- 793,799 ----
bb6a72a
  enable_tclinterp
bb6a72a
  with_tclsh
bb6a72a
  enable_rubyinterp
bb6a72a
+ with_ruby_command
bb6a72a
  enable_cscope
bb6a72a
  enable_workshop
bb6a72a
  enable_netbeans
bb6a72a
***************
bb6a72a
*** 1503,1508 ****
bb6a72a
--- 1504,1510 ----
bb6a72a
    --with-plthome=PLTHOME   Use PLTHOME.
bb6a72a
    --with-python-config-dir=PATH  Python's config directory
bb6a72a
    --with-tclsh=PATH       which tclsh to use (default: tclsh8.0)
bb6a72a
+   --with-ruby-command=RUBY  name of the Ruby command (default: ruby)
bb6a72a
    --with-x                use the X Window System
bb6a72a
    --with-gtk-prefix=PFX   Prefix where GTK is installed (optional)
bb6a72a
    --with-gtk-exec-prefix=PFX Exec prefix where GTK is installed (optional)
bb6a72a
***************
bb6a72a
*** 5703,5711 ****
bb6a72a
  { $as_echo "$as_me:$LINENO: result: $enable_rubyinterp" >&5
bb6a72a
  $as_echo "$enable_rubyinterp" >&6; }
bb6a72a
  if test "$enable_rubyinterp" = "yes"; then
bb6a72a
  
bb6a72a
!   # Extract the first word of "ruby", so it can be a program name with args.
bb6a72a
! set dummy ruby; ac_word=$2
bb6a72a
  { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
bb6a72a
  $as_echo_n "checking for $ac_word... " >&6; }
bb6a72a
  if test "${ac_cv_path_vi_cv_path_ruby+set}" = set; then
bb6a72a
--- 5705,5725 ----
bb6a72a
  { $as_echo "$as_me:$LINENO: result: $enable_rubyinterp" >&5
bb6a72a
  $as_echo "$enable_rubyinterp" >&6; }
bb6a72a
  if test "$enable_rubyinterp" = "yes"; then
bb6a72a
+   { $as_echo "$as_me:$LINENO: checking --with-ruby-command argument" >&5
bb6a72a
+ $as_echo_n "checking --with-ruby-command argument... " >&6; }
bb6a72a
  
bb6a72a
! # Check whether --with-ruby-command was given.
bb6a72a
! if test "${with_ruby_command+set}" = set; then
bb6a72a
!   withval=$with_ruby_command; RUBY_CMD="$withval"; { $as_echo "$as_me:$LINENO: result: $RUBY_CMD" >&5
bb6a72a
! $as_echo "$RUBY_CMD" >&6; }
bb6a72a
! else
bb6a72a
!   RUBY_CMD="ruby"; { $as_echo "$as_me:$LINENO: result: defaulting to $RUBY_CMD" >&5
bb6a72a
! $as_echo "defaulting to $RUBY_CMD" >&6; }
bb6a72a
! fi
bb6a72a
! 
bb6a72a
! 
bb6a72a
!   # Extract the first word of "$RUBY_CMD", so it can be a program name with args.
bb6a72a
! set dummy $RUBY_CMD; ac_word=$2
bb6a72a
  { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
bb6a72a
  $as_echo_n "checking for $ac_word... " >&6; }
bb6a72a
  if test "${ac_cv_path_vi_cv_path_ruby+set}" = set; then
bb6a72a
***************
bb6a72a
*** 5752,5762 ****
bb6a72a
  $as_echo "OK" >&6; }
bb6a72a
        { $as_echo "$as_me:$LINENO: checking Ruby header files" >&5
bb6a72a
  $as_echo_n "checking Ruby header files... " >&6; }
bb6a72a
!       rubyhdrdir=`$vi_cv_path_ruby -r mkmf -e 'print Config::CONFIG["archdir"] || $hdrdir' 2>/dev/null`
bb6a72a
        if test "X$rubyhdrdir" != "X"; then
bb6a72a
  	{ $as_echo "$as_me:$LINENO: result: $rubyhdrdir" >&5
bb6a72a
  $as_echo "$rubyhdrdir" >&6; }
bb6a72a
  	RUBY_CFLAGS="-I$rubyhdrdir"
bb6a72a
  	rubylibs=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG["LIBS"]'`
bb6a72a
  	if test "X$rubylibs" != "X"; then
bb6a72a
  	  RUBY_LIBS="$rubylibs"
bb6a72a
--- 5766,5782 ----
bb6a72a
  $as_echo "OK" >&6; }
bb6a72a
        { $as_echo "$as_me:$LINENO: checking Ruby header files" >&5
bb6a72a
  $as_echo_n "checking Ruby header files... " >&6; }
bb6a72a
!       rubyhdrdir=`$vi_cv_path_ruby -r mkmf -e 'print Config::CONFIG["rubyhdrdir"] || Config::CONFIG["archdir"] || $hdrdir' 2>/dev/null`
bb6a72a
        if test "X$rubyhdrdir" != "X"; then
bb6a72a
  	{ $as_echo "$as_me:$LINENO: result: $rubyhdrdir" >&5
bb6a72a
  $as_echo "$rubyhdrdir" >&6; }
bb6a72a
  	RUBY_CFLAGS="-I$rubyhdrdir"
bb6a72a
+         rubyarch=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG["arch"]'`
bb6a72a
+         if test -d "$rubyhdrdir/$rubyarch"; then
bb6a72a
+           RUBY_CFLAGS="$RUBY_CFLAGS -I$rubyhdrdir/$rubyarch"
bb6a72a
+         fi
bb6a72a
+         rubyversion=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG["ruby_version"].gsub(/\./, "")[0,2]'`
bb6a72a
+         RUBY_CFLAGS="$RUBY_CFLAGS -DRUBY_VERSION=$rubyversion"
bb6a72a
  	rubylibs=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG["LIBS"]'`
bb6a72a
  	if test "X$rubylibs" != "X"; then
bb6a72a
  	  RUBY_LIBS="$rubylibs"
bb6a72a
***************
bb6a72a
*** 5793,5800 ****
bb6a72a
  _ACEOF
bb6a72a
  
bb6a72a
        else
bb6a72a
! 	{ $as_echo "$as_me:$LINENO: result: not found" >&5
bb6a72a
! $as_echo "not found" >&6; }
bb6a72a
        fi
bb6a72a
      else
bb6a72a
        { $as_echo "$as_me:$LINENO: result: too old; need Ruby version 1.6.0 or later" >&5
bb6a72a
--- 5813,5820 ----
bb6a72a
  _ACEOF
bb6a72a
  
bb6a72a
        else
bb6a72a
! 	{ $as_echo "$as_me:$LINENO: result: not found; disabling Ruby" >&5
bb6a72a
! $as_echo "not found; disabling Ruby" >&6; }
bb6a72a
        fi
bb6a72a
      else
bb6a72a
        { $as_echo "$as_me:$LINENO: result: too old; need Ruby version 1.6.0 or later" >&5
bb6a72a
*** ../vim-7.2.360/src/configure.in	2009-12-16 17:14:08.000000000 +0100
bb6a72a
--- src/configure.in	2010-02-17 16:00:58.000000000 +0100
bb6a72a
***************
bb6a72a
*** 949,965 ****
bb6a72a
  	[enable_rubyinterp="no"])
bb6a72a
  AC_MSG_RESULT($enable_rubyinterp)
bb6a72a
  if test "$enable_rubyinterp" = "yes"; then
bb6a72a
    AC_SUBST(vi_cv_path_ruby)
bb6a72a
!   AC_PATH_PROG(vi_cv_path_ruby, ruby)
bb6a72a
    if test "X$vi_cv_path_ruby" != "X"; then
bb6a72a
      AC_MSG_CHECKING(Ruby version)
bb6a72a
      if $vi_cv_path_ruby -e '(VERSION rescue RUBY_VERSION) >= "1.6.0" or exit 1' >/dev/null 2>/dev/null; then
bb6a72a
        AC_MSG_RESULT(OK)
bb6a72a
        AC_MSG_CHECKING(Ruby header files)
bb6a72a
!       rubyhdrdir=`$vi_cv_path_ruby -r mkmf -e 'print Config::CONFIG[["archdir"]] || $hdrdir' 2>/dev/null`
bb6a72a
        if test "X$rubyhdrdir" != "X"; then
bb6a72a
  	AC_MSG_RESULT($rubyhdrdir)
bb6a72a
  	RUBY_CFLAGS="-I$rubyhdrdir"
bb6a72a
  	rubylibs=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["LIBS"]]'`
bb6a72a
  	if test "X$rubylibs" != "X"; then
bb6a72a
  	  RUBY_LIBS="$rubylibs"
bb6a72a
--- 949,975 ----
bb6a72a
  	[enable_rubyinterp="no"])
bb6a72a
  AC_MSG_RESULT($enable_rubyinterp)
bb6a72a
  if test "$enable_rubyinterp" = "yes"; then
bb6a72a
+   AC_MSG_CHECKING(--with-ruby-command argument)
bb6a72a
+   AC_ARG_WITH(ruby-command, [  --with-ruby-command=RUBY  name of the Ruby command (default: ruby)],
bb6a72a
+ 	RUBY_CMD="$withval"; AC_MSG_RESULT($RUBY_CMD),
bb6a72a
+ 	RUBY_CMD="ruby"; AC_MSG_RESULT(defaulting to $RUBY_CMD))
bb6a72a
    AC_SUBST(vi_cv_path_ruby)
bb6a72a
!   AC_PATH_PROG(vi_cv_path_ruby, $RUBY_CMD)
bb6a72a
    if test "X$vi_cv_path_ruby" != "X"; then
bb6a72a
      AC_MSG_CHECKING(Ruby version)
bb6a72a
      if $vi_cv_path_ruby -e '(VERSION rescue RUBY_VERSION) >= "1.6.0" or exit 1' >/dev/null 2>/dev/null; then
bb6a72a
        AC_MSG_RESULT(OK)
bb6a72a
        AC_MSG_CHECKING(Ruby header files)
bb6a72a
!       rubyhdrdir=`$vi_cv_path_ruby -r mkmf -e 'print Config::CONFIG[["rubyhdrdir"]] || Config::CONFIG[["archdir"]] || $hdrdir' 2>/dev/null`
bb6a72a
        if test "X$rubyhdrdir" != "X"; then
bb6a72a
  	AC_MSG_RESULT($rubyhdrdir)
bb6a72a
  	RUBY_CFLAGS="-I$rubyhdrdir"
bb6a72a
+         rubyarch=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["arch"]]'`
bb6a72a
+         if test -d "$rubyhdrdir/$rubyarch"; then
bb6a72a
+           RUBY_CFLAGS="$RUBY_CFLAGS -I$rubyhdrdir/$rubyarch"
bb6a72a
+         fi
bb6a72a
+         rubyversion=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["ruby_version"]].gsub(/\./, "")[[0,2]]'`
bb6a72a
+         RUBY_CFLAGS="$RUBY_CFLAGS -DRUBY_VERSION=$rubyversion"
bb6a72a
  	rubylibs=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["LIBS"]]'`
bb6a72a
  	if test "X$rubylibs" != "X"; then
bb6a72a
  	  RUBY_LIBS="$rubylibs"
bb6a72a
***************
bb6a72a
*** 997,1003 ****
bb6a72a
  	RUBY_PRO="if_ruby.pro"
bb6a72a
  	AC_DEFINE(FEAT_RUBY)
bb6a72a
        else
bb6a72a
! 	AC_MSG_RESULT(not found, disabling Ruby)
bb6a72a
        fi
bb6a72a
      else
bb6a72a
        AC_MSG_RESULT(too old; need Ruby version 1.6.0 or later)
bb6a72a
--- 1007,1013 ----
bb6a72a
  	RUBY_PRO="if_ruby.pro"
bb6a72a
  	AC_DEFINE(FEAT_RUBY)
bb6a72a
        else
bb6a72a
! 	AC_MSG_RESULT(not found; disabling Ruby)
bb6a72a
        fi
bb6a72a
      else
bb6a72a
        AC_MSG_RESULT(too old; need Ruby version 1.6.0 or later)
bb6a72a
*** ../vim-7.2.360/src/if_ruby.c	2010-02-17 15:11:35.000000000 +0100
bb6a72a
--- src/if_ruby.c	2010-02-17 16:08:47.000000000 +0100
bb6a72a
***************
bb6a72a
*** 54,59 ****
bb6a72a
--- 54,62 ----
bb6a72a
  #endif
bb6a72a
  
bb6a72a
  #include <ruby.h>
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ # include <ruby/encoding.h>
bb6a72a
+ #endif
bb6a72a
  
bb6a72a
  #undef EXTERN
bb6a72a
  #undef _
bb6a72a
***************
bb6a72a
*** 65,70 ****
bb6a72a
--- 68,95 ----
bb6a72a
  # define __OPENTRANSPORTPROVIDERS__
bb6a72a
  #endif
bb6a72a
  
bb6a72a
+ /*
bb6a72a
+  * Backward compatiblity for Ruby 1.8 and earlier.
bb6a72a
+  * Ruby 1.9 does not provide STR2CSTR, instead StringValuePtr is provided.
bb6a72a
+  * Ruby 1.9 does not provide RXXX(s)->len and RXXX(s)->ptr, instead
bb6a72a
+  * RXXX_LEN(s) and RXXX_PTR(s) are provided.
bb6a72a
+  */
bb6a72a
+ #ifndef StringValuePtr
bb6a72a
+ # define StringValuePtr(s) STR2CSTR(s)
bb6a72a
+ #endif
bb6a72a
+ #ifndef RARRAY_LEN
bb6a72a
+ # define RARRAY_LEN(s) RARRAY(s)->len
bb6a72a
+ #endif
bb6a72a
+ #ifndef RARRAY_PTR
bb6a72a
+ # define RARRAY_PTR(s) RARRAY(s)->ptr
bb6a72a
+ #endif
bb6a72a
+ #ifndef RSTRING_LEN
bb6a72a
+ # define RSTRING_LEN(s) RSTRING(s)->len
bb6a72a
+ #endif
bb6a72a
+ #ifndef RSTRING_PTR
bb6a72a
+ # define RSTRING_PTR(s) RSTRING(s)->ptr
bb6a72a
+ #endif
bb6a72a
+ 
bb6a72a
  #include "vim.h"
bb6a72a
  #include "version.h"
bb6a72a
  
bb6a72a
***************
bb6a72a
*** 134,140 ****
bb6a72a
  #define rb_str_concat			dll_rb_str_concat
bb6a72a
  #define rb_str_new			dll_rb_str_new
bb6a72a
  #define rb_str_new2			dll_rb_str_new2
bb6a72a
! #define ruby_errinfo			(*dll_ruby_errinfo)
bb6a72a
  #define ruby_init			dll_ruby_init
bb6a72a
  #define ruby_init_loadpath		dll_ruby_init_loadpath
bb6a72a
  #define NtInitialize			dll_NtInitialize
bb6a72a
--- 159,169 ----
bb6a72a
  #define rb_str_concat			dll_rb_str_concat
bb6a72a
  #define rb_str_new			dll_rb_str_new
bb6a72a
  #define rb_str_new2			dll_rb_str_new2
bb6a72a
! #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
! # define rb_errinfo			dll_rb_errinfo
bb6a72a
! #else
bb6a72a
! # define ruby_errinfo			(*dll_ruby_errinfo)
bb6a72a
! #endif
bb6a72a
  #define ruby_init			dll_ruby_init
bb6a72a
  #define ruby_init_loadpath		dll_ruby_init_loadpath
bb6a72a
  #define NtInitialize			dll_NtInitialize
bb6a72a
***************
bb6a72a
*** 142,147 ****
bb6a72a
--- 171,184 ----
bb6a72a
  # define rb_w32_snprintf		dll_rb_w32_snprintf
bb6a72a
  #endif
bb6a72a
  
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ # define ruby_script			dll_ruby_script
bb6a72a
+ # define rb_enc_find_index		dll_rb_enc_find_index
bb6a72a
+ # define rb_enc_find			dll_rb_enc_find
bb6a72a
+ # define rb_enc_str_new			dll_rb_enc_str_new
bb6a72a
+ # define rb_sprintf			dll_rb_sprintf
bb6a72a
+ #endif
bb6a72a
+ 
bb6a72a
  /*
bb6a72a
   * Pointers for dynamic link
bb6a72a
   */
bb6a72a
***************
bb6a72a
*** 189,195 ****
bb6a72a
--- 226,236 ----
bb6a72a
  static VALUE (*dll_rb_str_concat) (VALUE, VALUE);
bb6a72a
  static VALUE (*dll_rb_str_new) (const char*, long);
bb6a72a
  static VALUE (*dll_rb_str_new2) (const char*);
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ static VALUE (*dll_rb_errinfo) (void);
bb6a72a
+ #else
bb6a72a
  static VALUE *dll_ruby_errinfo;
bb6a72a
+ #endif
bb6a72a
  static void (*dll_ruby_init) (void);
bb6a72a
  static void (*dll_ruby_init_loadpath) (void);
bb6a72a
  static void (*dll_NtInitialize) (int*, char***);
bb6a72a
***************
bb6a72a
*** 197,202 ****
bb6a72a
--- 238,251 ----
bb6a72a
  static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
bb6a72a
  #endif
bb6a72a
  
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ static void (*dll_ruby_script) (const char*);
bb6a72a
+ static int (*dll_rb_enc_find_index) (const char*);
bb6a72a
+ static rb_encoding* (*dll_rb_enc_find) (const char*);
bb6a72a
+ static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*);
bb6a72a
+ static VALUE (*dll_rb_sprintf) (const char*, ...);
bb6a72a
+ #endif
bb6a72a
+ 
bb6a72a
  static HINSTANCE hinstRuby = 0; /* Instance of ruby.dll */
bb6a72a
  
bb6a72a
  /*
bb6a72a
***************
bb6a72a
*** 252,264 ****
bb6a72a
--- 301,324 ----
bb6a72a
      {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat},
bb6a72a
      {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new},
bb6a72a
      {"rb_str_new2", (RUBY_PROC*)&dll_rb_str_new2},
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+     {"rb_errinfo", (RUBY_PROC*)&dll_rb_errinfo},
bb6a72a
+ #else
bb6a72a
      {"ruby_errinfo", (RUBY_PROC*)&dll_ruby_errinfo},
bb6a72a
+ #endif
bb6a72a
      {"ruby_init", (RUBY_PROC*)&dll_ruby_init},
bb6a72a
      {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath},
bb6a72a
      {"NtInitialize", (RUBY_PROC*)&dll_NtInitialize},
bb6a72a
  #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
bb6a72a
      {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf},
bb6a72a
  #endif
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+     {"ruby_script", (RUBY_PROC*)&dll_ruby_script},
bb6a72a
+     {"rb_enc_find_index", (RUBY_PROC*)&dll_rb_enc_find_index},
bb6a72a
+     {"rb_enc_find", (RUBY_PROC*)&dll_rb_enc_find},
bb6a72a
+     {"rb_enc_str_new", (RUBY_PROC*)&dll_rb_enc_str_new},
bb6a72a
+     {"rb_sprintf", (RUBY_PROC*)&dll_rb_sprintf},
bb6a72a
+ #endif
bb6a72a
      {"", NULL},
bb6a72a
  };
bb6a72a
  
bb6a72a
***************
bb6a72a
*** 348,353 ****
bb6a72a
--- 408,465 ----
bb6a72a
      vim_free(script);
bb6a72a
  }
bb6a72a
  
bb6a72a
+ /*
bb6a72a
+  *  In Ruby 1.9 or later, ruby String object has encoding.
bb6a72a
+  *  conversion buffer string of vim to ruby String object using
bb6a72a
+  *  VIM encoding option.
bb6a72a
+  */
bb6a72a
+     static VALUE
bb6a72a
+ vim_str2rb_enc_str(const char *s)
bb6a72a
+ {
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+     int isnum;
bb6a72a
+     long lval;
bb6a72a
+     char_u *sval;
bb6a72a
+     rb_encoding *enc;
bb6a72a
+ 
bb6a72a
+     isnum = get_option_value((char_u *)"enc", &lval, &sval, 0);
bb6a72a
+     if (isnum == 0)
bb6a72a
+     {
bb6a72a
+ 	enc = rb_enc_find((char *)sval);
bb6a72a
+ 	vim_free(sval);
bb6a72a
+ 	if (enc) {
bb6a72a
+ 	    return rb_enc_str_new(s, strlen(s), enc);
bb6a72a
+ 	}
bb6a72a
+     }
bb6a72a
+ #endif
bb6a72a
+     return rb_str_new2(s);
bb6a72a
+ }
bb6a72a
+ 
bb6a72a
+     static VALUE
bb6a72a
+ eval_enc_string_protect(const char *str, int *state)
bb6a72a
+ {
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+     int isnum;
bb6a72a
+     long lval;
bb6a72a
+     char_u *sval;
bb6a72a
+     rb_encoding *enc;
bb6a72a
+     VALUE v;
bb6a72a
+ 
bb6a72a
+     isnum = get_option_value((char_u *)"enc", &lval, &sval, 0);
bb6a72a
+     if (isnum == 0)
bb6a72a
+     {
bb6a72a
+ 	enc = rb_enc_find((char *)sval);
bb6a72a
+ 	vim_free(sval);
bb6a72a
+ 	if (enc)
bb6a72a
+ 	{
bb6a72a
+ 	    v = rb_sprintf("#-*- coding:%s -*-\n%s", rb_enc_name(enc), str);
bb6a72a
+ 	    return rb_eval_string_protect(StringValuePtr(v), state);
bb6a72a
+ 	}
bb6a72a
+     }
bb6a72a
+ #endif
bb6a72a
+     return rb_eval_string_protect(str, state);
bb6a72a
+ }
bb6a72a
+ 
bb6a72a
  void ex_rubydo(exarg_T *eap)
bb6a72a
  {
bb6a72a
      int state;
bb6a72a
***************
bb6a72a
*** 360,368 ****
bb6a72a
  	for (i = eap->line1; i <= eap->line2; i++) {
bb6a72a
  	    VALUE line, oldline;
bb6a72a
  
bb6a72a
! 	    line = oldline = rb_str_new2((char *)ml_get(i));
bb6a72a
  	    rb_lastline_set(line);
bb6a72a
! 	    rb_eval_string_protect((char *) eap->arg, &state);
bb6a72a
  	    if (state) {
bb6a72a
  		error_print(state);
bb6a72a
  		break;
bb6a72a
--- 472,480 ----
bb6a72a
  	for (i = eap->line1; i <= eap->line2; i++) {
bb6a72a
  	    VALUE line, oldline;
bb6a72a
  
bb6a72a
! 	    line = oldline = vim_str2rb_enc_str((char *)ml_get(i));
bb6a72a
  	    rb_lastline_set(line);
bb6a72a
! 	    eval_enc_string_protect((char *) eap->arg, &state);
bb6a72a
  	    if (state) {
bb6a72a
  		error_print(state);
bb6a72a
  		break;
bb6a72a
***************
bb6a72a
*** 373,379 ****
bb6a72a
  		    EMSG(_("E265: $_ must be an instance of String"));
bb6a72a
  		    return;
bb6a72a
  		}
bb6a72a
! 		ml_replace(i, (char_u *) STR2CSTR(line), 1);
bb6a72a
  		changed();
bb6a72a
  #ifdef SYNTAX_HL
bb6a72a
  		syn_changed(i); /* recompute syntax hl. for this line */
bb6a72a
--- 485,491 ----
bb6a72a
  		    EMSG(_("E265: $_ must be an instance of String"));
bb6a72a
  		    return;
bb6a72a
  		}
bb6a72a
! 		ml_replace(i, (char_u *) StringValuePtr(line), 1);
bb6a72a
  		changed();
bb6a72a
  #ifdef SYNTAX_HL
bb6a72a
  		syn_changed(i); /* recompute syntax hl. for this line */
bb6a72a
***************
bb6a72a
*** 428,436 ****
bb6a72a
--- 540,557 ----
bb6a72a
  	    char *argv[] = {"gvim.exe"};
bb6a72a
  	    NtInitialize(&argc, &argv);
bb6a72a
  #endif
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ 	    RUBY_INIT_STACK;
bb6a72a
+ #endif
bb6a72a
  	    ruby_init();
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ 	    ruby_script("vim-ruby");
bb6a72a
+ #endif
bb6a72a
  	    ruby_init_loadpath();
bb6a72a
  	    ruby_io_init();
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ 	    rb_enc_find_index("encdb");
bb6a72a
+ #endif
bb6a72a
  	    ruby_vim_init();
bb6a72a
  	    ruby_initialized = 1;
bb6a72a
  #ifdef DYNAMIC_RUBY
bb6a72a
***************
bb6a72a
*** 448,455 ****
bb6a72a
--- 569,578 ----
bb6a72a
  static void error_print(int state)
bb6a72a
  {
bb6a72a
  #ifndef DYNAMIC_RUBY
bb6a72a
+ #if !(defined(RUBY_VERSION) &&  RUBY_VERSION >= 19)
bb6a72a
      RUBYEXTERN VALUE ruby_errinfo;
bb6a72a
  #endif
bb6a72a
+ #endif
bb6a72a
      VALUE eclass;
bb6a72a
      VALUE einfo;
bb6a72a
      char buff[BUFSIZ];
bb6a72a
***************
bb6a72a
*** 482,490 ****
bb6a72a
  	break;
bb6a72a
      case TAG_RAISE:
bb6a72a
      case TAG_FATAL:
bb6a72a
  	eclass = CLASS_OF(ruby_errinfo);
bb6a72a
  	einfo = rb_obj_as_string(ruby_errinfo);
bb6a72a
! 	if (eclass == rb_eRuntimeError && RSTRING(einfo)->len == 0) {
bb6a72a
  	    EMSG(_("E272: unhandled exception"));
bb6a72a
  	}
bb6a72a
  	else {
bb6a72a
--- 605,618 ----
bb6a72a
  	break;
bb6a72a
      case TAG_RAISE:
bb6a72a
      case TAG_FATAL:
bb6a72a
+ #if defined(RUBY_VERSION) && RUBY_VERSION >= 19
bb6a72a
+ 	eclass = CLASS_OF(rb_errinfo());
bb6a72a
+ 	einfo = rb_obj_as_string(rb_errinfo());
bb6a72a
+ #else
bb6a72a
  	eclass = CLASS_OF(ruby_errinfo);
bb6a72a
  	einfo = rb_obj_as_string(ruby_errinfo);
bb6a72a
! #endif
bb6a72a
! 	if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) {
bb6a72a
  	    EMSG(_("E272: unhandled exception"));
bb6a72a
  	}
bb6a72a
  	else {
bb6a72a
***************
bb6a72a
*** 493,499 ****
bb6a72a
  
bb6a72a
  	    epath = rb_class_path(eclass);
bb6a72a
  	    vim_snprintf(buff, BUFSIZ, "%s: %s",
bb6a72a
! 		     RSTRING(epath)->ptr, RSTRING(einfo)->ptr);
bb6a72a
  	    p = strchr(buff, '\n');
bb6a72a
  	    if (p) *p = '\0';
bb6a72a
  	    EMSG(buff);
bb6a72a
--- 621,627 ----
bb6a72a
  
bb6a72a
  	    epath = rb_class_path(eclass);
bb6a72a
  	    vim_snprintf(buff, BUFSIZ, "%s: %s",
bb6a72a
! 		     RSTRING_PTR(epath), RSTRING_PTR(einfo));
bb6a72a
  	    p = strchr(buff, '\n');
bb6a72a
  	    if (p) *p = '\0';
bb6a72a
  	    EMSG(buff);
bb6a72a
***************
bb6a72a
*** 511,518 ****
bb6a72a
      char *buff, *p;
bb6a72a
  
bb6a72a
      str = rb_obj_as_string(str);
bb6a72a
!     buff = ALLOCA_N(char, RSTRING(str)->len);
bb6a72a
!     strcpy(buff, RSTRING(str)->ptr);
bb6a72a
      p = strchr(buff, '\n');
bb6a72a
      if (p) *p = '\0';
bb6a72a
      MSG(buff);
bb6a72a
--- 639,646 ----
bb6a72a
      char *buff, *p;
bb6a72a
  
bb6a72a
      str = rb_obj_as_string(str);
bb6a72a
!     buff = ALLOCA_N(char, RSTRING_LEN(str));
bb6a72a
!     strcpy(buff, RSTRING_PTR(str));
bb6a72a
      p = strchr(buff, '\n');
bb6a72a
      if (p) *p = '\0';
bb6a72a
      MSG(buff);
bb6a72a
***************
bb6a72a
*** 521,541 ****
bb6a72a
  
bb6a72a
  static VALUE vim_set_option(VALUE self UNUSED, VALUE str)
bb6a72a
  {
bb6a72a
!     do_set((char_u *)STR2CSTR(str), 0);
bb6a72a
      update_screen(NOT_VALID);
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
  
bb6a72a
  static VALUE vim_command(VALUE self UNUSED, VALUE str)
bb6a72a
  {
bb6a72a
!     do_cmdline_cmd((char_u *)STR2CSTR(str));
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
  
bb6a72a
  static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
bb6a72a
  {
bb6a72a
  #ifdef FEAT_EVAL
bb6a72a
!     char_u *value = eval_to_string((char_u *)STR2CSTR(str), NULL, TRUE);
bb6a72a
  
bb6a72a
      if (value != NULL)
bb6a72a
      {
bb6a72a
--- 649,669 ----
bb6a72a
  
bb6a72a
  static VALUE vim_set_option(VALUE self UNUSED, VALUE str)
bb6a72a
  {
bb6a72a
!     do_set((char_u *)StringValuePtr(str), 0);
bb6a72a
      update_screen(NOT_VALID);
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
  
bb6a72a
  static VALUE vim_command(VALUE self UNUSED, VALUE str)
bb6a72a
  {
bb6a72a
!     do_cmdline_cmd((char_u *)StringValuePtr(str));
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
  
bb6a72a
  static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
bb6a72a
  {
bb6a72a
  #ifdef FEAT_EVAL
bb6a72a
!     char_u *value = eval_to_string((char_u *)StringValuePtr(str), NULL, TRUE);
bb6a72a
  
bb6a72a
      if (value != NULL)
bb6a72a
      {
bb6a72a
***************
bb6a72a
*** 640,648 ****
bb6a72a
      if (n > 0 && n <= buf->b_ml.ml_line_count)
bb6a72a
      {
bb6a72a
  	char *line = (char *)ml_get_buf(buf, n, FALSE);
bb6a72a
! 	return line ? rb_str_new2(line) : Qnil;
bb6a72a
      }
bb6a72a
!     rb_raise(rb_eIndexError, "index %d out of buffer", n);
bb6a72a
  #ifndef __GNUC__
bb6a72a
      return Qnil; /* For stop warning */
bb6a72a
  #endif
bb6a72a
--- 768,776 ----
bb6a72a
      if (n > 0 && n <= buf->b_ml.ml_line_count)
bb6a72a
      {
bb6a72a
  	char *line = (char *)ml_get_buf(buf, n, FALSE);
bb6a72a
! 	return line ? vim_str2rb_enc_str(line) : Qnil;
bb6a72a
      }
bb6a72a
!     rb_raise(rb_eIndexError, "line number %ld out of range", (long)n);
bb6a72a
  #ifndef __GNUC__
bb6a72a
      return Qnil; /* For stop warning */
bb6a72a
  #endif
bb6a72a
***************
bb6a72a
*** 659,665 ****
bb6a72a
  
bb6a72a
  static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str)
bb6a72a
  {
bb6a72a
!     char	*line = STR2CSTR(str);
bb6a72a
      aco_save_T	aco;
bb6a72a
  
bb6a72a
      if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL)
bb6a72a
--- 787,793 ----
bb6a72a
  
bb6a72a
  static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str)
bb6a72a
  {
bb6a72a
!     char	*line = StringValuePtr(str);
bb6a72a
      aco_save_T	aco;
bb6a72a
  
bb6a72a
      if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL)
bb6a72a
***************
bb6a72a
*** 683,689 ****
bb6a72a
      }
bb6a72a
      else
bb6a72a
      {
bb6a72a
! 	rb_raise(rb_eIndexError, "index %d out of buffer", n);
bb6a72a
  #ifndef __GNUC__
bb6a72a
  	return Qnil; /* For stop warning */
bb6a72a
  #endif
bb6a72a
--- 811,817 ----
bb6a72a
      }
bb6a72a
      else
bb6a72a
      {
bb6a72a
! 	rb_raise(rb_eIndexError, "line number %ld out of range", (long)n);
bb6a72a
  #ifndef __GNUC__
bb6a72a
  	return Qnil; /* For stop warning */
bb6a72a
  #endif
bb6a72a
***************
bb6a72a
*** 729,735 ****
bb6a72a
      }
bb6a72a
      else
bb6a72a
      {
bb6a72a
! 	rb_raise(rb_eIndexError, "index %d out of buffer", n);
bb6a72a
      }
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
--- 857,863 ----
bb6a72a
      }
bb6a72a
      else
bb6a72a
      {
bb6a72a
! 	rb_raise(rb_eIndexError, "line number %ld out of range", n);
bb6a72a
      }
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
***************
bb6a72a
*** 737,747 ****
bb6a72a
  static VALUE buffer_append(VALUE self, VALUE num, VALUE str)
bb6a72a
  {
bb6a72a
      buf_T	*buf = get_buf(self);
bb6a72a
!     char	*line = STR2CSTR(str);
bb6a72a
      long	n = NUM2LONG(num);
bb6a72a
      aco_save_T	aco;
bb6a72a
  
bb6a72a
!     if (n >= 0 && n <= buf->b_ml.ml_line_count && line != NULL)
bb6a72a
      {
bb6a72a
  	/* set curwin/curbuf for "buf" and save some things */
bb6a72a
  	aucmd_prepbuf(&aco, buf);
bb6a72a
--- 865,878 ----
bb6a72a
  static VALUE buffer_append(VALUE self, VALUE num, VALUE str)
bb6a72a
  {
bb6a72a
      buf_T	*buf = get_buf(self);
bb6a72a
!     char	*line = StringValuePtr(str);
bb6a72a
      long	n = NUM2LONG(num);
bb6a72a
      aco_save_T	aco;
bb6a72a
  
bb6a72a
!     if (line != NULL) {
bb6a72a
! 	rb_raise(rb_eIndexError, "NULL line");
bb6a72a
!     }
bb6a72a
!     else if (n >= 0 && n <= buf->b_ml.ml_line_count)
bb6a72a
      {
bb6a72a
  	/* set curwin/curbuf for "buf" and save some things */
bb6a72a
  	aucmd_prepbuf(&aco, buf);
bb6a72a
***************
bb6a72a
*** 763,769 ****
bb6a72a
  	update_curbuf(NOT_VALID);
bb6a72a
      }
bb6a72a
      else {
bb6a72a
! 	rb_raise(rb_eIndexError, "index %d out of buffer", n);
bb6a72a
      }
bb6a72a
      return str;
bb6a72a
  }
bb6a72a
--- 894,900 ----
bb6a72a
  	update_curbuf(NOT_VALID);
bb6a72a
      }
bb6a72a
      else {
bb6a72a
! 	rb_raise(rb_eIndexError, "line number %ld out of range", n);
bb6a72a
      }
bb6a72a
      return str;
bb6a72a
  }
bb6a72a
***************
bb6a72a
*** 904,913 ****
bb6a72a
      win_T *win = get_win(self);
bb6a72a
  
bb6a72a
      Check_Type(pos, T_ARRAY);
bb6a72a
!     if (RARRAY(pos)->len != 2)
bb6a72a
  	rb_raise(rb_eArgError, "array length must be 2");
bb6a72a
!     lnum = RARRAY(pos)->ptr[0];
bb6a72a
!     col = RARRAY(pos)->ptr[1];
bb6a72a
      win->w_cursor.lnum = NUM2LONG(lnum);
bb6a72a
      win->w_cursor.col = NUM2UINT(col);
bb6a72a
      check_cursor();		    /* put cursor on an existing line */
bb6a72a
--- 1035,1044 ----
bb6a72a
      win_T *win = get_win(self);
bb6a72a
  
bb6a72a
      Check_Type(pos, T_ARRAY);
bb6a72a
!     if (RARRAY_LEN(pos) != 2)
bb6a72a
  	rb_raise(rb_eArgError, "array length must be 2");
bb6a72a
!     lnum = RARRAY_PTR(pos)[0];
bb6a72a
!     col = RARRAY_PTR(pos)[1];
bb6a72a
      win->w_cursor.lnum = NUM2LONG(lnum);
bb6a72a
      win->w_cursor.col = NUM2UINT(col);
bb6a72a
      check_cursor();		    /* put cursor on an existing line */
bb6a72a
***************
bb6a72a
*** 924,930 ****
bb6a72a
  	if (i > 0) rb_str_cat(str, ", ", 2);
bb6a72a
  	rb_str_concat(str, rb_inspect(argv[i]));
bb6a72a
      }
bb6a72a
!     MSG(RSTRING(str)->ptr);
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
  
bb6a72a
--- 1055,1061 ----
bb6a72a
  	if (i > 0) rb_str_cat(str, ", ", 2);
bb6a72a
  	rb_str_concat(str, rb_inspect(argv[i]));
bb6a72a
      }
bb6a72a
!     MSG(RSTRING_PTR(str));
bb6a72a
      return Qnil;
bb6a72a
  }
bb6a72a
  
bb6a72a
*** ../vim-7.2.360/src/version.c	2010-02-17 15:11:35.000000000 +0100
bb6a72a
--- src/version.c	2010-02-17 15:59:12.000000000 +0100
bb6a72a
***************
bb6a72a
*** 683,684 ****
bb6a72a
--- 683,686 ----
bb6a72a
  {   /* Add new patch number below this line */
bb6a72a
+ /**/
bb6a72a
+     361,
bb6a72a
  /**/
bb6a72a
bb6a72a
-- 
bb6a72a
"Marriage is when a man and woman become as one; the trouble starts
bb6a72a
when they try to decide which one"
bb6a72a
bb6a72a
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
bb6a72a
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
bb6a72a
\\\        download, build and distribute -- http://www.A-A-P.org        ///
bb6a72a
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///