Skip to content

Commit a5ae024

Browse files
committedOct 7, 2015
fix several CAPI specs by correctly getting descriptor
1 parent 20141ec commit a5ae024

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed
 

‎vm/capi/io.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,23 @@ namespace rubinius {
5757
}
5858

5959
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);
6164

6265
if(type_ != cRIO) {
6366
env->shared().capi_ds_lock().lock();
6467

6568
if(type_ != cRIO) {
6669
native_int fd = -1;
6770
//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+
}
7177

7278
env->shared().capi_ds_lock().unlock();
7379

@@ -78,7 +84,7 @@ namespace rubinius {
7884
}
7985

8086
//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()));
8288

8389
if(!f) {
8490
char buf[RBX_STRERROR_BUFSIZE];
@@ -358,11 +364,12 @@ extern "C" {
358364

359365
void rb_io_set_nonblock(rb_io_t* iot) {
360366
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"));
362369

363370
//IO* io = c_as<IO>(env->get_object(io_handle));
364371
//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);
366373
}
367374

368375
VALUE rb_io_check_io(VALUE io) {
@@ -420,20 +427,20 @@ extern "C" {
420427
void rb_fd_fix_cloexec(int fd) {
421428
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
422429
//IO::new_open_fd(env->state(), fd);
423-
VALUE fd_class = rb_path2class("IO::FileDescriptor");
424430
VALUE descriptor = env->get_handle(Fixnum::from(fd));
431+
VALUE fd_class = rb_path2class("IO::FileDescriptor");
425432

426433
rb_funcall(fd_class, rb_intern("new_open_fd"), descriptor);
427434
}
428435

429436
int rb_cloexec_open(const char *pathname, int flags, int mode) {
430437
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
431-
VALUE fd_class = rb_path2class("IO::FileDescriptor");
438+
VALUE fd_class = rb_path2class("IO::FileDescriptor");
432439
VALUE pathname_v = env->get_handle(String::create(env->state(), pathname));
433440
VALUE flags_v = env->get_handle(Fixnum::from(flags));
434441
VALUE mode_v = env->get_handle(Fixnum::from(mode));
435442
//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);
437444

438445
return c_as<Fixnum>(env->get_object(result))->to_native();
439446
}

0 commit comments

Comments
 (0)
Please sign in to comment.