comparison src/if_ruby.c @ 30421:425b686c5244 v9.0.0546

patch 9.0.0546: supporting Ruby 1.8 makes code complicated Commit: https://github.com/vim/vim/commit/236ccbf6f8a671a45b773de4b34558ecfdf9ac02 Author: K.Takata <kentkt@csc.jp> Date: Thu Sep 22 16:12:06 2022 +0100 patch 9.0.0546: supporting Ruby 1.8 makes code complicated Problem: Supporting Ruby 1.8 makes code complicated. Solution: Drop Ruby 1.8 support, it is ancient. (Ken Takata, closes https://github.com/vim/vim/issues/11195)
author Bram Moolenaar <Bram@vim.org>
date Thu, 22 Sep 2022 17:15:03 +0200
parents 029c59bf78f1
children 684e6dfa2fba
comparison
equal deleted inserted replaced
30420:920fc6b9b395 30421:425b686c5244
18 18
19 #include <stdio.h> 19 #include <stdio.h>
20 #include <string.h> 20 #include <string.h>
21 21
22 #ifdef _WIN32 22 #ifdef _WIN32
23 # if !defined(DYNAMIC_RUBY) || (RUBY_VERSION < 18) 23 # ifndef DYNAMIC_RUBY
24 # define NT 24 # define NT
25 # endif
26 # ifndef DYNAMIC_RUBY
27 # define IMPORT // For static dll usage __declspec(dllimport) 25 # define IMPORT // For static dll usage __declspec(dllimport)
28 # define RUBYEXTERN __declspec(dllimport) 26 # define RUBYEXTERN __declspec(dllimport)
29 # endif 27 # endif
30 #endif 28 #endif
31 #ifndef RUBYEXTERN 29 #ifndef RUBYEXTERN
53 # define rb_cNilClass (*dll_rb_cNilClass) 51 # define rb_cNilClass (*dll_rb_cNilClass)
54 # define rb_cString (*dll_rb_cString) 52 # define rb_cString (*dll_rb_cString)
55 # define rb_cSymbol (*dll_rb_cSymbol) 53 # define rb_cSymbol (*dll_rb_cSymbol)
56 # define rb_cTrueClass (*dll_rb_cTrueClass) 54 # define rb_cTrueClass (*dll_rb_cTrueClass)
57 55
58 # if RUBY_VERSION >= 18
59 /* 56 /*
60 * On ver 1.8, all Ruby functions are exported with "__declspec(dllimport)" 57 * All Ruby functions are exported with "__declspec(dllimport)" in ruby.h.
61 * in ruby.h. But it causes trouble for these variables, because it is 58 * But it causes trouble for these variables, because it is defined in this
62 * defined in this file. When defined this RUBY_EXPORT it modified to 59 * file. When defined this RUBY_EXPORT it modified to "extern" and be able
63 * "extern" and be able to avoid this problem. 60 * to avoid this problem.
64 */ 61 */
65 # define RUBY_EXPORT 62 # define RUBY_EXPORT
66 # endif 63
67
68 # if RUBY_VERSION >= 19
69 // Ruby 1.9 defines a number of static functions which use rb_num2long and 64 // Ruby 1.9 defines a number of static functions which use rb_num2long and
70 // rb_int2big 65 // rb_int2big
71 # define rb_num2long rb_num2long_stub 66 # define rb_num2long rb_num2long_stub
72 # define rb_int2big rb_int2big_stub 67 # define rb_int2big rb_int2big_stub
73 68
74 # if RUBY_VERSION >= 30 || VIM_SIZEOF_INT < VIM_SIZEOF_LONG 69 # if RUBY_VERSION >= 30 || VIM_SIZEOF_INT < VIM_SIZEOF_LONG
75 // Ruby 1.9 defines a number of static functions which use rb_fix2int and 70 // Ruby 1.9 defines a number of static functions which use rb_fix2int and
76 // rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit) 71 // rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit)
77 # define rb_fix2int rb_fix2int_stub 72 # define rb_fix2int rb_fix2int_stub
78 # define rb_num2int rb_num2int_stub 73 # define rb_num2int rb_num2int_stub
79 # endif
80 # endif 74 # endif
81 75
82 # if RUBY_VERSION == 21 76 # if RUBY_VERSION == 21
83 // Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses 77 // Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses
84 // rb_gc_writebarrier_unprotect_promoted if USE_RGENGC 78 // rb_gc_writebarrier_unprotect_promoted if USE_RGENGC
112 #ifdef SIZEOF_TIME_T 106 #ifdef SIZEOF_TIME_T
113 # undef SIZEOF_TIME_T 107 # undef SIZEOF_TIME_T
114 #endif 108 #endif
115 109
116 #include <ruby.h> 110 #include <ruby.h>
117 #if RUBY_VERSION >= 19 111 #include <ruby/encoding.h>
118 # include <ruby/encoding.h>
119 #endif
120 #if RUBY_VERSION <= 18
121 # include <st.h> // for ST_STOP and ST_CONTINUE
122 #endif
123 112
124 // See above. 113 // See above.
125 #ifdef SIZEOF_TIME_T 114 #ifdef SIZEOF_TIME_T
126 # undef SIZEOF_TIME_T 115 # undef SIZEOF_TIME_T
127 #endif 116 #endif
222 static void error_print(int); 211 static void error_print(int);
223 static void ruby_io_init(void); 212 static void ruby_io_init(void);
224 static void ruby_vim_init(void); 213 static void ruby_vim_init(void);
225 static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv); 214 static int ruby_convert_to_vim_value(VALUE val, typval_T *rettv);
226 215
227 #if (RUBY_VERSION >= 19) || defined(RUBY_INIT_STACK) 216 #if defined(__ia64) && !defined(ruby_init_stack)
228 # if defined(__ia64) && !defined(ruby_init_stack) 217 # define ruby_init_stack(addr) ruby_init_stack((addr), rb_ia64_bsp())
229 # define ruby_init_stack(addr) ruby_init_stack((addr), rb_ia64_bsp())
230 # endif
231 #endif 218 #endif
232 219
233 #if defined(DYNAMIC_RUBY) || defined(PROTO) 220 #if defined(DYNAMIC_RUBY) || defined(PROTO)
234 # if defined(PROTO) && !defined(HINSTANCE) 221 # if defined(PROTO) && !defined(HINSTANCE)
235 # define HINSTANCE int // for generating prototypes 222 # define HINSTANCE int // for generating prototypes
296 // work. Not using the cache appears to be the best solution. 283 // work. Not using the cache appears to be the best solution.
297 # undef rb_intern 284 # undef rb_intern
298 # define rb_intern dll_rb_intern 285 # define rb_intern dll_rb_intern
299 286
300 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only 287 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only
301 # if RUBY_VERSION <= 18
302 # define rb_fix2int dll_rb_fix2int
303 # define rb_num2int dll_rb_num2int
304 # endif
305 # if RUBY_VERSION < 30 288 # if RUBY_VERSION < 30
306 # define rb_num2uint dll_rb_num2uint 289 # define rb_num2uint dll_rb_num2uint
307 # endif 290 # endif
308 # endif 291 # endif
309 # define rb_num2dbl dll_rb_num2dbl 292 # define rb_num2dbl dll_rb_num2dbl
310 # define rb_lastline_get dll_rb_lastline_get 293 # define rb_lastline_get dll_rb_lastline_get
311 # define rb_lastline_set dll_rb_lastline_set 294 # define rb_lastline_set dll_rb_lastline_set
312 # define rb_protect dll_rb_protect 295 # define rb_protect dll_rb_protect
313 # define rb_load dll_rb_load 296 # define rb_load dll_rb_load
314 # if RUBY_VERSION <= 18 297 # if RUBY_VERSION < 20
315 # define rb_num2long dll_rb_num2long
316 # endif
317 # if RUBY_VERSION <= 19
318 # define rb_num2ulong dll_rb_num2ulong 298 # define rb_num2ulong dll_rb_num2ulong
319 # endif 299 # endif
320 # define rb_obj_alloc dll_rb_obj_alloc 300 # define rb_obj_alloc dll_rb_obj_alloc
321 # define rb_obj_as_string dll_rb_obj_as_string 301 # define rb_obj_as_string dll_rb_obj_as_string
322 # define rb_obj_id dll_rb_obj_id 302 # define rb_obj_id dll_rb_obj_id
333 # undef rb_str_new_cstr 313 # undef rb_str_new_cstr
334 # define rb_str_new_cstr dll_rb_str_new_cstr 314 # define rb_str_new_cstr dll_rb_str_new_cstr
335 # else 315 # else
336 # define rb_str_new2 dll_rb_str_new2 316 # define rb_str_new2 dll_rb_str_new2
337 # endif 317 # endif
338 # if RUBY_VERSION >= 18 318 # define rb_string_value dll_rb_string_value
339 # define rb_string_value dll_rb_string_value 319 # define rb_string_value_ptr dll_rb_string_value_ptr
340 # define rb_string_value_ptr dll_rb_string_value_ptr 320 # define rb_float_new dll_rb_float_new
341 # define rb_float_new dll_rb_float_new 321 # define rb_ary_new dll_rb_ary_new
342 # define rb_ary_new dll_rb_ary_new 322 # ifdef rb_ary_new4
343 # ifdef rb_ary_new4 323 # define RB_ARY_NEW4_MACRO 1
344 # define RB_ARY_NEW4_MACRO 1 324 # undef rb_ary_new4
345 # undef rb_ary_new4 325 # endif
346 # endif 326 # define rb_ary_new4 dll_rb_ary_new4
347 # define rb_ary_new4 dll_rb_ary_new4 327 # define rb_ary_push dll_rb_ary_push
348 # define rb_ary_push dll_rb_ary_push 328 # ifdef __ia64
349 # if (RUBY_VERSION >= 19) || defined(RUBY_INIT_STACK) 329 # define rb_ia64_bsp dll_rb_ia64_bsp
350 # ifdef __ia64 330 # undef ruby_init_stack
351 # define rb_ia64_bsp dll_rb_ia64_bsp 331 # define ruby_init_stack(addr) dll_ruby_init_stack((addr), rb_ia64_bsp())
352 # undef ruby_init_stack
353 # define ruby_init_stack(addr) dll_ruby_init_stack((addr), rb_ia64_bsp())
354 # else
355 # define ruby_init_stack dll_ruby_init_stack
356 # endif
357 # endif
358 # else 332 # else
359 # define rb_str2cstr dll_rb_str2cstr 333 # define ruby_init_stack dll_ruby_init_stack
360 # endif 334 # endif
361 # if RUBY_VERSION >= 19 335 # define rb_errinfo dll_rb_errinfo
362 # define rb_errinfo dll_rb_errinfo
363 # else
364 # define ruby_errinfo (*dll_ruby_errinfo)
365 # endif
366 # define ruby_init dll_ruby_init 336 # define ruby_init dll_ruby_init
367 # define ruby_init_loadpath dll_ruby_init_loadpath 337 # define ruby_init_loadpath dll_ruby_init_loadpath
368 # ifdef MSWIN 338 # ifdef MSWIN
369 # if RUBY_VERSION >= 19 339 # define ruby_sysinit dll_ruby_sysinit
370 # define ruby_sysinit dll_ruby_sysinit 340 # define rb_w32_snprintf dll_rb_w32_snprintf
371 # else 341 # endif
372 # define NtInitialize dll_NtInitialize 342
373 # endif 343 # define ruby_script dll_ruby_script
374 # if RUBY_VERSION >= 18 344 # define rb_enc_find_index dll_rb_enc_find_index
375 # define rb_w32_snprintf dll_rb_w32_snprintf 345 # define rb_enc_find dll_rb_enc_find
376 # endif 346 # undef rb_enc_str_new
377 # endif 347 # define rb_enc_str_new dll_rb_enc_str_new
378 348 # define rb_sprintf dll_rb_sprintf
379 # if RUBY_VERSION >= 19 349 # define rb_require dll_rb_require
380 # define ruby_script dll_ruby_script 350 # define ruby_options dll_ruby_options
381 # define rb_enc_find_index dll_rb_enc_find_index
382 # define rb_enc_find dll_rb_enc_find
383 # undef rb_enc_str_new
384 # define rb_enc_str_new dll_rb_enc_str_new
385 # define rb_sprintf dll_rb_sprintf
386 # define rb_require dll_rb_require
387 # define ruby_options dll_ruby_options
388 # endif
389 351
390 /* 352 /*
391 * Pointers for dynamic link 353 * Pointers for dynamic link
392 */ 354 */
393 static VALUE (*dll_rb_assoc_new) (VALUE, VALUE); 355 static VALUE (*dll_rb_assoc_new) (VALUE, VALUE);
463 static unsigned long (*dll_rb_num2ulong) (VALUE); 425 static unsigned long (*dll_rb_num2ulong) (VALUE);
464 static VALUE (*dll_rb_obj_alloc) (VALUE); 426 static VALUE (*dll_rb_obj_alloc) (VALUE);
465 static VALUE (*dll_rb_obj_as_string) (VALUE); 427 static VALUE (*dll_rb_obj_as_string) (VALUE);
466 static VALUE (*dll_rb_obj_id) (VALUE); 428 static VALUE (*dll_rb_obj_id) (VALUE);
467 static void (*dll_rb_raise) (VALUE, const char*, ...); 429 static void (*dll_rb_raise) (VALUE, const char*, ...);
468 # if RUBY_VERSION >= 18
469 static VALUE (*dll_rb_string_value) (volatile VALUE*); 430 static VALUE (*dll_rb_string_value) (volatile VALUE*);
470 # else
471 static char *(*dll_rb_str2cstr) (VALUE,int*);
472 # endif
473 static VALUE (*dll_rb_str_cat) (VALUE, const char*, long); 431 static VALUE (*dll_rb_str_cat) (VALUE, const char*, long);
474 static VALUE (*dll_rb_str_concat) (VALUE, VALUE); 432 static VALUE (*dll_rb_str_concat) (VALUE, VALUE);
475 static VALUE (*dll_rb_str_new) (const char*, long); 433 static VALUE (*dll_rb_str_new) (const char*, long);
476 # ifdef need_rb_str_new_cstr 434 # ifdef need_rb_str_new_cstr
477 // Ruby may #define rb_str_new2 to use rb_str_new_cstr. 435 // Ruby may #define rb_str_new2 to use rb_str_new_cstr.
478 static VALUE (*dll_rb_str_new_cstr) (const char*); 436 static VALUE (*dll_rb_str_new_cstr) (const char*);
479 # else 437 # else
480 static VALUE (*dll_rb_str_new2) (const char*); 438 static VALUE (*dll_rb_str_new2) (const char*);
481 # endif 439 # endif
482 # if RUBY_VERSION >= 19
483 static VALUE (*dll_rb_errinfo) (void); 440 static VALUE (*dll_rb_errinfo) (void);
484 # else
485 static VALUE *dll_ruby_errinfo;
486 # endif
487 static void (*dll_ruby_init) (void); 441 static void (*dll_ruby_init) (void);
488 static void (*dll_ruby_init_loadpath) (void); 442 static void (*dll_ruby_init_loadpath) (void);
489 # ifdef MSWIN 443 # ifdef MSWIN
490 # if RUBY_VERSION >= 19
491 static void (*dll_ruby_sysinit) (int*, char***); 444 static void (*dll_ruby_sysinit) (int*, char***);
492 # else
493 static void (*dll_NtInitialize) (int*, char***);
494 # endif
495 # if RUBY_VERSION >= 18
496 static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...); 445 static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
497 # endif
498 # endif 446 # endif
499 # if RUBY_VERSION >= 31 447 # if RUBY_VERSION >= 31
500 # ifdef _MSC_VER 448 # ifdef _MSC_VER
501 static void (*dll_rb_unexpected_type) (VALUE, int); 449 static void (*dll_rb_unexpected_type) (VALUE, int);
502 # else 450 # else
503 NORETURN(static void (*dll_rb_unexpected_type) (VALUE, int)); 451 NORETURN(static void (*dll_rb_unexpected_type) (VALUE, int));
504 # endif 452 # endif
505 # endif 453 # endif
506 # if RUBY_VERSION >= 18
507 static char * (*dll_rb_string_value_ptr) (volatile VALUE*); 454 static char * (*dll_rb_string_value_ptr) (volatile VALUE*);
508 static VALUE (*dll_rb_float_new) (double); 455 static VALUE (*dll_rb_float_new) (double);
509 static VALUE (*dll_rb_ary_new) (void); 456 static VALUE (*dll_rb_ary_new) (void);
510 static VALUE (*dll_rb_ary_new4) (long n, const VALUE *elts); 457 static VALUE (*dll_rb_ary_new4) (long n, const VALUE *elts);
511 static VALUE (*dll_rb_ary_push) (VALUE, VALUE); 458 static VALUE (*dll_rb_ary_push) (VALUE, VALUE);
512 # if RUBY_VERSION >= 26 459 # if RUBY_VERSION >= 26
513 static void (*dll_rb_ary_detransient) (VALUE); 460 static void (*dll_rb_ary_detransient) (VALUE);
514 # endif 461 # endif
515 # if (RUBY_VERSION >= 19) || defined(RUBY_INIT_STACK) 462 # ifdef __ia64
516 # ifdef __ia64
517 static void * (*dll_rb_ia64_bsp) (void); 463 static void * (*dll_rb_ia64_bsp) (void);
518 static void (*dll_ruby_init_stack)(VALUE*, void*); 464 static void (*dll_ruby_init_stack)(VALUE*, void*);
519 # else 465 # else
520 static void (*dll_ruby_init_stack)(VALUE*); 466 static void (*dll_ruby_init_stack)(VALUE*);
521 # endif 467 # endif
522 # endif
523 # endif
524 # if RUBY_VERSION >= 19
525 static VALUE (*dll_rb_int2big)(SIGNED_VALUE); 468 static VALUE (*dll_rb_int2big)(SIGNED_VALUE);
526 # endif 469
527
528 # if RUBY_VERSION >= 19
529 static void (*dll_ruby_script) (const char*); 470 static void (*dll_ruby_script) (const char*);
530 static int (*dll_rb_enc_find_index) (const char*); 471 static int (*dll_rb_enc_find_index) (const char*);
531 static rb_encoding* (*dll_rb_enc_find) (const char*); 472 static rb_encoding* (*dll_rb_enc_find) (const char*);
532 static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*); 473 static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*);
533 static VALUE (*dll_rb_sprintf) (const char*, ...); 474 static VALUE (*dll_rb_sprintf) (const char*, ...);
534 static VALUE (*dll_rb_require) (const char*); 475 static VALUE (*dll_rb_require) (const char*);
535 static void* (*dll_ruby_options)(int, char**); 476 static void* (*dll_ruby_options)(int, char**);
536 # endif
537 477
538 # if defined(USE_RGENGC) && USE_RGENGC 478 # if defined(USE_RGENGC) && USE_RGENGC
539 # if RUBY_VERSION == 21 479 # if RUBY_VERSION == 21
540 static void (*dll_rb_gc_writebarrier_unprotect_promoted)(VALUE); 480 static void (*dll_rb_gc_writebarrier_unprotect_promoted)(VALUE);
541 # else 481 # else
555 void rb_ary_detransient_stub(VALUE x); 495 void rb_ary_detransient_stub(VALUE x);
556 # endif 496 # endif
557 497
558 // Do not generate a prototype here, VALUE isn't always defined. 498 // Do not generate a prototype here, VALUE isn't always defined.
559 # ifndef PROTO 499 # ifndef PROTO
560 # if RUBY_VERSION >= 19 500 # if RUBY_VERSION >= 22
561 # if RUBY_VERSION >= 22
562 long 501 long
563 rb_num2long_stub(VALUE x) 502 rb_num2long_stub(VALUE x)
564 # else 503 # else
565 SIGNED_VALUE 504 SIGNED_VALUE
566 rb_num2long_stub(VALUE x) 505 rb_num2long_stub(VALUE x)
567 # endif 506 # endif
568 { 507 {
569 return dll_rb_num2long(x); 508 return dll_rb_num2long(x);
570 } 509 }
571 # if RUBY_VERSION >= 26 510 # if RUBY_VERSION >= 26
572 VALUE 511 VALUE
573 rb_int2big_stub(intptr_t x) 512 rb_int2big_stub(intptr_t x)
513 # else
514 VALUE
515 rb_int2big_stub(SIGNED_VALUE x)
516 # endif
517 {
518 return dll_rb_int2big(x);
519 }
520 # if RUBY_VERSION >= 30 || VIM_SIZEOF_INT < VIM_SIZEOF_LONG
521 long
522 rb_fix2int_stub(VALUE x)
523 {
524 return dll_rb_fix2int(x);
525 }
526 long
527 rb_num2int_stub(VALUE x)
528 {
529 return dll_rb_num2int(x);
530 }
531 # endif
532 # if RUBY_VERSION >= 20
533 VALUE
534 rb_float_new_in_heap(double d)
535 {
536 return dll_rb_float_new(d);
537 }
538 # if RUBY_VERSION >= 22
539 unsigned long
540 rb_num2ulong(VALUE x)
574 # else 541 # else
575 VALUE 542 VALUE
576 rb_int2big_stub(SIGNED_VALUE x) 543 rb_num2ulong(VALUE x)
577 # endif 544 # endif
578 { 545 {
579 return dll_rb_int2big(x);
580 }
581 # if RUBY_VERSION >= 30 || VIM_SIZEOF_INT < VIM_SIZEOF_LONG
582 long
583 rb_fix2int_stub(VALUE x)
584 {
585 return dll_rb_fix2int(x);
586 }
587 long
588 rb_num2int_stub(VALUE x)
589 {
590 return dll_rb_num2int(x);
591 }
592 # endif
593 # if RUBY_VERSION >= 20
594 VALUE
595 rb_float_new_in_heap(double d)
596 {
597 return dll_rb_float_new(d);
598 }
599 # if RUBY_VERSION >= 22
600 unsigned long
601 rb_num2ulong(VALUE x)
602 # else
603 VALUE
604 rb_num2ulong(VALUE x)
605 # endif
606 {
607 return (long)RSHIFT((SIGNED_VALUE)(x),1); 546 return (long)RSHIFT((SIGNED_VALUE)(x),1);
608 } 547 }
609 # endif
610 # endif 548 # endif
611 # if defined(USE_RGENGC) && USE_RGENGC 549 # if defined(USE_RGENGC) && USE_RGENGC
612 # if RUBY_VERSION == 21 550 # if RUBY_VERSION == 21
613 void 551 void
614 rb_gc_writebarrier_unprotect_promoted_stub(VALUE obj) 552 rb_gc_writebarrier_unprotect_promoted_stub(VALUE obj)
746 {"rb_num2ulong", (RUBY_PROC*)&dll_rb_num2ulong}, 684 {"rb_num2ulong", (RUBY_PROC*)&dll_rb_num2ulong},
747 {"rb_obj_alloc", (RUBY_PROC*)&dll_rb_obj_alloc}, 685 {"rb_obj_alloc", (RUBY_PROC*)&dll_rb_obj_alloc},
748 {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string}, 686 {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string},
749 {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id}, 687 {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id},
750 {"rb_raise", (RUBY_PROC*)&dll_rb_raise}, 688 {"rb_raise", (RUBY_PROC*)&dll_rb_raise},
751 # if RUBY_VERSION >= 18
752 {"rb_string_value", (RUBY_PROC*)&dll_rb_string_value}, 689 {"rb_string_value", (RUBY_PROC*)&dll_rb_string_value},
753 # else
754 {"rb_str2cstr", (RUBY_PROC*)&dll_rb_str2cstr},
755 # endif
756 {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat}, 690 {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat},
757 {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat}, 691 {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat},
758 {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new}, 692 {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new},
759 # ifdef need_rb_str_new_cstr 693 # ifdef need_rb_str_new_cstr
760 {"rb_str_new_cstr", (RUBY_PROC*)&dll_rb_str_new_cstr}, 694 {"rb_str_new_cstr", (RUBY_PROC*)&dll_rb_str_new_cstr},
761 # else 695 # else
762 {"rb_str_new2", (RUBY_PROC*)&dll_rb_str_new2}, 696 {"rb_str_new2", (RUBY_PROC*)&dll_rb_str_new2},
763 # endif 697 # endif
764 # if RUBY_VERSION >= 19
765 {"rb_errinfo", (RUBY_PROC*)&dll_rb_errinfo}, 698 {"rb_errinfo", (RUBY_PROC*)&dll_rb_errinfo},
766 # else
767 {"ruby_errinfo", (RUBY_PROC*)&dll_ruby_errinfo},
768 # endif
769 {"ruby_init", (RUBY_PROC*)&dll_ruby_init}, 699 {"ruby_init", (RUBY_PROC*)&dll_ruby_init},
770 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath}, 700 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath},
771 # ifdef MSWIN 701 # ifdef MSWIN
772 # if RUBY_VERSION >= 19
773 {"ruby_sysinit", (RUBY_PROC*)&dll_ruby_sysinit}, 702 {"ruby_sysinit", (RUBY_PROC*)&dll_ruby_sysinit},
774 # else
775 {"NtInitialize", (RUBY_PROC*)&dll_NtInitialize},
776 # endif
777 # if RUBY_VERSION >= 18
778 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf}, 703 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf},
779 # endif
780 # endif 704 # endif
781 # if RUBY_VERSION >= 31 705 # if RUBY_VERSION >= 31
782 {"rb_unexpected_type", (RUBY_PROC*)&dll_rb_unexpected_type}, 706 {"rb_unexpected_type", (RUBY_PROC*)&dll_rb_unexpected_type},
783 # endif 707 # endif
784 # if RUBY_VERSION >= 18
785 {"rb_string_value_ptr", (RUBY_PROC*)&dll_rb_string_value_ptr}, 708 {"rb_string_value_ptr", (RUBY_PROC*)&dll_rb_string_value_ptr},
786 # if RUBY_VERSION <= 19 709 # if RUBY_VERSION >= 20
710 {"rb_float_new_in_heap", (RUBY_PROC*)&dll_rb_float_new},
711 # else
787 {"rb_float_new", (RUBY_PROC*)&dll_rb_float_new}, 712 {"rb_float_new", (RUBY_PROC*)&dll_rb_float_new},
788 # else 713 # endif
789 {"rb_float_new_in_heap", (RUBY_PROC*)&dll_rb_float_new},
790 # endif
791 {"rb_ary_new", (RUBY_PROC*)&dll_rb_ary_new}, 714 {"rb_ary_new", (RUBY_PROC*)&dll_rb_ary_new},
792 # ifdef RB_ARY_NEW4_MACRO 715 # ifdef RB_ARY_NEW4_MACRO
793 {"rb_ary_new_from_values", (RUBY_PROC*)&dll_rb_ary_new4}, 716 {"rb_ary_new_from_values", (RUBY_PROC*)&dll_rb_ary_new4},
794 # else 717 # else
795 {"rb_ary_new4", (RUBY_PROC*)&dll_rb_ary_new4}, 718 {"rb_ary_new4", (RUBY_PROC*)&dll_rb_ary_new4},
796 # endif 719 # endif
797 {"rb_ary_push", (RUBY_PROC*)&dll_rb_ary_push}, 720 {"rb_ary_push", (RUBY_PROC*)&dll_rb_ary_push},
798 # if RUBY_VERSION >= 26 721 # if RUBY_VERSION >= 26
799 {"rb_ary_detransient", (RUBY_PROC*)&dll_rb_ary_detransient}, 722 {"rb_ary_detransient", (RUBY_PROC*)&dll_rb_ary_detransient},
800 # endif 723 # endif
801 # endif
802 # if RUBY_VERSION >= 19
803 {"rb_int2big", (RUBY_PROC*)&dll_rb_int2big}, 724 {"rb_int2big", (RUBY_PROC*)&dll_rb_int2big},
804 {"ruby_script", (RUBY_PROC*)&dll_ruby_script}, 725 {"ruby_script", (RUBY_PROC*)&dll_ruby_script},
805 {"rb_enc_find_index", (RUBY_PROC*)&dll_rb_enc_find_index}, 726 {"rb_enc_find_index", (RUBY_PROC*)&dll_rb_enc_find_index},
806 {"rb_enc_find", (RUBY_PROC*)&dll_rb_enc_find}, 727 {"rb_enc_find", (RUBY_PROC*)&dll_rb_enc_find},
807 {"rb_enc_str_new", (RUBY_PROC*)&dll_rb_enc_str_new}, 728 {"rb_enc_str_new", (RUBY_PROC*)&dll_rb_enc_str_new},
808 {"rb_sprintf", (RUBY_PROC*)&dll_rb_sprintf}, 729 {"rb_sprintf", (RUBY_PROC*)&dll_rb_sprintf},
809 {"rb_require", (RUBY_PROC*)&dll_rb_require}, 730 {"rb_require", (RUBY_PROC*)&dll_rb_require},
810 {"ruby_options", (RUBY_PROC*)&dll_ruby_options}, 731 {"ruby_options", (RUBY_PROC*)&dll_ruby_options},
811 # endif 732 # ifdef __ia64
812 # if (RUBY_VERSION >= 19) || defined(RUBY_INIT_STACK)
813 # ifdef __ia64
814 {"rb_ia64_bsp", (RUBY_PROC*)&dll_rb_ia64_bsp}, 733 {"rb_ia64_bsp", (RUBY_PROC*)&dll_rb_ia64_bsp},
815 # endif 734 # endif
816 {"ruby_init_stack", (RUBY_PROC*)&dll_ruby_init_stack}, 735 {"ruby_init_stack", (RUBY_PROC*)&dll_ruby_init_stack},
817 # endif
818 # if defined(USE_RGENGC) && USE_RGENGC 736 # if defined(USE_RGENGC) && USE_RGENGC
819 # if RUBY_VERSION == 21 737 # if RUBY_VERSION == 21
820 {"rb_gc_writebarrier_unprotect_promoted", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect_promoted}, 738 {"rb_gc_writebarrier_unprotect_promoted", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect_promoted},
821 # else 739 # else
822 {"rb_gc_writebarrier_unprotect", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect}, 740 {"rb_gc_writebarrier_unprotect", (RUBY_PROC*)&dll_rb_gc_writebarrier_unprotect},
904 * VIM encoding option. 822 * VIM encoding option.
905 */ 823 */
906 static VALUE 824 static VALUE
907 vim_str2rb_enc_str(const char *s) 825 vim_str2rb_enc_str(const char *s)
908 { 826 {
909 #if RUBY_VERSION >= 19
910 long lval; 827 long lval;
911 char_u *sval; 828 char_u *sval;
912 rb_encoding *enc; 829 rb_encoding *enc;
913 830
914 if (get_option_value((char_u *)"enc", &lval, &sval, NULL, 0) == gov_string) 831 if (get_option_value((char_u *)"enc", &lval, &sval, NULL, 0) == gov_string)
916 enc = rb_enc_find((char *)sval); 833 enc = rb_enc_find((char *)sval);
917 vim_free(sval); 834 vim_free(sval);
918 if (enc) 835 if (enc)
919 return rb_enc_str_new(s, (long)strlen(s), enc); 836 return rb_enc_str_new(s, (long)strlen(s), enc);
920 } 837 }
921 #endif
922 return rb_str_new2(s); 838 return rb_str_new2(s);
923 } 839 }
924 840
925 static VALUE 841 static VALUE
926 eval_enc_string_protect(const char *str, int *state) 842 eval_enc_string_protect(const char *str, int *state)
927 { 843 {
928 #if RUBY_VERSION >= 19
929 long lval; 844 long lval;
930 char_u *sval; 845 char_u *sval;
931 rb_encoding *enc; 846 rb_encoding *enc;
932 VALUE v; 847 VALUE v;
933 848
939 { 854 {
940 v = rb_sprintf("#-*- coding:%s -*-\n%s", rb_enc_name(enc), str); 855 v = rb_sprintf("#-*- coding:%s -*-\n%s", rb_enc_name(enc), str);
941 return rb_eval_string_protect(StringValuePtr(v), state); 856 return rb_eval_string_protect(StringValuePtr(v), state);
942 } 857 }
943 } 858 }
944 #endif
945 return rb_eval_string_protect(str, state); 859 return rb_eval_string_protect(str, state);
946 } 860 }
947 861
948 void 862 void
949 ex_rubydo(exarg_T *eap) 863 ex_rubydo(exarg_T *eap)
1038 { 952 {
1039 if (!ruby_initialized) 953 if (!ruby_initialized)
1040 { 954 {
1041 #ifdef DYNAMIC_RUBY 955 #ifdef DYNAMIC_RUBY
1042 if (ruby_enabled(TRUE)) 956 if (ruby_enabled(TRUE))
957 #endif
1043 { 958 {
1044 #endif
1045 #ifdef MSWIN 959 #ifdef MSWIN
1046 // suggested by Ariya Mizutani 960 // suggested by Ariya Mizutani
1047 int argc = 1; 961 int argc = 1;
1048 char *argv[] = {"gvim.exe"}; 962 char *argv[] = {"gvim.exe"};
1049 char **argvp = argv; 963 char **argvp = argv;
1050 # if RUBY_VERSION >= 19
1051 ruby_sysinit(&argc, &argvp); 964 ruby_sysinit(&argc, &argvp);
1052 # else
1053 NtInitialize(&argc, &argvp);
1054 # endif
1055 #endif 965 #endif
1056 { 966 {
1057 #if (RUBY_VERSION >= 19) || defined(RUBY_INIT_STACK)
1058 ruby_init_stack(ruby_stack_start); 967 ruby_init_stack(ruby_stack_start);
1059 #endif
1060 ruby_init(); 968 ruby_init();
1061 } 969 }
1062 #if RUBY_VERSION >= 19
1063 { 970 {
1064 int dummy_argc = 2; 971 int dummy_argc = 2;
1065 char *dummy_argv[] = {"vim-ruby", "-e_=0"}; 972 char *dummy_argv[] = {"vim-ruby", "-e_=0"};
1066 ruby_options(dummy_argc, dummy_argv); 973 ruby_options(dummy_argc, dummy_argv);
1067 } 974 }
1068 ruby_script("vim-ruby"); 975 ruby_script("vim-ruby");
1069 #else
1070 ruby_init_loadpath();
1071 #endif
1072 ruby_io_init(); 976 ruby_io_init();
1073 ruby_vim_init(); 977 ruby_vim_init();
1074 ruby_initialized = 1; 978 ruby_initialized = 1;
979 }
1075 #ifdef DYNAMIC_RUBY 980 #ifdef DYNAMIC_RUBY
1076 }
1077 else 981 else
1078 { 982 {
1079 emsg(_(e_sorry_this_command_is_disabled_the_ruby_library_could_not_be_loaded)); 983 emsg(_(e_sorry_this_command_is_disabled_the_ruby_library_could_not_be_loaded));
1080 return 0; 984 return 0;
1081 } 985 }
1085 } 989 }
1086 990
1087 static void 991 static void
1088 error_print(int state) 992 error_print(int state)
1089 { 993 {
1090 #if !defined(DYNAMIC_RUBY) && (RUBY_VERSION <= 18)
1091 RUBYEXTERN VALUE ruby_errinfo;
1092 #endif
1093 VALUE error; 994 VALUE error;
1094 VALUE eclass; 995 VALUE eclass;
1095 VALUE einfo; 996 VALUE einfo;
1096 VALUE bt; 997 VALUE bt;
1097 int attr; 998 int attr;
1125 case TAG_RETRY: 1026 case TAG_RETRY:
1126 emsg(_(e_retry_outside_of_rescue_clause)); 1027 emsg(_(e_retry_outside_of_rescue_clause));
1127 break; 1028 break;
1128 case TAG_RAISE: 1029 case TAG_RAISE:
1129 case TAG_FATAL: 1030 case TAG_FATAL:
1130 #if RUBY_VERSION >= 19
1131 error = rb_errinfo(); 1031 error = rb_errinfo();
1132 #else
1133 error = ruby_errinfo;
1134 #endif
1135 eclass = CLASS_OF(error); 1032 eclass = CLASS_OF(error);
1136 einfo = rb_obj_as_string(error); 1033 einfo = rb_obj_as_string(error);
1137 if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) 1034 if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0)
1138 { 1035 {
1139 emsg(_(e_unhandled_exception)); 1036 emsg(_(e_unhandled_exception));