]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2039: if_ruby: crash when using Ruby/dyn 4.0 v9.1.2039
authorYee Cheng Chin <ychin.git@gmail.com>
Thu, 1 Jan 2026 16:25:10 +0000 (16:25 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 1 Jan 2026 16:25:10 +0000 (16:25 +0000)
Problem:  if_ruby: crash when using Ruby/dyn 4.0
          (after v9.1.2036)
Solution: Fix Ruby 4.0 dynamic builds correctly by inlining
          rb_check_typeddata (Yee Cheng Chin)

Ruby 4.0 broke Vim compilation in dynamic builds. That's because the
function `rb_check_typeddata` is now used in an inline function defined
in Ruby headers, which causes it to link against the lib statically
rather than using the one we load in dynamically
(`dll_rb_check_typeddata`) as we only remap it later (after the Ruby
header include).

A previous fix (v9.1.2036) did a wrong fix by stubbing in the actual
inline function `rbimpl_check_typeddata` instead. This does not work
because the inline function is not part of the dynamic lib and therefore
it's not possible to load it in dynamically (the patch also did not
actually attempt to load in the stub). With that patch, Vim would
crash when this function is used as the function pointer is null.

Fix this properly by reverting the previous change, and simply stub
`rb_check_typeddata` using similar mechanisms the file had already set
up for similar situations.

fixes:   #18884
related: #19051
closes:  #19060

Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/if_ruby.c
src/version.c

index 49fdc34dd5316bf23855cf31b79c6dd2cdc4e391..913936174a5e0112f002a570f59f3a341e7943d3 100644 (file)
 #  define rb_num2int   rb_num2int_stub
 # endif
 
+# if RUBY_VERSION >= 20
+// USE_TYPEDDATA is not defined yet. We just check for 2.0.
+#  define rb_check_typeddata           rb_check_typeddata_stub
+#endif
+
 # if RUBY_VERSION == 21
 // Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses
 // rb_gc_writebarrier_unprotect_promoted if USE_RGENGC
@@ -243,12 +248,6 @@ static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
 # if RUBY_VERSION < 30
 #  define rb_check_type                        dll_rb_check_type
 # endif
-# ifdef USE_TYPEDDATA
-#  if RUBY_VERSION >= 40
-#    define rbimpl_check_typeddata             dll_rbimpl_check_typeddata
-#  endif
-#  define rb_check_typeddata           dll_rb_check_typeddata
-# endif
 # define rb_class_path                 dll_rb_class_path
 # ifdef USE_TYPEDDATA
 #  if RUBY_VERSION >= 23
@@ -376,9 +375,6 @@ VALUE *dll_rb_cTrueClass;
 static VALUE (*dll_rb_class_new_instance) (int,VALUE*,VALUE);
 static void (*dll_rb_check_type) (VALUE,int);
 # ifdef USE_TYPEDDATA
-#  if RUBY_VERSION >= 40
-static void *(*dll_rbimpl_check_typeddata) (VALUE,const rb_data_type_t *);
-#  endif
 static void *(*dll_rb_check_typeddata) (VALUE,const rb_data_type_t *);
 # endif
 static VALUE (*dll_rb_class_path) (VALUE);
@@ -607,6 +603,12 @@ rb_unexpected_type_stub(VALUE self, int t)
     dll_rb_unexpected_type(self, t);
 }
 #  endif
+#  ifdef USE_TYPEDDATA
+void *rb_check_typeddata_stub(VALUE obj, const rb_data_type_t *data_type)
+{
+    return dll_rb_check_typeddata(obj, data_type);
+}
+#  endif
 # endif // ifndef PROTO
 
 static HINSTANCE hinstRuby = NULL; // Instance of ruby.dll
index 76b823a31e65327af28c0bd87503f21e25879b70..99804297effb3fb649f41200b796f4f18e4a76b9 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2039,
 /**/
     2038,
 /**/