summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2019-10-10 17:49:31 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2019-10-10 17:49:31 +0900
commit2d393bf1255864706cabdd9375dd26e33bdf40b9 (patch)
tree734ee485400d902701c7060d56ad0f872f547a2e
parentf1ce4897f2eaf9a99c250e4707e3ab6f6bdacb74 (diff)
guard rb_fatal against non-GVL call
Suggested by ko1. rb_fatal requires GVL so just in case one lacks, print that information and let the process die. As commented, we cannot print the given messages on such situations.
-rw-r--r--error.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/error.c b/error.c
index 0c3633c581..fa750e2a3e 100644
--- a/error.c
+++ b/error.c
@@ -2668,6 +2668,14 @@ rb_fatal(const char *fmt, ...)
va_list args;
VALUE mesg;
+ if (! ruby_thread_has_gvl_p()) {
+ /* The thread has no GVL. Object allocation impossible (cant run GC),
+ * thus no message can be printed out. */
+ fprintf(stderr, "[FATAL] rb_fatal() outside of GVL\n");
+ rb_print_backtrace();
+ die();
+ }
+
va_start(args, fmt);
mesg = rb_vsprintf(fmt, args);
va_end(args);