@@ -57,17 +57,23 @@ namespace rubinius {
57
57
}
58
58
59
59
RIO* Handle::as_rio (NativeMethodEnvironment* env) {
60
- // IO* io_obj = c_as<IO>(object());
60
+ IO* io_obj = c_as<IO>(object ());
61
+ ID id_descriptor = rb_intern (" descriptor" );
62
+ ID id_mode = rb_intern (" mode" );
63
+ VALUE jobj = env->get_handle (io_obj);
61
64
62
65
if (type_ != cRIO) {
63
66
env->shared ().capi_ds_lock ().lock ();
64
67
65
68
if (type_ != cRIO) {
66
69
native_int fd = -1 ;
67
70
// int fd = (int)io_obj->descriptor()->to_native();
68
- if (Fixnum* f = try_as<Fixnum>(env->get_object (rb_funcall (as_value (), rb_intern (" fileno" ), 0 )))) {
69
- fd = f->to_native ();
70
- }
71
+ VALUE fileno = rb_funcall (jobj, id_descriptor, 0 );
72
+ Fixnum* tmp_fd = try_as<Fixnum>(env->get_object (fileno ));
73
+
74
+ if (tmp_fd) {
75
+ fd = tmp_fd->to_native ();
76
+ }
71
77
72
78
env->shared ().capi_ds_lock ().unlock ();
73
79
@@ -78,7 +84,7 @@ namespace rubinius {
78
84
}
79
85
80
86
// FILE* f = fdopen(fd, flags_modestr(io_obj->mode()->to_native()));
81
- FILE* f = fdopen (fd, flags_modestr (c_as <Fixnum>(env->get_object (rb_funcall (as_value (), rb_intern ( " mode " ) , 0 )))->to_native ()));
87
+ FILE* f = fdopen (fd, flags_modestr (try_as <Fixnum>(env->get_object (rb_funcall (jobj, id_mode , 0 )))->to_native ()));
82
88
83
89
if (!f) {
84
90
char buf[RBX_STRERROR_BUFSIZE];
@@ -358,11 +364,12 @@ extern "C" {
358
364
359
365
void rb_io_set_nonblock (rb_io_t * iot) {
360
366
VALUE io_handle = iot->handle ;
361
- NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
367
+ // NativeMethodEnvironment* env = NativeMethodEnvironment::get();
368
+ VALUE fd_ivar = rb_ivar_get (io_handle, rb_intern (" fd" ));
362
369
363
370
// IO* io = c_as<IO>(env->get_object(io_handle));
364
371
// io->set_nonblock(env->state());
365
- rb_funcall (io_handle , rb_intern (" nonblock= " ), env-> get_handle (cTrue) );
372
+ rb_funcall (fd_ivar , rb_intern (" set_nonblock " ), 0 );
366
373
}
367
374
368
375
VALUE rb_io_check_io (VALUE io) {
@@ -420,20 +427,20 @@ extern "C" {
420
427
void rb_fd_fix_cloexec (int fd) {
421
428
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
422
429
// IO::new_open_fd(env->state(), fd);
423
- VALUE fd_class = rb_path2class (" IO::FileDescriptor" );
424
430
VALUE descriptor = env->get_handle (Fixnum::from (fd));
431
+ VALUE fd_class = rb_path2class (" IO::FileDescriptor" );
425
432
426
433
rb_funcall (fd_class, rb_intern (" new_open_fd" ), descriptor);
427
434
}
428
435
429
436
int rb_cloexec_open (const char *pathname, int flags, int mode) {
430
437
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
431
- VALUE fd_class = rb_path2class (" IO::FileDescriptor" );
438
+ VALUE fd_class = rb_path2class (" IO::FileDescriptor" );
432
439
VALUE pathname_v = env->get_handle (String::create (env->state (), pathname));
433
440
VALUE flags_v = env->get_handle (Fixnum::from (flags));
434
441
VALUE mode_v = env->get_handle (Fixnum::from (mode));
435
442
// return -1; //IO::open_with_cloexec(env->state(), pathname, mode, flags);
436
- VALUE result = rb_funcall (fd_class, rb_intern (" open_with_cloexec" ), pathname_v, flags_v, mode_v);
443
+ VALUE result = rb_funcall (fd_class, rb_intern (" open_with_cloexec" ), pathname_v, flags_v, mode_v);
437
444
438
445
return c_as<Fixnum>(env->get_object (result))->to_native ();
439
446
}
0 commit comments