diff src/if_ruby.c @ 2621:baa5f81197c8 v7.3.043

updated for version 7.3.043 Problem: Can't load Ruby dynamically on Unix. Solution: Adjust the configure script. (James Vega)
author Bram Moolenaar <bram@vim.org>
date Wed, 27 Oct 2010 16:49:47 +0200
parents fa5dee44df3f
children bfd69bfb4149
line wrap: on
line diff
--- a/src/if_ruby.c
+++ b/src/if_ruby.c
@@ -14,6 +14,8 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "auto/config.h"
+
 #ifdef _WIN32
 # if !defined(DYNAMIC_RUBY_VER) || (DYNAMIC_RUBY_VER < 18)
 #   define NT
@@ -48,13 +50,15 @@
 #  define RUBY_EXPORT
 # endif
 
-#if !(defined(WIN32) || defined(_WIN64))
+#ifndef WIN3264
 # include <dlfcn.h>
-# define HANDLE void*
+# define HINSTANCE void*
+# define RUBY_PROC void*
 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
 # define symbol_from_dll dlsym
 # define close_dll dlclose
 #else
+# define RUBY_PROC FARPROC
 # define load_dll vimLoadLib
 # define symbol_from_dll GetProcAddress
 # define close_dll FreeLibrary
@@ -174,7 +178,9 @@ static void ruby_vim_init(void);
 #define rb_lastline_get			dll_rb_lastline_get
 #define rb_lastline_set			dll_rb_lastline_set
 #define rb_load_protect			dll_rb_load_protect
+#ifndef RUBY19_OR_LATER
 #define rb_num2long			dll_rb_num2long
+#endif
 #define rb_num2ulong			dll_rb_num2ulong
 #define rb_obj_alloc			dll_rb_obj_alloc
 #define rb_obj_as_string		dll_rb_obj_as_string
@@ -186,6 +192,9 @@ static void ruby_vim_init(void);
 #ifdef rb_str_new2
 /* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */
 # define need_rb_str_new_cstr 1
+/* Ruby's headers #define rb_str_new_cstr to make use of GCC's
+ * __builtin_constant_p extension. */
+# undef rb_str_new_cstr
 # define rb_str_new_cstr		dll_rb_str_new_cstr
 #else
 # define rb_str_new2			dll_rb_str_new2
@@ -206,9 +215,11 @@ static void ruby_vim_init(void);
 #endif
 #define ruby_init			dll_ruby_init
 #define ruby_init_loadpath		dll_ruby_init_loadpath
-#define NtInitialize			dll_NtInitialize
-#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
-# define rb_w32_snprintf		dll_rb_w32_snprintf
+#ifdef WIN3264
+# define NtInitialize			dll_NtInitialize
+# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
+#  define rb_w32_snprintf		dll_rb_w32_snprintf
+# endif
 #endif
 
 #ifdef RUBY19_OR_LATER
@@ -283,7 +294,12 @@ static VALUE *dll_ruby_errinfo;
 #endif
 static void (*dll_ruby_init) (void);
 static void (*dll_ruby_init_loadpath) (void);
+#ifdef WIN3264
 static void (*dll_NtInitialize) (int*, char***);
+# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
+static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
+# endif
+#endif
 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
 static char * (*dll_rb_string_value_ptr) (volatile VALUE*);
 static VALUE (*dll_rb_float_new) (double);
@@ -293,9 +309,6 @@ static VALUE (*dll_rb_ary_push) (VALUE, 
 #ifdef RUBY19_OR_LATER
 static VALUE (*dll_rb_int2big)(SIGNED_VALUE);
 #endif
-#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
-static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
-#endif
 
 #ifdef RUBY19_OR_LATER
 static void (*dll_ruby_script) (const char*);
@@ -317,12 +330,11 @@ VALUE rb_int2big_stub(SIGNED_VALUE x)
 }
 #endif
 
-static HINSTANCE hinstRuby = 0; /* Instance of ruby.dll */
+static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */
 
 /*
  * Table of name to function pointer of ruby.
  */
-#define RUBY_PROC FARPROC
 static struct
 {
     char *name;
@@ -387,15 +399,17 @@ static struct
 #endif
     {"ruby_init", (RUBY_PROC*)&dll_ruby_init},
     {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath},
+#ifdef WIN3264
     {
-#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 19
+# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 19
     "NtInitialize",
-#else
+# else
     "ruby_sysinit",
-#endif
+# endif
 			(RUBY_PROC*)&dll_NtInitialize},
-#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
+# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
     {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf},
+# endif
 #endif
 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
     {"rb_string_value_ptr", (RUBY_PROC*)&dll_rb_string_value_ptr},
@@ -424,7 +438,7 @@ end_dynamic_ruby()
     if (hinstRuby)
     {
 	close_dll(hinstRuby);
-	hinstRuby = 0;
+	hinstRuby = NULL;
     }
 }
 
@@ -454,7 +468,7 @@ ruby_runtime_link_init(char *libname, in
 			ruby_funcname_table[i].name)))
 	{
 	    close_dll(hinstRuby);
-	    hinstRuby = 0;
+	    hinstRuby = NULL;
 	    if (verbose)
 		EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
 	    return FAIL;
@@ -936,9 +950,7 @@ static VALUE get_buffer_line(buf_T *buf,
 	return line ? vim_str2rb_enc_str(line) : Qnil;
     }
     rb_raise(rb_eIndexError, "line number %ld out of range", (long)n);
-#ifndef __GNUC__
     return Qnil; /* For stop warning */
-#endif
 }
 
 static VALUE buffer_aref(VALUE self, VALUE num)