Avoiding a segfault when trying to run Ruby from a non-Ruby thread

This commit is contained in:
Matthias Koefferlein 2025-05-27 00:48:10 +02:00
parent bfe49c22e3
commit 010fa2d5ba
1 changed files with 4 additions and 0 deletions

View File

@ -450,6 +450,10 @@ VALUE rba_funcall2_checked (VALUE obj, ID id, int argc, VALUE *args)
// HINT: the ugly (VALUE) cast is required since there is only one form of rb_protect
rb_protect_init (); // see above
if (! ruby_native_thread_p ()) {
throw tl::Exception (tl::to_string (tr ("Can't execute Ruby callbacks from non-Ruby threads")));
}
RUBY_BEGIN_EXEC
ret = rb_protect (&rb_funcall2_wrap, (VALUE) &p, &error);
RUBY_END_EXEC