Mercurial > vim
comparison src/if_ruby.c @ 14437:ceb9b6bf0f4a v8.1.0232
patch 8.1.0232: Ruby error does not include backtrace
commit https://github.com/vim/vim/commit/f711cb2f12458d32e082c0e3d4103e2b072947c3
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 1 18:42:13 2018 +0200
patch 8.1.0232: Ruby error does not include backtrace
Problem: Ruby error does not include backtrace.
Solution: Add an error backtrace. (Masataka Pocke Kuwabara, closes https://github.com/vim/vim/issues/3267)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 01 Aug 2018 18:45:05 +0200 |
parents | 504091aca571 |
children | dda317774511 |
comparison
equal
deleted
inserted
replaced
14436:c5b4768f5224 | 14437:ceb9b6bf0f4a |
---|---|
89 #endif | 89 #endif |
90 | 90 |
91 #if (defined(RUBY_VERSION) && RUBY_VERSION >= 20) \ | 91 #if (defined(RUBY_VERSION) && RUBY_VERSION >= 20) \ |
92 || (defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20) | 92 || (defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20) |
93 # define RUBY20_OR_LATER 1 | 93 # define RUBY20_OR_LATER 1 |
94 #endif | |
95 | |
96 #if (defined(RUBY_VERSION) && RUBY_VERSION >= 21) \ | |
97 || (defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 21) | |
98 # define RUBY21_OR_LATER 1 | |
94 #endif | 99 #endif |
95 | 100 |
96 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 | 101 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 |
97 /* Ruby 1.9 defines a number of static functions which use rb_num2long and | 102 /* Ruby 1.9 defines a number of static functions which use rb_num2long and |
98 * rb_int2big */ | 103 * rb_int2big */ |
236 # define rb_eArgError (*dll_rb_eArgError) | 241 # define rb_eArgError (*dll_rb_eArgError) |
237 # define rb_eIndexError (*dll_rb_eIndexError) | 242 # define rb_eIndexError (*dll_rb_eIndexError) |
238 # define rb_eRuntimeError (*dll_rb_eRuntimeError) | 243 # define rb_eRuntimeError (*dll_rb_eRuntimeError) |
239 # define rb_eStandardError (*dll_rb_eStandardError) | 244 # define rb_eStandardError (*dll_rb_eStandardError) |
240 # define rb_eval_string_protect dll_rb_eval_string_protect | 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 # define rb_global_variable dll_rb_global_variable | 251 # define rb_global_variable dll_rb_global_variable |
242 # define rb_hash_aset dll_rb_hash_aset | 252 # define rb_hash_aset dll_rb_hash_aset |
243 # define rb_hash_new dll_rb_hash_new | 253 # define rb_hash_new dll_rb_hash_new |
244 # define rb_inspect dll_rb_inspect | 254 # define rb_inspect dll_rb_inspect |
245 # define rb_int2inum dll_rb_int2inum | 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 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ | 261 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ |
247 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 18 | 262 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 18 |
248 # define rb_fix2int dll_rb_fix2int | 263 # define rb_fix2int dll_rb_fix2int |
249 # define rb_num2int dll_rb_num2int | 264 # define rb_num2int dll_rb_num2int |
250 # endif | 265 # endif |
365 static VALUE *dll_rb_eArgError; | 380 static VALUE *dll_rb_eArgError; |
366 static VALUE *dll_rb_eIndexError; | 381 static VALUE *dll_rb_eIndexError; |
367 static VALUE *dll_rb_eRuntimeError; | 382 static VALUE *dll_rb_eRuntimeError; |
368 static VALUE *dll_rb_eStandardError; | 383 static VALUE *dll_rb_eStandardError; |
369 static VALUE (*dll_rb_eval_string_protect) (const char*, int*); | 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 static void (*dll_rb_global_variable) (VALUE*); | 390 static void (*dll_rb_global_variable) (VALUE*); |
371 static VALUE (*dll_rb_hash_aset) (VALUE, VALUE, VALUE); | 391 static VALUE (*dll_rb_hash_aset) (VALUE, VALUE, VALUE); |
372 static VALUE (*dll_rb_hash_new) (void); | 392 static VALUE (*dll_rb_hash_new) (void); |
373 static VALUE (*dll_rb_inspect) (VALUE); | 393 static VALUE (*dll_rb_inspect) (VALUE); |
374 static VALUE (*dll_rb_int2inum) (long); | 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 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ | 400 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ |
376 static long (*dll_rb_fix2int) (VALUE); | 401 static long (*dll_rb_fix2int) (VALUE); |
377 static long (*dll_rb_num2int) (VALUE); | 402 static long (*dll_rb_num2int) (VALUE); |
378 static unsigned long (*dll_rb_num2uint) (VALUE); | 403 static unsigned long (*dll_rb_num2uint) (VALUE); |
379 # endif | 404 # endif |
559 {"rb_eArgError", (RUBY_PROC*)&dll_rb_eArgError}, | 584 {"rb_eArgError", (RUBY_PROC*)&dll_rb_eArgError}, |
560 {"rb_eIndexError", (RUBY_PROC*)&dll_rb_eIndexError}, | 585 {"rb_eIndexError", (RUBY_PROC*)&dll_rb_eIndexError}, |
561 {"rb_eRuntimeError", (RUBY_PROC*)&dll_rb_eRuntimeError}, | 586 {"rb_eRuntimeError", (RUBY_PROC*)&dll_rb_eRuntimeError}, |
562 {"rb_eStandardError", (RUBY_PROC*)&dll_rb_eStandardError}, | 587 {"rb_eStandardError", (RUBY_PROC*)&dll_rb_eStandardError}, |
563 {"rb_eval_string_protect", (RUBY_PROC*)&dll_rb_eval_string_protect}, | 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 {"rb_global_variable", (RUBY_PROC*)&dll_rb_global_variable}, | 594 {"rb_global_variable", (RUBY_PROC*)&dll_rb_global_variable}, |
565 {"rb_hash_aset", (RUBY_PROC*)&dll_rb_hash_aset}, | 595 {"rb_hash_aset", (RUBY_PROC*)&dll_rb_hash_aset}, |
566 {"rb_hash_new", (RUBY_PROC*)&dll_rb_hash_new}, | 596 {"rb_hash_new", (RUBY_PROC*)&dll_rb_hash_new}, |
567 {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, | 597 {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, |
568 {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum}, | 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 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ | 604 # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ |
570 {"rb_fix2int", (RUBY_PROC*)&dll_rb_fix2int}, | 605 {"rb_fix2int", (RUBY_PROC*)&dll_rb_fix2int}, |
571 {"rb_num2int", (RUBY_PROC*)&dll_rb_num2int}, | 606 {"rb_num2int", (RUBY_PROC*)&dll_rb_num2int}, |
572 {"rb_num2uint", (RUBY_PROC*)&dll_rb_num2uint}, | 607 {"rb_num2uint", (RUBY_PROC*)&dll_rb_num2uint}, |
573 # endif | 608 # endif |
924 #if !(defined(RUBY_VERSION) && RUBY_VERSION >= 19) \ | 959 #if !(defined(RUBY_VERSION) && RUBY_VERSION >= 19) \ |
925 && !(defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19) | 960 && !(defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19) |
926 RUBYEXTERN VALUE ruby_errinfo; | 961 RUBYEXTERN VALUE ruby_errinfo; |
927 #endif | 962 #endif |
928 #endif | 963 #endif |
964 VALUE error; | |
929 VALUE eclass; | 965 VALUE eclass; |
930 VALUE einfo; | 966 VALUE einfo; |
967 VALUE bt; | |
968 int attr; | |
931 char buff[BUFSIZ]; | 969 char buff[BUFSIZ]; |
970 long i; | |
932 | 971 |
933 #define TAG_RETURN 0x1 | 972 #define TAG_RETURN 0x1 |
934 #define TAG_BREAK 0x2 | 973 #define TAG_BREAK 0x2 |
935 #define TAG_NEXT 0x3 | 974 #define TAG_NEXT 0x3 |
936 #define TAG_RETRY 0x4 | 975 #define TAG_RETRY 0x4 |
958 EMSG(_("E271: retry outside of rescue clause")); | 997 EMSG(_("E271: retry outside of rescue clause")); |
959 break; | 998 break; |
960 case TAG_RAISE: | 999 case TAG_RAISE: |
961 case TAG_FATAL: | 1000 case TAG_FATAL: |
962 #ifdef RUBY19_OR_LATER | 1001 #ifdef RUBY19_OR_LATER |
963 eclass = CLASS_OF(rb_errinfo()); | 1002 error = rb_errinfo(); |
964 einfo = rb_obj_as_string(rb_errinfo()); | |
965 #else | 1003 #else |
966 eclass = CLASS_OF(ruby_errinfo); | 1004 error = ruby_errinfo; |
967 einfo = rb_obj_as_string(ruby_errinfo); | 1005 #endif |
968 #endif | 1006 eclass = CLASS_OF(error); |
1007 einfo = rb_obj_as_string(error); | |
969 if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) | 1008 if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) |
970 { | 1009 { |
971 EMSG(_("E272: unhandled exception")); | 1010 EMSG(_("E272: unhandled exception")); |
972 } | 1011 } |
973 else | 1012 else |
980 RSTRING_PTR(epath), RSTRING_PTR(einfo)); | 1019 RSTRING_PTR(epath), RSTRING_PTR(einfo)); |
981 p = strchr(buff, '\n'); | 1020 p = strchr(buff, '\n'); |
982 if (p) *p = '\0'; | 1021 if (p) *p = '\0'; |
983 EMSG(buff); | 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 break; | 1035 break; |
986 default: | 1036 default: |
987 vim_snprintf(buff, BUFSIZ, _("E273: unknown longjmp status %d"), state); | 1037 vim_snprintf(buff, BUFSIZ, _("E273: unknown longjmp status %d"), state); |
988 EMSG(buff); | 1038 EMSG(buff); |
989 break; | 1039 break; |