Skip to content

Commit dace9f7

Browse files
committed
patch 8.2.2235: build failure with some Ruby versions
Problem: Build failure with some Ruby versions. Solution: Adjust the code for Ruby 3.0. (Ozaki Kiichi, closes #7564)
1 parent 3e112ac commit dace9f7

3 files changed

Lines changed: 92 additions & 55 deletions

File tree

ci/config.mk.clang.sed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/^CFLAGS[[:blank:]]*=/s/$/ -Wno-error=missing-field-initializers/
2-
/^RUBY_CFLAGS[[:blank:]]*=/s/$/ -Wno-error=unknown-attributes -Wno-error=ignored-attributes/
2+
/^RUBY_CFLAGS[[:blank:]]*=/s/$/ -Wno-error=unknown-attributes -Wno-error=ignored-attributes -fms-extensions/

src/if_ruby.c

Lines changed: 89 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
# define RUBYEXTERN extern
3333
#endif
3434

35-
#if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 24
36-
# define USE_RUBY_INTEGER
35+
// suggested by Ariya Mizutani
36+
#if (_MSC_VER == 1200)
37+
# undef _WIN32_WINNT
3738
#endif
3839

3940
#ifdef DYNAMIC_RUBY
@@ -42,6 +43,10 @@
4243
* definition. This function use these variables. But we want function to
4344
* use dll_* variables.
4445
*/
46+
# if RUBY_VERSION >= 24
47+
# define USE_RUBY_INTEGER
48+
# endif
49+
4550
# define rb_cFalseClass (*dll_rb_cFalseClass)
4651
# define rb_cFixnum (*dll_rb_cFixnum)
4752
# if defined(USE_RUBY_INTEGER)
@@ -54,6 +59,7 @@
5459
# define rb_cString (*dll_rb_cString)
5560
# define rb_cSymbol (*dll_rb_cSymbol)
5661
# define rb_cTrueClass (*dll_rb_cTrueClass)
62+
5763
# if RUBY_VERSION >= 18
5864
/*
5965
* On ver 1.8, all Ruby functions are exported with "__declspec(dllimport)"
@@ -64,40 +70,41 @@
6470
# define RUBY_EXPORT
6571
# endif
6672

67-
#endif // ifdef DYNAMIC_RUBY
68-
69-
// suggested by Ariya Mizutani
70-
#if (_MSC_VER == 1200)
71-
# undef _WIN32_WINNT
72-
#endif
73-
74-
#if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 19
73+
# if RUBY_VERSION >= 19
7574
// Ruby 1.9 defines a number of static functions which use rb_num2long and
7675
// rb_int2big
77-
# define rb_num2long rb_num2long_stub
78-
# define rb_int2big rb_int2big_stub
79-
#endif
76+
# define rb_num2long rb_num2long_stub
77+
# define rb_int2big rb_int2big_stub
8078

81-
#if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 19 \
82-
&& VIM_SIZEOF_INT < VIM_SIZEOF_LONG
79+
# if RUBY_VERSION >= 30 || VIM_SIZEOF_INT < VIM_SIZEOF_LONG
8380
// Ruby 1.9 defines a number of static functions which use rb_fix2int and
8481
// rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit)
85-
# define rb_fix2int rb_fix2int_stub
86-
# define rb_num2int rb_num2int_stub
87-
#endif
82+
# define rb_fix2int rb_fix2int_stub
83+
# define rb_num2int rb_num2int_stub
84+
# endif
85+
# endif
8886

89-
#if defined(DYNAMIC_RUBY) && RUBY_VERSION == 21
87+
# if RUBY_VERSION == 21
9088
// Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses
9189
// rb_gc_writebarrier_unprotect_promoted if USE_RGENGC
92-
# define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub
93-
#endif
94-
#if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 22
95-
# define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub
96-
#endif
90+
# define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub
91+
# endif
9792

98-
#if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 26
99-
# define rb_ary_detransient rb_ary_detransient_stub
100-
#endif
93+
# if RUBY_VERSION >= 22
94+
# define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub
95+
# endif
96+
97+
# if RUBY_VERSION >= 26
98+
# define rb_ary_detransient rb_ary_detransient_stub
99+
# endif
100+
101+
# if RUBY_VERSION >= 30
102+
# define rb_check_type rb_check_type_stub
103+
# define rb_num2uint rb_num2uint_stub
104+
# define ruby_malloc_size_overflow ruby_malloc_size_overflow_stub
105+
# endif
106+
107+
#endif // ifdef DYNAMIC_RUBY
101108

102109
// On macOS pre-installed Ruby defines "SIZEOF_TIME_T" as "SIZEOF_LONG" so it
103110
// conflicts with the definition in config.h then causes a macro-redefined
@@ -232,7 +239,9 @@ static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
232239
# define rb_assoc_new dll_rb_assoc_new
233240
# define rb_cObject (*dll_rb_cObject)
234241
# define rb_class_new_instance dll_rb_class_new_instance
235-
# define rb_check_type dll_rb_check_type
242+
# if RUBY_VERSION < 30
243+
# define rb_check_type dll_rb_check_type
244+
# endif
236245
# ifdef USE_TYPEDDATA
237246
# define rb_check_typeddata dll_rb_check_typeddata
238247
# endif
@@ -283,7 +292,9 @@ static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
283292
# define rb_fix2int dll_rb_fix2int
284293
# define rb_num2int dll_rb_num2int
285294
# endif
286-
# define rb_num2uint dll_rb_num2uint
295+
# if RUBY_VERSION < 30
296+
# define rb_num2uint dll_rb_num2uint
297+
# endif
287298
# endif
288299
# define rb_num2dbl dll_rb_num2dbl
289300
# define rb_lastline_get dll_rb_lastline_get
@@ -501,7 +512,7 @@ static rb_encoding* (*dll_rb_enc_find) (const char*);
501512
static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*);
502513
static VALUE (*dll_rb_sprintf) (const char*, ...);
503514
static VALUE (*dll_rb_require) (const char*);
504-
static void* (*ruby_options)(int, char**);
515+
static void* (*dll_ruby_options)(int, char**);
505516
# endif
506517

507518
# if defined(USE_RGENGC) && USE_RGENGC
@@ -512,32 +523,38 @@ static void (*dll_rb_gc_writebarrier_unprotect)(VALUE obj);
512523
# endif
513524
# endif
514525

526+
# if RUBY_VERSION >= 30
527+
NORETURN(static void (*dll_ruby_malloc_size_overflow)(size_t, size_t));
528+
# endif
529+
515530
# if RUBY_VERSION >= 26
516531
void rb_ary_detransient_stub(VALUE x);
517532
# endif
518533

519-
# if (RUBY_VERSION >= 19) && !defined(PROTO)
520-
# if RUBY_VERSION >= 22
534+
// Do not generate a prototype here, VALUE isn't always defined.
535+
# ifndef PROTO
536+
# if RUBY_VERSION >= 19
537+
# if RUBY_VERSION >= 22
521538
long
522539
rb_num2long_stub(VALUE x)
523-
# else
540+
# else
524541
SIGNED_VALUE
525542
rb_num2long_stub(VALUE x)
526-
# endif
543+
# endif
527544
{
528545
return dll_rb_num2long(x);
529546
}
530-
# if RUBY_VERSION >= 26
547+
# if RUBY_VERSION >= 26
531548
VALUE
532549
rb_int2big_stub(intptr_t x)
533-
# else
550+
# else
534551
VALUE
535552
rb_int2big_stub(SIGNED_VALUE x)
536-
# endif
553+
# endif
537554
{
538555
return dll_rb_int2big(x);
539556
}
540-
# if (RUBY_VERSION >= 19) && (VIM_SIZEOF_INT < VIM_SIZEOF_LONG)
557+
# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG
541558
long
542559
rb_fix2int_stub(VALUE x)
543560
{
@@ -548,50 +565,65 @@ rb_num2int_stub(VALUE x)
548565
{
549566
return dll_rb_num2int(x);
550567
}
551-
# endif
552-
# if RUBY_VERSION >= 20
568+
# endif
569+
# if RUBY_VERSION >= 20
553570
VALUE
554571
rb_float_new_in_heap(double d)
555572
{
556573
return dll_rb_float_new(d);
557574
}
558-
# if RUBY_VERSION >= 22
575+
# if RUBY_VERSION >= 22
559576
unsigned long
560577
rb_num2ulong(VALUE x)
561-
# else
578+
# else
562579
VALUE
563580
rb_num2ulong(VALUE x)
564-
# endif
581+
# endif
565582
{
566583
return (long)RSHIFT((SIGNED_VALUE)(x),1);
567584
}
585+
# endif
568586
# endif
569-
# endif
570-
571-
// Do not generate a prototype here, VALUE isn't always defined.
572-
# if defined(USE_RGENGC) && USE_RGENGC && !defined(PROTO)
573-
# if RUBY_VERSION == 21
587+
# if defined(USE_RGENGC) && USE_RGENGC
588+
# if RUBY_VERSION == 21
574589
void
575590
rb_gc_writebarrier_unprotect_promoted_stub(VALUE obj)
576591
{
577592
dll_rb_gc_writebarrier_unprotect_promoted(obj);
578593
}
579-
# else
594+
# else
580595
void
581596
rb_gc_writebarrier_unprotect_stub(VALUE obj)
582597
{
583598
dll_rb_gc_writebarrier_unprotect(obj);
584599
}
600+
# endif
585601
# endif
586-
# endif
587-
588-
# if RUBY_VERSION >= 26
602+
# if RUBY_VERSION >= 26
589603
void
590604
rb_ary_detransient_stub(VALUE x)
591605
{
592606
dll_rb_ary_detransient(x);
593607
}
594-
# endif
608+
# endif
609+
# if RUBY_VERSION >= 30
610+
void
611+
rb_check_type_stub(VALUE obj, int t)
612+
{
613+
dll_rb_check_type(obj, t);
614+
}
615+
unsigned long
616+
rb_num2uint_stub(VALUE x)
617+
{
618+
return dll_rb_num2uint(x);
619+
}
620+
void
621+
ruby_malloc_size_overflow_stub(size_t x, size_t y)
622+
{
623+
dll_ruby_malloc_size_overflow(x, y);
624+
}
625+
# endif
626+
# endif // ifndef PROTO
595627

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

@@ -747,6 +779,9 @@ static struct
747779
# else
748780
{"rb_gc_writebarrier_unprotect", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect},
749781
# endif
782+
# endif
783+
# if RUBY_VERSION >= 30
784+
{"ruby_malloc_size_overflow", (RUBY_PROC*)&dll_ruby_malloc_size_overflow},
750785
# endif
751786
{"", NULL},
752787
};
@@ -1827,7 +1862,7 @@ convert_hash2dict(VALUE key, VALUE val, VALUE arg)
18271862
dict_T *d = (dict_T *)arg;
18281863
dictitem_T *di;
18291864

1830-
di = dictitem_alloc((char_u *)RSTRING_PTR(RSTRING(rb_obj_as_string(key))));
1865+
di = dictitem_alloc((char_u *)RSTRING_PTR(rb_obj_as_string(key)));
18311866
if (di == NULL || ruby_convert_to_vim_value(val, &di->di_tv) != OK
18321867
|| dict_add(d, di) != OK)
18331868
{

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2235,
753755
/**/
754756
2234,
755757
/**/

0 commit comments

Comments
 (0)