1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

eval.c: copy special exceptions before raise

* eval.c (setup_exception): consider if the exception is frozen,
  but not one of special exception objects.

* gc.c (rb_memerror): copy minimum objects.

* thread.c (rb_threadptr_execute_interrupts): prepare special
  exception queued by another thread to be raised.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-04-17 02:31:35 +00:00
parent e97ac02f84
commit e601e77590
3 changed files with 27 additions and 49 deletions

30
eval.c
View file

@ -464,23 +464,6 @@ exc_setup_cause(VALUE exc, VALUE cause)
return exc; return exc;
} }
static inline int
sysstack_error_p(VALUE exc)
{
return exc == sysstack_error || (!SPECIAL_CONST_P(exc) && RBASIC_CLASS(exc) == rb_eSysStackError);
}
static inline int
special_exception_p(rb_thread_t *th, VALUE exc)
{
enum ruby_special_exceptions i;
const VALUE *exceptions = th->vm->special_exceptions;
for (i = 0; i < ruby_special_error_count; ++i) {
if (exceptions[i] == exc) return TRUE;
}
return FALSE;
}
static void static void
setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
{ {
@ -498,9 +481,6 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
mesg = rb_exc_new(rb_eRuntimeError, 0, 0); mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
nocause = 0; nocause = 0;
} }
else if (special_exception_p(th, mesg)) {
mesg = ruby_vm_special_exception_copy(mesg);
}
if (cause != Qundef) { if (cause != Qundef) {
exc_setup_cause(mesg, cause); exc_setup_cause(mesg, cause);
} }
@ -514,14 +494,6 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
file = rb_source_loc(&line); file = rb_source_loc(&line);
if (file && !NIL_P(mesg)) { if (file && !NIL_P(mesg)) {
VALUE at; VALUE at;
if (sysstack_error_p(mesg)) {
if (NIL_P(rb_attr_get(mesg, idBt))) {
at = rb_threadptr_backtrace_object(th);
rb_ivar_set(mesg, idBt, at);
rb_ivar_set(mesg, idBt_locations, at);
}
}
else {
int status; int status;
TH_PUSH_TAG(th); TH_PUSH_TAG(th);
@ -541,7 +513,6 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
} }
TH_POP_TAG(); TH_POP_TAG();
} }
}
if (!NIL_P(mesg)) { if (!NIL_P(mesg)) {
th->errinfo = mesg; th->errinfo = mesg;
@ -738,7 +709,6 @@ make_exception(int argc, const VALUE *argv, int isstr)
exc = argv[0]; exc = argv[0];
n = 1; n = 1;
exception_call: exception_call:
if (sysstack_error_p(exc)) return exc;
mesg = rb_check_funcall(exc, idException, n, argv+1); mesg = rb_check_funcall(exc, idException, n, argv+1);
if (mesg == Qundef) { if (mesg == Qundef) {
rb_raise(rb_eTypeError, "exception class/object expected"); rb_raise(rb_eTypeError, "exception class/object expected");

12
gc.c
View file

@ -7624,21 +7624,25 @@ rb_memerror(void)
{ {
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
rb_objspace_t *objspace = rb_objspace_of(th->vm); rb_objspace_t *objspace = rb_objspace_of(th->vm);
VALUE exc;
if (during_gc) gc_exit(objspace, "rb_memerror"); if (during_gc) gc_exit(objspace, "rb_memerror");
if (!nomem_error || exc = nomem_error;
if (!exc ||
rb_thread_raised_p(th, RAISED_NOMEMORY)) { rb_thread_raised_p(th, RAISED_NOMEMORY)) {
fprintf(stderr, "[FATAL] failed to allocate memory\n"); fprintf(stderr, "[FATAL] failed to allocate memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (rb_thread_raised_p(th, RAISED_NOMEMORY)) { if (rb_thread_raised_p(th, RAISED_NOMEMORY)) {
rb_thread_raised_clear(th); rb_thread_raised_clear(th);
GET_THREAD()->errinfo = nomem_error;
TH_JUMP_TAG(th, TAG_RAISE);
} }
else {
rb_thread_raised_set(th, RAISED_NOMEMORY); rb_thread_raised_set(th, RAISED_NOMEMORY);
rb_exc_raise(nomem_error); exc = ruby_vm_special_exception_copy(exc);
}
th->errinfo = exc;
TH_JUMP_TAG(th, TAG_RAISE);
} }
static void * static void *

View file

@ -2071,6 +2071,10 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
rb_threadptr_to_kill(th); rb_threadptr_to_kill(th);
} }
else { else {
if (err == th->vm->special_exceptions[ruby_error_stream_closed]) {
/* the only special exception to be queued accross thread */
err = ruby_vm_special_exception_copy(err);
}
/* set runnable if th was slept. */ /* set runnable if th was slept. */
if (th->status == THREAD_STOPPED || if (th->status == THREAD_STOPPED ||
th->status == THREAD_STOPPED_FOREVER) th->status == THREAD_STOPPED_FOREVER)