Refactored rb_readwrite_syserr_fail

* renamed argument `writable` as `waiting`
* hosited out creating and raising exception
* turned into a `switch`
This commit is contained in:
Nobuyoshi Nakada 2020-04-15 01:07:50 +09:00
parent 00d9278387
commit b5132d91c0
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6

38
io.c
View File

@ -13014,53 +13014,55 @@ argf_write(VALUE argf, VALUE str)
} }
void void
rb_readwrite_sys_fail(enum rb_io_wait_readwrite writable, const char *mesg) rb_readwrite_sys_fail(enum rb_io_wait_readwrite waiting, const char *mesg)
{ {
rb_readwrite_syserr_fail(writable, errno, mesg); rb_readwrite_syserr_fail(waiting, errno, mesg);
} }
void void
rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg) rb_readwrite_syserr_fail(enum rb_io_wait_readwrite waiting, int n, const char *mesg)
{ {
VALUE arg; VALUE arg, c = Qnil;
arg = mesg ? rb_str_new2(mesg) : Qnil; arg = mesg ? rb_str_new2(mesg) : Qnil;
if (writable == RB_IO_WAIT_WRITABLE) { switch (waiting) {
case RB_IO_WAIT_WRITABLE:
switch (n) { switch (n) {
case EAGAIN: case EAGAIN:
rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEAGAINWaitWritable)); c = rb_eEAGAINWaitWritable;
break; break;
#if EAGAIN != EWOULDBLOCK #if EAGAIN != EWOULDBLOCK
case EWOULDBLOCK: case EWOULDBLOCK:
rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEWOULDBLOCKWaitWritable)); c = rb_eEWOULDBLOCKWaitWritable;
break; break;
#endif #endif
case EINPROGRESS: case EINPROGRESS:
rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEINPROGRESSWaitWritable)); c = rb_eEINPROGRESSWaitWritable;
break; break;
default: default:
rb_mod_sys_fail_str(rb_mWaitWritable, arg); rb_mod_syserr_fail_str(rb_mWaitWritable, n, arg);
} }
} break;
else if (writable == RB_IO_WAIT_READABLE) { case RB_IO_WAIT_READABLE:
switch (n) { switch (n) {
case EAGAIN: case EAGAIN:
rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEAGAINWaitReadable)); c = rb_eEAGAINWaitReadable;
break; break;
#if EAGAIN != EWOULDBLOCK #if EAGAIN != EWOULDBLOCK
case EWOULDBLOCK: case EWOULDBLOCK:
rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEWOULDBLOCKWaitReadable)); c = rb_eEWOULDBLOCKWaitReadable;
break; break;
#endif #endif
case EINPROGRESS: case EINPROGRESS:
rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEINPROGRESSWaitReadable)); c = rb_eEINPROGRESSWaitReadable;
break; break;
default: default:
rb_mod_sys_fail_str(rb_mWaitReadable, arg); rb_mod_syserr_fail_str(rb_mWaitReadable, n, arg);
} }
break;
default:
rb_bug("invalid read/write type passed to rb_readwrite_sys_fail: %d", waiting);
} }
else { rb_exc_raise(rb_class_new_instance(1, &arg, c));
rb_bug("invalid read/write type passed to rb_readwrite_sys_fail: %d", writable);
}
} }
static VALUE static VALUE