4
4
#include " builtin/array.hpp"
5
5
#include " builtin/fixnum.hpp"
6
6
#include " builtin/io.hpp"
7
+ #include " builtin/string.hpp"
7
8
#include " builtin/thread.hpp"
8
9
#include " object_memory.hpp"
9
10
#include " primitives.hpp"
@@ -56,13 +57,17 @@ namespace rubinius {
56
57
}
57
58
58
59
RIO* Handle::as_rio (NativeMethodEnvironment* env) {
59
- IO* io_obj = c_as<IO>(object ());
60
+ // IO* io_obj = c_as<IO>(object());
60
61
61
62
if (type_ != cRIO) {
62
63
env->shared ().capi_ds_lock ().lock ();
63
64
64
65
if (type_ != cRIO) {
65
- int fd = (int )io_obj->descriptor ()->to_native ();
66
+ native_int fd = -1 ;
67
+ // 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
+ }
66
71
67
72
env->shared ().capi_ds_lock ().unlock ();
68
73
@@ -72,7 +77,8 @@ namespace rubinius {
72
77
rb_raise (rb_eIOError, " %s (%d)" , err, errno);
73
78
}
74
79
75
- FILE* f = fdopen (fd, flags_modestr (io_obj->mode ()->to_native ()));
80
+ // 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 ()));
76
82
77
83
if (!f) {
78
84
char buf[RBX_STRERROR_BUFSIZE];
@@ -165,8 +171,9 @@ extern "C" {
165
171
int rb_io_fd (VALUE io_handle) {
166
172
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
167
173
168
- IO* io = c_as<IO>(env->get_object (io_handle));
169
- return io->descriptor ()->to_native ();
174
+ // IO* io = c_as<IO>(env->get_object(io_handle));
175
+ // return io->descriptor()->to_native();
176
+ return c_as<Fixnum>(env->get_object (rb_funcall (io_handle, rb_intern (" fileno" ), 0 )))->to_native ();
170
177
}
171
178
172
179
long rb_io_fread (char * ptr, int len, FILE* f) {
@@ -353,8 +360,9 @@ extern "C" {
353
360
VALUE io_handle = iot->handle ;
354
361
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
355
362
356
- IO* io = c_as<IO>(env->get_object (io_handle));
357
- io->set_nonblock (env->state ());
363
+ // IO* io = c_as<IO>(env->get_object(io_handle));
364
+ // io->set_nonblock(env->state());
365
+ rb_funcall (io_handle, rb_intern (" nonblock=" ), env->get_handle (cTrue));
358
366
}
359
367
360
368
VALUE rb_io_check_io (VALUE io) {
@@ -369,18 +377,20 @@ extern "C" {
369
377
void rb_io_check_closed (rb_io_t * iot) {
370
378
VALUE io_handle = iot->handle ;
371
379
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
372
- IO* io = c_as<IO>(env->get_object (io_handle));
380
+ // IO* io = c_as<IO>(env->get_object(io_handle));
373
381
374
- if (io->descriptor ()->to_native () == -1 ) {
382
+ // if(io->descriptor()->to_native() == -1) {
383
+ if (c_as<Fixnum>(env->get_object (rb_funcall (io_handle, rb_intern (" fileno" ), 0 )))->to_native () == -1 ) {
375
384
rb_raise (rb_eIOError, " closed stream" );
376
385
}
377
386
}
378
387
379
388
void rb_io_check_readable (rb_io_t * iot) {
380
389
VALUE io_handle = iot->handle ;
381
390
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
382
- IO* io = c_as<IO>(env->get_object (io_handle));
383
- int io_mode = io->mode ()->to_native () & O_ACCMODE;
391
+ // IO* io = c_as<IO>(env->get_object(io_handle));
392
+ // int io_mode = io->mode()->to_native() & O_ACCMODE;
393
+ int io_mode = c_as<Fixnum>(env->get_object (rb_funcall (io_handle, rb_intern (" mode" ), 0 )))->to_native () & O_ACCMODE;
384
394
if (!(O_RDONLY == io_mode || O_RDWR == io_mode)) {
385
395
rb_raise (rb_eIOError, " not opened for reading" );
386
396
}
@@ -389,25 +399,42 @@ extern "C" {
389
399
void rb_io_check_writable (rb_io_t * iot) {
390
400
VALUE io_handle = iot->handle ;
391
401
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
392
- IO* io = c_as<IO>(env->get_object (io_handle));
393
- int io_mode = io->mode ()->to_native () & O_ACCMODE;
402
+ // IO* io = c_as<IO>(env->get_object(io_handle));
403
+ // int io_mode = io->mode()->to_native() & O_ACCMODE;
404
+ int io_mode = c_as<Fixnum>(env->get_object (rb_funcall (io_handle, rb_intern (" mode" ), 0 )))->to_native () & O_ACCMODE;
394
405
if (!(O_WRONLY == io_mode || O_RDWR == io_mode)) {
395
406
rb_raise (rb_eIOError, " not opened for writing" );
396
407
}
397
408
}
398
409
399
410
void rb_update_max_fd (int fd) {
400
411
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
401
- IO::update_max_fd (env->state (), fd);
412
+
413
+ // IO::update_max_fd(env->state(), fd);
414
+ VALUE fd_class = rb_path2class (" IO::FileDescriptor" );
415
+ VALUE descriptor = env->get_handle (Fixnum::from (fd));
416
+
417
+ rb_funcall (fd_class, rb_intern (" update_max_fd" ), descriptor);
402
418
}
403
419
404
420
void rb_fd_fix_cloexec (int fd) {
405
421
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
406
- IO::new_open_fd (env->state (), fd);
422
+ // IO::new_open_fd(env->state(), fd);
423
+ VALUE fd_class = rb_path2class (" IO::FileDescriptor" );
424
+ VALUE descriptor = env->get_handle (Fixnum::from (fd));
425
+
426
+ rb_funcall (fd_class, rb_intern (" new_open_fd" ), descriptor);
407
427
}
408
428
409
429
int rb_cloexec_open (const char *pathname, int flags, int mode) {
410
430
NativeMethodEnvironment* env = NativeMethodEnvironment::get ();
411
- return IO::open_with_cloexec (env->state (), pathname, mode, flags);
431
+ VALUE fd_class = rb_path2class (" IO::FileDescriptor" );
432
+ VALUE pathname_v = env->get_handle (String::create (env->state (), pathname));
433
+ VALUE flags_v = env->get_handle (Fixnum::from (flags));
434
+ VALUE mode_v = env->get_handle (Fixnum::from (mode));
435
+ // 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);
437
+
438
+ return c_as<Fixnum>(env->get_object (result))->to_native ();
412
439
}
413
440
}
0 commit comments