9393# define RUBY20_OR_LATER 1
9494#endif
9595
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+
96101#if defined(DYNAMIC_RUBY_VER ) && DYNAMIC_RUBY_VER >= 19
97102/* Ruby 1.9 defines a number of static functions which use rb_num2long and
98103 * rb_int2big */
@@ -238,11 +243,21 @@ static void ruby_vim_init(void);
238243# define rb_eRuntimeError (*dll_rb_eRuntimeError)
239244# define rb_eStandardError (*dll_rb_eStandardError)
240245# 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
241251# define rb_global_variable dll_rb_global_variable
242252# define rb_hash_aset dll_rb_hash_aset
243253# define rb_hash_new dll_rb_hash_new
244254# define rb_inspect dll_rb_inspect
245255# 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
246261# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */
247262# if defined(DYNAMIC_RUBY_VER ) && DYNAMIC_RUBY_VER <= 18
248263# define rb_fix2int dll_rb_fix2int
@@ -367,11 +382,21 @@ static VALUE *dll_rb_eIndexError;
367382static VALUE * dll_rb_eRuntimeError ;
368383static VALUE * dll_rb_eStandardError ;
369384static 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
370390static void (* dll_rb_global_variable ) (VALUE * );
371391static VALUE (* dll_rb_hash_aset ) (VALUE , VALUE , VALUE );
372392static VALUE (* dll_rb_hash_new ) (void );
373393static VALUE (* dll_rb_inspect ) (VALUE );
374394static 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
375400# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */
376401static long (* dll_rb_fix2int ) (VALUE );
377402static long (* dll_rb_num2int ) (VALUE );
@@ -561,11 +586,21 @@ static struct
561586 {"rb_eRuntimeError" , (RUBY_PROC * )& dll_rb_eRuntimeError },
562587 {"rb_eStandardError" , (RUBY_PROC * )& dll_rb_eStandardError },
563588 {"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
564594 {"rb_global_variable" , (RUBY_PROC * )& dll_rb_global_variable },
565595 {"rb_hash_aset" , (RUBY_PROC * )& dll_rb_hash_aset },
566596 {"rb_hash_new" , (RUBY_PROC * )& dll_rb_hash_new },
567597 {"rb_inspect" , (RUBY_PROC * )& dll_rb_inspect },
568598 {"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
569604# if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */
570605 {"rb_fix2int" , (RUBY_PROC * )& dll_rb_fix2int },
571606 {"rb_num2int" , (RUBY_PROC * )& dll_rb_num2int },
@@ -926,9 +961,13 @@ static void error_print(int state)
926961 RUBYEXTERN VALUE ruby_errinfo ;
927962#endif
928963#endif
964+ VALUE error ;
929965 VALUE eclass ;
930966 VALUE einfo ;
967+ VALUE bt ;
968+ int attr ;
931969 char buff [BUFSIZ ];
970+ long i ;
932971
933972#define TAG_RETURN 0x1
934973#define TAG_BREAK 0x2
@@ -960,12 +999,12 @@ static void error_print(int state)
960999 case TAG_RAISE :
9611000 case TAG_FATAL :
9621001#ifdef RUBY19_OR_LATER
963- eclass = CLASS_OF (rb_errinfo ());
964- einfo = rb_obj_as_string (rb_errinfo ());
1002+ error = rb_errinfo ();
9651003#else
966- eclass = CLASS_OF (ruby_errinfo );
967- einfo = rb_obj_as_string (ruby_errinfo );
1004+ error = ruby_errinfo ;
9681005#endif
1006+ eclass = CLASS_OF (error );
1007+ einfo = rb_obj_as_string (error );
9691008 if (eclass == rb_eRuntimeError && RSTRING_LEN (einfo ) == 0 )
9701009 {
9711010 EMSG (_ ("E272: unhandled exception" ));
@@ -982,6 +1021,17 @@ static void error_print(int state)
9821021 if (p ) * p = '\0' ;
9831022 EMSG (buff );
9841023 }
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
9851035 break ;
9861036 default :
9871037 vim_snprintf (buff , BUFSIZ , _ ("E273: unknown longjmp status %d" ), state );
0 commit comments