Mercurial > vim
comparison src/if_ruby.c @ 23384:f719577ddae6 v8.2.2235
patch 8.2.2235: build failure with some Ruby versions
Commit: https://github.com/vim/vim/commit/dace9f785fca6cc802b2fb7f11a5ee4fab896432
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 28 15:07:45 2020 +0100
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 https://github.com/vim/vim/issues/7564)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 28 Dec 2020 15:15:03 +0100 |
parents | 19575087e859 |
children | bb0c53f4ef8b |
comparison
equal
deleted
inserted
replaced
23383:68a3d16e47cb | 23384:f719577ddae6 |
---|---|
30 #endif | 30 #endif |
31 #ifndef RUBYEXTERN | 31 #ifndef RUBYEXTERN |
32 # define RUBYEXTERN extern | 32 # define RUBYEXTERN extern |
33 #endif | 33 #endif |
34 | 34 |
35 #if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 24 | 35 // suggested by Ariya Mizutani |
36 # define USE_RUBY_INTEGER | 36 #if (_MSC_VER == 1200) |
37 # undef _WIN32_WINNT | |
37 #endif | 38 #endif |
38 | 39 |
39 #ifdef DYNAMIC_RUBY | 40 #ifdef DYNAMIC_RUBY |
40 /* | 41 /* |
41 * This is tricky. In ruby.h there is (inline) function rb_class_of() | 42 * This is tricky. In ruby.h there is (inline) function rb_class_of() |
42 * definition. This function use these variables. But we want function to | 43 * definition. This function use these variables. But we want function to |
43 * use dll_* variables. | 44 * use dll_* variables. |
44 */ | 45 */ |
46 # if RUBY_VERSION >= 24 | |
47 # define USE_RUBY_INTEGER | |
48 # endif | |
49 | |
45 # define rb_cFalseClass (*dll_rb_cFalseClass) | 50 # define rb_cFalseClass (*dll_rb_cFalseClass) |
46 # define rb_cFixnum (*dll_rb_cFixnum) | 51 # define rb_cFixnum (*dll_rb_cFixnum) |
47 # if defined(USE_RUBY_INTEGER) | 52 # if defined(USE_RUBY_INTEGER) |
48 # define rb_cInteger (*dll_rb_cInteger) | 53 # define rb_cInteger (*dll_rb_cInteger) |
49 # endif | 54 # endif |
52 # endif | 57 # endif |
53 # define rb_cNilClass (*dll_rb_cNilClass) | 58 # define rb_cNilClass (*dll_rb_cNilClass) |
54 # define rb_cString (*dll_rb_cString) | 59 # define rb_cString (*dll_rb_cString) |
55 # define rb_cSymbol (*dll_rb_cSymbol) | 60 # define rb_cSymbol (*dll_rb_cSymbol) |
56 # define rb_cTrueClass (*dll_rb_cTrueClass) | 61 # define rb_cTrueClass (*dll_rb_cTrueClass) |
62 | |
57 # if RUBY_VERSION >= 18 | 63 # if RUBY_VERSION >= 18 |
58 /* | 64 /* |
59 * On ver 1.8, all Ruby functions are exported with "__declspec(dllimport)" | 65 * On ver 1.8, all Ruby functions are exported with "__declspec(dllimport)" |
60 * in ruby.h. But it causes trouble for these variables, because it is | 66 * in ruby.h. But it causes trouble for these variables, because it is |
61 * defined in this file. When defined this RUBY_EXPORT it modified to | 67 * defined in this file. When defined this RUBY_EXPORT it modified to |
62 * "extern" and be able to avoid this problem. | 68 * "extern" and be able to avoid this problem. |
63 */ | 69 */ |
64 # define RUBY_EXPORT | 70 # define RUBY_EXPORT |
65 # endif | 71 # endif |
66 | 72 |
67 #endif // ifdef DYNAMIC_RUBY | 73 # if RUBY_VERSION >= 19 |
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 | |
75 // Ruby 1.9 defines a number of static functions which use rb_num2long and | 74 // Ruby 1.9 defines a number of static functions which use rb_num2long and |
76 // rb_int2big | 75 // rb_int2big |
77 # define rb_num2long rb_num2long_stub | 76 # define rb_num2long rb_num2long_stub |
78 # define rb_int2big rb_int2big_stub | 77 # define rb_int2big rb_int2big_stub |
79 #endif | 78 |
80 | 79 # if RUBY_VERSION >= 30 || VIM_SIZEOF_INT < VIM_SIZEOF_LONG |
81 #if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 19 \ | |
82 && VIM_SIZEOF_INT < VIM_SIZEOF_LONG | |
83 // Ruby 1.9 defines a number of static functions which use rb_fix2int and | 80 // Ruby 1.9 defines a number of static functions which use rb_fix2int and |
84 // rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit) | 81 // rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit) |
85 # define rb_fix2int rb_fix2int_stub | 82 # define rb_fix2int rb_fix2int_stub |
86 # define rb_num2int rb_num2int_stub | 83 # define rb_num2int rb_num2int_stub |
87 #endif | 84 # endif |
88 | 85 # endif |
89 #if defined(DYNAMIC_RUBY) && RUBY_VERSION == 21 | 86 |
87 # if RUBY_VERSION == 21 | |
90 // Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses | 88 // Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses |
91 // rb_gc_writebarrier_unprotect_promoted if USE_RGENGC | 89 // rb_gc_writebarrier_unprotect_promoted if USE_RGENGC |
92 # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub | 90 # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub |
93 #endif | 91 # endif |
94 #if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 22 | 92 |
95 # define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub | 93 # if RUBY_VERSION >= 22 |
96 #endif | 94 # define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub |
97 | 95 # endif |
98 #if defined(DYNAMIC_RUBY) && RUBY_VERSION >= 26 | 96 |
99 # define rb_ary_detransient rb_ary_detransient_stub | 97 # if RUBY_VERSION >= 26 |
100 #endif | 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 | |
101 | 108 |
102 // On macOS pre-installed Ruby defines "SIZEOF_TIME_T" as "SIZEOF_LONG" so it | 109 // On macOS pre-installed Ruby defines "SIZEOF_TIME_T" as "SIZEOF_LONG" so it |
103 // conflicts with the definition in config.h then causes a macro-redefined | 110 // conflicts with the definition in config.h then causes a macro-redefined |
104 // warning. | 111 // warning. |
105 #ifdef SIZEOF_TIME_T | 112 #ifdef SIZEOF_TIME_T |
230 # endif | 237 # endif |
231 | 238 |
232 # define rb_assoc_new dll_rb_assoc_new | 239 # define rb_assoc_new dll_rb_assoc_new |
233 # define rb_cObject (*dll_rb_cObject) | 240 # define rb_cObject (*dll_rb_cObject) |
234 # define rb_class_new_instance dll_rb_class_new_instance | 241 # 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 | |
236 # ifdef USE_TYPEDDATA | 245 # ifdef USE_TYPEDDATA |
237 # define rb_check_typeddata dll_rb_check_typeddata | 246 # define rb_check_typeddata dll_rb_check_typeddata |
238 # endif | 247 # endif |
239 # define rb_class_path dll_rb_class_path | 248 # define rb_class_path dll_rb_class_path |
240 # ifdef USE_TYPEDDATA | 249 # ifdef USE_TYPEDDATA |
281 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only | 290 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only |
282 # if RUBY_VERSION <= 18 | 291 # if RUBY_VERSION <= 18 |
283 # define rb_fix2int dll_rb_fix2int | 292 # define rb_fix2int dll_rb_fix2int |
284 # define rb_num2int dll_rb_num2int | 293 # define rb_num2int dll_rb_num2int |
285 # endif | 294 # endif |
286 # define rb_num2uint dll_rb_num2uint | 295 # if RUBY_VERSION < 30 |
296 # define rb_num2uint dll_rb_num2uint | |
297 # endif | |
287 # endif | 298 # endif |
288 # define rb_num2dbl dll_rb_num2dbl | 299 # define rb_num2dbl dll_rb_num2dbl |
289 # define rb_lastline_get dll_rb_lastline_get | 300 # define rb_lastline_get dll_rb_lastline_get |
290 # define rb_lastline_set dll_rb_lastline_set | 301 # define rb_lastline_set dll_rb_lastline_set |
291 # define rb_protect dll_rb_protect | 302 # define rb_protect dll_rb_protect |
499 static int (*dll_rb_enc_find_index) (const char*); | 510 static int (*dll_rb_enc_find_index) (const char*); |
500 static rb_encoding* (*dll_rb_enc_find) (const char*); | 511 static rb_encoding* (*dll_rb_enc_find) (const char*); |
501 static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*); | 512 static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*); |
502 static VALUE (*dll_rb_sprintf) (const char*, ...); | 513 static VALUE (*dll_rb_sprintf) (const char*, ...); |
503 static VALUE (*dll_rb_require) (const char*); | 514 static VALUE (*dll_rb_require) (const char*); |
504 static void* (*ruby_options)(int, char**); | 515 static void* (*dll_ruby_options)(int, char**); |
505 # endif | 516 # endif |
506 | 517 |
507 # if defined(USE_RGENGC) && USE_RGENGC | 518 # if defined(USE_RGENGC) && USE_RGENGC |
508 # if RUBY_VERSION == 21 | 519 # if RUBY_VERSION == 21 |
509 static void (*dll_rb_gc_writebarrier_unprotect_promoted)(VALUE); | 520 static void (*dll_rb_gc_writebarrier_unprotect_promoted)(VALUE); |
510 # else | 521 # else |
511 static void (*dll_rb_gc_writebarrier_unprotect)(VALUE obj); | 522 static void (*dll_rb_gc_writebarrier_unprotect)(VALUE obj); |
512 # endif | 523 # endif |
513 # endif | 524 # endif |
514 | 525 |
526 # if RUBY_VERSION >= 30 | |
527 NORETURN(static void (*dll_ruby_malloc_size_overflow)(size_t, size_t)); | |
528 # endif | |
529 | |
515 # if RUBY_VERSION >= 26 | 530 # if RUBY_VERSION >= 26 |
516 void rb_ary_detransient_stub(VALUE x); | 531 void rb_ary_detransient_stub(VALUE x); |
517 # endif | 532 # endif |
518 | 533 |
519 # if (RUBY_VERSION >= 19) && !defined(PROTO) | 534 // Do not generate a prototype here, VALUE isn't always defined. |
520 # if RUBY_VERSION >= 22 | 535 # ifndef PROTO |
536 # if RUBY_VERSION >= 19 | |
537 # if RUBY_VERSION >= 22 | |
521 long | 538 long |
522 rb_num2long_stub(VALUE x) | 539 rb_num2long_stub(VALUE x) |
523 # else | 540 # else |
524 SIGNED_VALUE | 541 SIGNED_VALUE |
525 rb_num2long_stub(VALUE x) | 542 rb_num2long_stub(VALUE x) |
526 # endif | 543 # endif |
527 { | 544 { |
528 return dll_rb_num2long(x); | 545 return dll_rb_num2long(x); |
529 } | 546 } |
530 # if RUBY_VERSION >= 26 | 547 # if RUBY_VERSION >= 26 |
531 VALUE | 548 VALUE |
532 rb_int2big_stub(intptr_t x) | 549 rb_int2big_stub(intptr_t x) |
533 # else | 550 # else |
534 VALUE | 551 VALUE |
535 rb_int2big_stub(SIGNED_VALUE x) | 552 rb_int2big_stub(SIGNED_VALUE x) |
536 # endif | 553 # endif |
537 { | 554 { |
538 return dll_rb_int2big(x); | 555 return dll_rb_int2big(x); |
539 } | 556 } |
540 # if (RUBY_VERSION >= 19) && (VIM_SIZEOF_INT < VIM_SIZEOF_LONG) | 557 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG |
541 long | 558 long |
542 rb_fix2int_stub(VALUE x) | 559 rb_fix2int_stub(VALUE x) |
543 { | 560 { |
544 return dll_rb_fix2int(x); | 561 return dll_rb_fix2int(x); |
545 } | 562 } |
546 long | 563 long |
547 rb_num2int_stub(VALUE x) | 564 rb_num2int_stub(VALUE x) |
548 { | 565 { |
549 return dll_rb_num2int(x); | 566 return dll_rb_num2int(x); |
550 } | 567 } |
551 # endif | 568 # endif |
552 # if RUBY_VERSION >= 20 | 569 # if RUBY_VERSION >= 20 |
553 VALUE | 570 VALUE |
554 rb_float_new_in_heap(double d) | 571 rb_float_new_in_heap(double d) |
555 { | 572 { |
556 return dll_rb_float_new(d); | 573 return dll_rb_float_new(d); |
557 } | 574 } |
558 # if RUBY_VERSION >= 22 | 575 # if RUBY_VERSION >= 22 |
559 unsigned long | 576 unsigned long |
560 rb_num2ulong(VALUE x) | 577 rb_num2ulong(VALUE x) |
561 # else | 578 # else |
562 VALUE | 579 VALUE |
563 rb_num2ulong(VALUE x) | 580 rb_num2ulong(VALUE x) |
581 # endif | |
582 { | |
583 return (long)RSHIFT((SIGNED_VALUE)(x),1); | |
584 } | |
564 # endif | 585 # endif |
565 { | 586 # endif |
566 return (long)RSHIFT((SIGNED_VALUE)(x),1); | 587 # if defined(USE_RGENGC) && USE_RGENGC |
567 } | 588 # if RUBY_VERSION == 21 |
568 # 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 | |
574 void | 589 void |
575 rb_gc_writebarrier_unprotect_promoted_stub(VALUE obj) | 590 rb_gc_writebarrier_unprotect_promoted_stub(VALUE obj) |
576 { | 591 { |
577 dll_rb_gc_writebarrier_unprotect_promoted(obj); | 592 dll_rb_gc_writebarrier_unprotect_promoted(obj); |
578 } | 593 } |
579 # else | 594 # else |
580 void | 595 void |
581 rb_gc_writebarrier_unprotect_stub(VALUE obj) | 596 rb_gc_writebarrier_unprotect_stub(VALUE obj) |
582 { | 597 { |
583 dll_rb_gc_writebarrier_unprotect(obj); | 598 dll_rb_gc_writebarrier_unprotect(obj); |
584 } | 599 } |
585 # endif | 600 # endif |
586 # endif | 601 # endif |
587 | 602 # if RUBY_VERSION >= 26 |
588 # if RUBY_VERSION >= 26 | |
589 void | 603 void |
590 rb_ary_detransient_stub(VALUE x) | 604 rb_ary_detransient_stub(VALUE x) |
591 { | 605 { |
592 dll_rb_ary_detransient(x); | 606 dll_rb_ary_detransient(x); |
593 } | 607 } |
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 | |
595 | 627 |
596 static HINSTANCE hinstRuby = NULL; // Instance of ruby.dll | 628 static HINSTANCE hinstRuby = NULL; // Instance of ruby.dll |
597 | 629 |
598 /* | 630 /* |
599 * Table of name to function pointer of ruby. | 631 * Table of name to function pointer of ruby. |
745 # if RUBY_VERSION == 21 | 777 # if RUBY_VERSION == 21 |
746 {"rb_gc_writebarrier_unprotect_promoted", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect_promoted}, | 778 {"rb_gc_writebarrier_unprotect_promoted", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect_promoted}, |
747 # else | 779 # else |
748 {"rb_gc_writebarrier_unprotect", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect}, | 780 {"rb_gc_writebarrier_unprotect", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect}, |
749 # endif | 781 # endif |
782 # endif | |
783 # if RUBY_VERSION >= 30 | |
784 {"ruby_malloc_size_overflow", (RUBY_PROC*)&dll_ruby_malloc_size_overflow}, | |
750 # endif | 785 # endif |
751 {"", NULL}, | 786 {"", NULL}, |
752 }; | 787 }; |
753 | 788 |
754 /* | 789 /* |
1825 convert_hash2dict(VALUE key, VALUE val, VALUE arg) | 1860 convert_hash2dict(VALUE key, VALUE val, VALUE arg) |
1826 { | 1861 { |
1827 dict_T *d = (dict_T *)arg; | 1862 dict_T *d = (dict_T *)arg; |
1828 dictitem_T *di; | 1863 dictitem_T *di; |
1829 | 1864 |
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))); |
1831 if (di == NULL || ruby_convert_to_vim_value(val, &di->di_tv) != OK | 1866 if (di == NULL || ruby_convert_to_vim_value(val, &di->di_tv) != OK |
1832 || dict_add(d, di) != OK) | 1867 || dict_add(d, di) != OK) |
1833 { | 1868 { |
1834 d->dv_hashtab.ht_error = TRUE; | 1869 d->dv_hashtab.ht_error = TRUE; |
1835 return ST_STOP; | 1870 return ST_STOP; |