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