Skip to content

Commit 871d2cc

Browse files
ychinchrisbra
authored andcommitted
patch 9.1.2039: if_ruby: crash when using Ruby/dyn 4.0
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>
1 parent 4fe7301 commit 871d2cc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/if_ruby.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
# define rb_num2int rb_num2int_stub
7474
# endif
7575

76+
# if RUBY_VERSION >= 20
77+
// USE_TYPEDDATA is not defined yet. We just check for 2.0.
78+
# define rb_check_typeddata rb_check_typeddata_stub
79+
#endif
80+
7681
# if RUBY_VERSION == 21
7782
// Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses
7883
// rb_gc_writebarrier_unprotect_promoted if USE_RGENGC
@@ -243,12 +248,6 @@ static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
243248
# if RUBY_VERSION < 30
244249
# define rb_check_type dll_rb_check_type
245250
# endif
246-
# ifdef USE_TYPEDDATA
247-
# if RUBY_VERSION >= 40
248-
# define rbimpl_check_typeddata dll_rbimpl_check_typeddata
249-
# endif
250-
# define rb_check_typeddata dll_rb_check_typeddata
251-
# endif
252251
# define rb_class_path dll_rb_class_path
253252
# ifdef USE_TYPEDDATA
254253
# if RUBY_VERSION >= 23
@@ -376,9 +375,6 @@ VALUE *dll_rb_cTrueClass;
376375
static VALUE (*dll_rb_class_new_instance) (int,VALUE*,VALUE);
377376
static void (*dll_rb_check_type) (VALUE,int);
378377
# ifdef USE_TYPEDDATA
379-
# if RUBY_VERSION >= 40
380-
static void *(*dll_rbimpl_check_typeddata) (VALUE,const rb_data_type_t *);
381-
# endif
382378
static void *(*dll_rb_check_typeddata) (VALUE,const rb_data_type_t *);
383379
# endif
384380
static VALUE (*dll_rb_class_path) (VALUE);
@@ -607,6 +603,12 @@ rb_unexpected_type_stub(VALUE self, int t)
607603
dll_rb_unexpected_type(self, t);
608604
}
609605
# endif
606+
# ifdef USE_TYPEDDATA
607+
void *rb_check_typeddata_stub(VALUE obj, const rb_data_type_t *data_type)
608+
{
609+
return dll_rb_check_typeddata(obj, data_type);
610+
}
611+
# endif
610612
# endif // ifndef PROTO
611613

612614
static HINSTANCE hinstRuby = NULL; // Instance of ruby.dll

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2039,
737739
/**/
738740
2038,
739741
/**/

0 commit comments

Comments
 (0)