93
93
# define RUBY20_OR_LATER 1
94
94
#endif
95
95
96
+ #if (defined(RUBY_VERSION ) && RUBY_VERSION >= 21 ) \
97
+ || (defined(DYNAMIC_RUBY_VER ) && DYNAMIC_RUBY_VER >= 21 )
98
+ # define RUBY21_OR_LATER 1
99
+ #endif
100
+
96
101
#if defined(DYNAMIC_RUBY_VER ) && DYNAMIC_RUBY_VER >= 19
97
102
/* Ruby 1.9 defines a number of static functions which use rb_num2long and
98
103
* rb_int2big */
@@ -238,11 +243,21 @@ static void ruby_vim_init(void);
238
243
# define rb_eRuntimeError (*dll_rb_eRuntimeError)
239
244
# define rb_eStandardError (*dll_rb_eStandardError)
240
245
# define rb_eval_string_protect dll_rb_eval_string_protect
246
+ # ifdef RUBY21_OR_LATER
247
+ # define rb_funcallv dll_rb_funcallv
248
+ # else
249
+ # define rb_funcall2 dll_rb_funcall2
250
+ # endif
241
251
# define rb_global_variable dll_rb_global_variable
242
252
# define rb_hash_aset dll_rb_hash_aset
243
253
# define rb_hash_new dll_rb_hash_new
244
254
# define rb_inspect dll_rb_inspect
245
255
# define rb_int2inum dll_rb_int2inum
256
+ # ifdef RUBY19_OR_LATER
257
+ # define rb_intern2 dll_rb_intern2
258
+ # else
259
+ # define rb_intern dll_rb_intern
260
+ # endif
246
261
# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */
247
262
# if defined(DYNAMIC_RUBY_VER ) && DYNAMIC_RUBY_VER <= 18
248
263
# define rb_fix2int dll_rb_fix2int
@@ -367,11 +382,21 @@ static VALUE *dll_rb_eIndexError;
367
382
static VALUE * dll_rb_eRuntimeError ;
368
383
static VALUE * dll_rb_eStandardError ;
369
384
static VALUE (* dll_rb_eval_string_protect ) (const char * , int * );
385
+ # ifdef RUBY21_OR_LATER
386
+ static VALUE (* dll_rb_funcallv ) (VALUE , ID , int , const VALUE * );
387
+ # else
388
+ static VALUE (* dll_rb_funcall2 ) (VALUE , ID , int , const VALUE * );
389
+ # endif
370
390
static void (* dll_rb_global_variable ) (VALUE * );
371
391
static VALUE (* dll_rb_hash_aset ) (VALUE , VALUE , VALUE );
372
392
static VALUE (* dll_rb_hash_new ) (void );
373
393
static VALUE (* dll_rb_inspect ) (VALUE );
374
394
static VALUE (* dll_rb_int2inum ) (long );
395
+ # ifdef RUBY19_OR_LATER
396
+ static ID (* dll_rb_intern2 ) (const char * , long );
397
+ # else
398
+ static ID (* dll_rb_intern ) (const char * );
399
+ # endif
375
400
# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */
376
401
static long (* dll_rb_fix2int ) (VALUE );
377
402
static long (* dll_rb_num2int ) (VALUE );
@@ -561,11 +586,21 @@ static struct
561
586
{"rb_eRuntimeError" , (RUBY_PROC * )& dll_rb_eRuntimeError },
562
587
{"rb_eStandardError" , (RUBY_PROC * )& dll_rb_eStandardError },
563
588
{"rb_eval_string_protect" , (RUBY_PROC * )& dll_rb_eval_string_protect },
589
+ # ifdef RUBY21_OR_LATER
590
+ {"rb_funcallv" , (RUBY_PROC * )& dll_rb_funcallv },
591
+ # else
592
+ {"rb_funcall2" , (RUBY_PROC * )& dll_rb_funcall2 },
593
+ # endif
564
594
{"rb_global_variable" , (RUBY_PROC * )& dll_rb_global_variable },
565
595
{"rb_hash_aset" , (RUBY_PROC * )& dll_rb_hash_aset },
566
596
{"rb_hash_new" , (RUBY_PROC * )& dll_rb_hash_new },
567
597
{"rb_inspect" , (RUBY_PROC * )& dll_rb_inspect },
568
598
{"rb_int2inum" , (RUBY_PROC * )& dll_rb_int2inum },
599
+ # ifdef RUBY19_OR_LATER
600
+ {"rb_intern2" , (RUBY_PROC * )& dll_rb_intern2 },
601
+ # else
602
+ {"rb_intern" , (RUBY_PROC * )& dll_rb_intern },
603
+ # endif
569
604
# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */
570
605
{"rb_fix2int" , (RUBY_PROC * )& dll_rb_fix2int },
571
606
{"rb_num2int" , (RUBY_PROC * )& dll_rb_num2int },
@@ -926,9 +961,13 @@ static void error_print(int state)
926
961
RUBYEXTERN VALUE ruby_errinfo ;
927
962
#endif
928
963
#endif
964
+ VALUE error ;
929
965
VALUE eclass ;
930
966
VALUE einfo ;
967
+ VALUE bt ;
968
+ int attr ;
931
969
char buff [BUFSIZ ];
970
+ long i ;
932
971
933
972
#define TAG_RETURN 0x1
934
973
#define TAG_BREAK 0x2
@@ -960,12 +999,12 @@ static void error_print(int state)
960
999
case TAG_RAISE :
961
1000
case TAG_FATAL :
962
1001
#ifdef RUBY19_OR_LATER
963
- eclass = CLASS_OF (rb_errinfo ());
964
- einfo = rb_obj_as_string (rb_errinfo ());
1002
+ error = rb_errinfo ();
965
1003
#else
966
- eclass = CLASS_OF (ruby_errinfo );
967
- einfo = rb_obj_as_string (ruby_errinfo );
1004
+ error = ruby_errinfo ;
968
1005
#endif
1006
+ eclass = CLASS_OF (error );
1007
+ einfo = rb_obj_as_string (error );
969
1008
if (eclass == rb_eRuntimeError && RSTRING_LEN (einfo ) == 0 )
970
1009
{
971
1010
EMSG (_ ("E272: unhandled exception" ));
@@ -982,6 +1021,17 @@ static void error_print(int state)
982
1021
if (p ) * p = '\0' ;
983
1022
EMSG (buff );
984
1023
}
1024
+
1025
+ attr = syn_name2attr ((char_u * )"Error" );
1026
+ # ifdef RUBY21_OR_LATER
1027
+ bt = rb_funcallv (error , rb_intern ("backtrace" ), 0 , 0 );
1028
+ for (i = 0 ; i < RARRAY_LEN (bt ); i ++ )
1029
+ msg_attr ((char_u * )RSTRING_PTR (RARRAY_AREF (bt , i )), attr );
1030
+ # else
1031
+ bt = rb_funcall2 (error , rb_intern ("backtrace" ), 0 , 0 );
1032
+ for (i = 0 ; i < RARRAY_LEN (bt ); i ++ )
1033
+ msg_attr ((char_u * )RSTRING_PTR (RARRAY_PTR (bt )[i ]), attr );
1034
+ # endif
985
1035
break ;
986
1036
default :
987
1037
vim_snprintf (buff , BUFSIZ , _ ("E273: unknown longjmp status %d" ), state );
0 commit comments