[macruby-changes] [884] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 11 18:47:49 PDT 2009


Revision: 884
          http://trac.macosforge.org/projects/ruby/changeset/884
Author:   pthomson at apple.com
Date:     2009-03-11 18:47:48 -0700 (Wed, 11 Mar 2009)
Log Message:
-----------
HUGE commit. Removed most of the IO systems, excluded many of the IO-dependent components, broke the world, etc.

Modified Paths:
--------------
    MacRuby/branches/experimental/Rakefile
    MacRuby/branches/experimental/file.c
    MacRuby/branches/experimental/gc.c
    MacRuby/branches/experimental/include/ruby/intern.h
    MacRuby/branches/experimental/include/ruby/io.h
    MacRuby/branches/experimental/include/ruby/ruby.h
    MacRuby/branches/experimental/inits.c
    MacRuby/branches/experimental/io.c
    MacRuby/branches/experimental/marshal.c
    MacRuby/branches/experimental/parse.y
    MacRuby/branches/experimental/ruby.c
    MacRuby/branches/experimental/string.c
    MacRuby/branches/experimental/test_roxor.rb

Modified: MacRuby/branches/experimental/Rakefile
===================================================================
--- MacRuby/branches/experimental/Rakefile	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/Rakefile	2009-03-12 01:47:48 UTC (rev 884)
@@ -92,13 +92,14 @@
 LDFLAGS << " -lpthread -ldl -lxml2 -lobjc -lffi -lauto -framework Foundation"
 DLDFLAGS = "-dynamiclib -undefined suppress -flat_namespace -install_name #{INSTALL_NAME} -current_version #{MACRUBY_VERSION} -compatibility_version #{MACRUBY_VERSION}"
 
+# removed: marshal, file, process
 OBJS = %w{ 
-  array bignum class compar complex dir enum enumerator error eval load proc 
-  file gc hash inits io marshal math numeric object pack parse process prec 
+  array bignum class compar complex enum enumerator error eval file load proc 
+  gc hash inits io math numeric object pack parse prec  
   random range rational re regcomp regenc regerror regexec regparse regsyntax
   ruby set signal sprintf st string struct time transcode util variable version
-  thread id objc bs encoding main dln dmyext enc/ascii vm_eval prelude miniprelude
-  gc-stub roxor
+  thread id objc bs encoding main dln dmyext enc/ascii 
+  vm_eval prelude miniprelude gc-stub roxor
 }
 
 class Builder

Modified: MacRuby/branches/experimental/file.c
===================================================================
--- MacRuby/branches/experimental/file.c	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/file.c	2009-03-12 01:47:48 UTC (rev 884)
@@ -167,12 +167,13 @@
 static VALUE
 rb_file_path(VALUE obj, SEL sel)
 {
-    rb_io_t *fptr;
-
-    fptr = RFILE(rb_io_taint_check(obj))->fptr;
-    rb_io_check_initialized(fptr);
-    if (!fptr->path) return Qnil;
-    return rb_tainted_str_new2(fptr->path);
+    // rb_io_t *fptr;
+    // 
+    // fptr = RFILE(rb_io_taint_check(obj))->fptr;
+    // rb_io_check_initialized(fptr);
+    // if (!fptr->path) return Qnil;
+    // return rb_tainted_str_new2(fptr->path);
+    rb_notimplement();
 }
 
 static VALUE
@@ -712,18 +713,19 @@
 static int
 rb_stat(VALUE file, struct stat *st)
 {
-    VALUE tmp;
-
-    rb_secure(2);
-    tmp = rb_check_convert_type(file, T_FILE, "IO", "to_io");
-    if (!NIL_P(tmp)) {
-	rb_io_t *fptr;
-
-	GetOpenFile(tmp, fptr);
-	return fstat(fptr->fd, st);
-    }
-    FilePathValue(file);
-    return stat(StringValueCStr(file), st);
+    //     VALUE tmp;
+    // 
+    //     rb_secure(2);
+    //     tmp = rb_check_convert_type(file, T_FILE, "IO", "to_io");
+    //     if (!NIL_P(tmp)) {
+    // rb_io_t *fptr;
+    // 
+    // GetOpenFile(tmp, fptr);
+    // return fstat(fptr->fd, st);
+    //     }
+    //     FilePathValue(file);
+    //     return stat(StringValueCStr(file), st);
+    rb_notimplement();
 }
 
 #ifdef _WIN32
@@ -800,14 +802,15 @@
 static VALUE
 rb_io_stat(VALUE obj, SEL sel)
 {
-    rb_io_t *fptr;
-    struct stat st;
-
-    GetOpenFile(obj, fptr);
-    if (fstat(fptr->fd, &st) == -1) {
-	rb_sys_fail(fptr->path);
-    }
-    return stat_new(&st);
+    //     rb_io_t *fptr;
+    //     struct stat st;
+    // 
+    //     GetOpenFile(obj, fptr);
+    //     if (fstat(fptr->fd, &st) == -1) {
+    // rb_sys_fail(fptr->path);
+    //     }
+    //     return stat_new(&st);
+    rb_notimplement();
 }
 
 /*
@@ -859,20 +862,21 @@
 static VALUE
 rb_file_lstat(VALUE obj, SEL sel)
 {
-#ifdef HAVE_LSTAT
-    rb_io_t *fptr;
-    struct stat st;
-
-    rb_secure(2);
-    GetOpenFile(obj, fptr);
-    if (!fptr->path) return Qnil;
-    if (lstat(fptr->path, &st) == -1) {
-	rb_sys_fail(fptr->path);
-    }
-    return stat_new(&st);
-#else
-    return rb_io_stat(obj, 0);
-#endif
+// #ifdef HAVE_LSTAT
+//     rb_io_t *fptr;
+//     struct stat st;
+// 
+//     rb_secure(2);
+//     GetOpenFile(obj, fptr);
+//     if (!fptr->path) return Qnil;
+//     if (lstat(fptr->path, &st) == -1) {
+//  rb_sys_fail(fptr->path);
+//     }
+//     return stat_new(&st);
+// #else
+//     return rb_io_stat(obj, 0);
+// #endif
+    rb_notimplement();
 }
 
 #ifndef HAVE_GROUP_MEMBER
@@ -1702,14 +1706,15 @@
 static VALUE
 rb_file_atime(VALUE obj, SEL sel)
 {
-    rb_io_t *fptr;
-    struct stat st;
-
-    GetOpenFile(obj, fptr);
-    if (fstat(fptr->fd, &st) == -1) {
-	rb_sys_fail(fptr->path);
-    }
-    return stat_atime(&st);
+    //     rb_io_t *fptr;
+    //     struct stat st;
+    // 
+    //     GetOpenFile(obj, fptr);
+    //     if (fstat(fptr->fd, &st) == -1) {
+    // rb_sys_fail(fptr->path);
+    //     }
+    //     return stat_atime(&st);
+        rb_notimplement();
 }
 
 /*
@@ -1745,14 +1750,15 @@
 static VALUE
 rb_file_mtime(VALUE obj, SEL sel)
 {
-    rb_io_t *fptr;
-    struct stat st;
-
-    GetOpenFile(obj, fptr);
-    if (fstat(fptr->fd, &st) == -1) {
-	rb_sys_fail(fptr->path);
-    }
-    return stat_mtime(&st);
+    //     rb_io_t *fptr;
+    //     struct stat st;
+    // 
+    //     GetOpenFile(obj, fptr);
+    //     if (fstat(fptr->fd, &st) == -1) {
+    // rb_sys_fail(fptr->path);
+    //     }
+    //     return stat_mtime(&st);
+    rb_notimplement();
 }
 
 /*
@@ -1791,14 +1797,15 @@
 static VALUE
 rb_file_ctime(VALUE obj, SEL sel)
 {
-    rb_io_t *fptr;
-    struct stat st;
-
-    GetOpenFile(obj, fptr);
-    if (fstat(fptr->fd, &st) == -1) {
-	rb_sys_fail(fptr->path);
-    }
-    return stat_ctime(&st);
+    //     rb_io_t *fptr;
+    //     struct stat st;
+    // 
+    //     GetOpenFile(obj, fptr);
+    //     if (fstat(fptr->fd, &st) == -1) {
+    // rb_sys_fail(fptr->path);
+    //     }
+    //     return stat_ctime(&st);
+    rb_notimplement();
 }
 
 static void
@@ -1853,23 +1860,24 @@
 static VALUE
 rb_file_chmod(VALUE obj, SEL sel, VALUE vmode)
 {
-    rb_io_t *fptr;
-    int mode;
-
-    rb_secure(2);
-    mode = NUM2INT(vmode);
-
-    GetOpenFile(obj, fptr);
-#ifdef HAVE_FCHMOD
-    if (fchmod(fptr->fd, mode) == -1)
-	rb_sys_fail(fptr->path);
-#else
-    if (!fptr->path) return Qnil;
-    if (chmod(fptr->path, mode) == -1)
-	rb_sys_fail(fptr->path);
-#endif
-
-    return INT2FIX(0);
+//     rb_io_t *fptr;
+//     int mode;
+// 
+//     rb_secure(2);
+//     mode = NUM2INT(vmode);
+// 
+//     GetOpenFile(obj, fptr);
+// #ifdef HAVE_FCHMOD
+//     if (fchmod(fptr->fd, mode) == -1)
+//  rb_sys_fail(fptr->path);
+// #else
+//     if (!fptr->path) return Qnil;
+//     if (chmod(fptr->path, mode) == -1)
+//  rb_sys_fail(fptr->path);
+// #endif
+// 
+//     return INT2FIX(0);
+    rb_notimplement();
 }
 
 #if defined(HAVE_LCHMOD)
@@ -1985,23 +1993,24 @@
 static VALUE
 rb_file_chown(VALUE obj, SEL sel, VALUE owner, VALUE group)
 {
-    rb_io_t *fptr;
-    int o, g;
-
-    rb_secure(2);
-    o = NIL_P(owner) ? -1 : NUM2INT(owner);
-    g = NIL_P(group) ? -1 : NUM2INT(group);
-    GetOpenFile(obj, fptr);
-#if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__EMX__)
-    if (!fptr->path) return Qnil;
-    if (chown(fptr->path, o, g) == -1)
-	rb_sys_fail(fptr->path);
-#else
-    if (fchown(fptr->fd, o, g) == -1)
-	rb_sys_fail(fptr->path);
-#endif
-
-    return INT2FIX(0);
+//     rb_io_t *fptr;
+//     int o, g;
+// 
+//     rb_secure(2);
+//     o = NIL_P(owner) ? -1 : NUM2INT(owner);
+//     g = NIL_P(group) ? -1 : NUM2INT(group);
+//     GetOpenFile(obj, fptr);
+// #if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__EMX__)
+//     if (!fptr->path) return Qnil;
+//     if (chown(fptr->path, o, g) == -1)
+//  rb_sys_fail(fptr->path);
+// #else
+//     if (fchown(fptr->fd, o, g) == -1)
+//  rb_sys_fail(fptr->path);
+// #endif
+    
+//    return INT2FIX(0);
+    rb_notimplement();
 }
 
 #if defined(HAVE_LCHOWN) && !defined(__CHECKER__)
@@ -3392,28 +3401,29 @@
 static VALUE
 rb_file_truncate(VALUE obj, SEL sel, VALUE len)
 {
-    rb_io_t *fptr;
-    off_t pos;
-
-    rb_secure(2);
-    pos = NUM2OFFT(len);
-    GetOpenFile(obj, fptr);
-    if (!(fptr->mode & FMODE_WRITABLE)) {
-	rb_raise(rb_eIOError, "not opened for writing");
-    }
-    rb_io_flush(obj);
-#ifdef HAVE_FTRUNCATE
-    if (ftruncate(fptr->fd, pos) < 0)
-	rb_sys_fail(fptr->path);
-#else
-# ifdef HAVE_CHSIZE
-    if (chsize(fptr->fd, pos) < 0)
-	rb_sys_fail(fptr->path);
-# else
+//     rb_io_t *fptr;
+//     off_t pos;
+// 
+//     rb_secure(2);
+//     pos = NUM2OFFT(len);
+//     GetOpenFile(obj, fptr);
+//     if (!(fptr->mode & FMODE_WRITABLE)) {
+//  rb_raise(rb_eIOError, "not opened for writing");
+//     }
+//     rb_io_flush(obj);
+// #ifdef HAVE_FTRUNCATE
+//     if (ftruncate(fptr->fd, pos) < 0)
+//  rb_sys_fail(fptr->path);
+// #else
+// # ifdef HAVE_CHSIZE
+//     if (chsize(fptr->fd, pos) < 0)
+//  rb_sys_fail(fptr->path);
+// # else
+//     rb_notimplement();
+// # endif
+// #endif
+//     return INT2FIX(0);
     rb_notimplement();
-# endif
-#endif
-    return INT2FIX(0);
 }
 
 # ifndef LOCK_SH
@@ -3462,7 +3472,7 @@
  *     File.new("testfile").flock(File::LOCK_UN)   #=> 0
  *     
  */
-
+#if 0
 static VALUE
 rb_file_flock(VALUE obj, SEL sel, VALUE operation)
 {
@@ -3506,6 +3516,7 @@
     return INT2FIX(0);
 }
 #undef flock
+#endif
 
 static void
 test_check(int n, int argc, VALUE *argv)
@@ -4761,7 +4772,7 @@
     rb_objc_define_method(rb_cFile, "chown", rb_file_chown, 2);
     rb_objc_define_method(rb_cFile, "truncate", rb_file_truncate, 1);
 
-    rb_objc_define_method(rb_cFile, "flock", rb_file_flock, 1);
+    //rb_objc_define_method(rb_cFile, "flock", rb_file_flock, 1);
 
     rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
     rb_include_module(rb_cIO, rb_mFConst);

Modified: MacRuby/branches/experimental/gc.c
===================================================================
--- MacRuby/branches/experimental/gc.c	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/gc.c	2009-03-12 01:47:48 UTC (rev 884)
@@ -38,7 +38,10 @@
 #endif
 static auto_zone_t *__auto_zone = NULL;
 
-int rb_io_fptr_finalize(struct rb_io_t*);
+int rb_io_fptr_finalize(struct rb_io_t* t)
+{
+    rb_notimplement();
+}
 
 static VALUE nomem_error;
 

Modified: MacRuby/branches/experimental/include/ruby/intern.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/intern.h	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/include/ruby/intern.h	2009-03-12 01:47:48 UTC (rev 884)
@@ -281,6 +281,8 @@
 VALUE rb_proc_call(VALUE, VALUE);
 int rb_proc_arity(VALUE);
 VALUE rb_binding_new(void);
+VALUE rb_obj_method(VALUE, VALUE);
+VALUE rb_method_call(int, VALUE*, VALUE);
 int rb_mod_method_arity(VALUE, ID);
 int rb_obj_method_arity(VALUE, ID);
 VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*);
@@ -386,17 +388,17 @@
 RUBY_EXTERN VALUE rb_rs;
 RUBY_EXTERN VALUE rb_default_rs;
 RUBY_EXTERN VALUE rb_output_rs;
-VALUE rb_io_write(VALUE, VALUE);
-VALUE rb_io_gets(VALUE);
-VALUE rb_io_getbyte(VALUE);
-VALUE rb_io_ungetc(VALUE, VALUE);
-VALUE rb_io_close(VALUE);
-VALUE rb_io_flush(VALUE);
-VALUE rb_io_eof(VALUE);
-VALUE rb_io_binmode(VALUE);
-VALUE rb_io_addstr(VALUE, VALUE);
-VALUE rb_io_printf(int, VALUE*, VALUE);
-VALUE rb_io_print(int, VALUE*, VALUE);
+VALUE rb_io_write(VALUE, SEL, VALUE);
+VALUE rb_io_gets(VALUE, SEL);
+VALUE rb_io_getbyte(VALUE, SEL);
+VALUE rb_io_ungetc(VALUE, SEL, VALUE);
+VALUE rb_io_close(VALUE, SEL);
+VALUE rb_io_flush(VALUE, SEL);
+VALUE rb_io_eof(VALUE, SEL);
+VALUE rb_io_binmode(VALUE, SEL);
+VALUE rb_io_addstr(VALUE, SEL, VALUE);
+VALUE rb_io_printf(VALUE, SEL, int, VALUE *);
+VALUE rb_io_print(VALUE, SEL, int, VALUE *);
 VALUE rb_io_fdopen(int, int, const char*);
 VALUE rb_file_open(const char*, const char*);
 VALUE rb_gets(void);

Modified: MacRuby/branches/experimental/include/ruby/io.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/io.h	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/include/ruby/io.h	2009-03-12 01:47:48 UTC (rev 884)
@@ -23,57 +23,23 @@
 #include <errno.h>
 #include "ruby/encoding.h"
 
-#if defined(HAVE_STDIO_EXT_H)
-#include <stdio_ext.h>
-#endif
-
 typedef struct rb_io_t {
-    int fd;                     /* file descriptor */
-    FILE *stdio_file;		/* stdio ptr for read/write if available */
-    int mode;			/* mode flags */
-    rb_pid_t pid;		/* child's pid (for pipes) */
-    int lineno;			/* number of lines read */
-    char *path;			/* pathname for file */
-    void (*finalize)(struct rb_io_t*,int); /* finalize proc */
-    long refcnt;
-    char *wbuf;                 /* wbuf_off + wbuf_len <= wbuf_capa */
-    int wbuf_off;
-    int wbuf_len;
-    int wbuf_capa;
-    char *rbuf;                 /* rbuf_off + rbuf_len <= rbuf_capa */
-    int rbuf_off;
-    int rbuf_len;
-    int rbuf_capa;
-    VALUE tied_io_for_writing;
-    rb_encoding *enc;
-    rb_encoding *enc2;
+    CFReadStreamRef readStream;
+    CFWriteStreamRef writeStream;
+    CFStringRef path;
+    pid_t pid;
+    int lineno;
 } rb_io_t;
 
-#define HAVE_RB_IO_T 1
 
-#define FMODE_READABLE  1
-#define FMODE_WRITABLE  2
-#define FMODE_READWRITE 3
-#define FMODE_APPEND   64
-#define FMODE_CREATE  128
-#define FMODE_BINMODE   4
-#define FMODE_SYNC      8
-#define FMODE_TTY      16
-#define FMODE_DUPLEX   32
-#define FMODE_WSPLIT  0x200
-#define FMODE_WSPLIT_INITIALIZED  0x400
-
-#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
-
-#define MakeOpenFile(obj, fp) do {\
+#define CreateIOStruct(obj, fp) do {\
     if (RFILE(obj)->fptr) {\
 	rb_io_close(obj);\
 	free(RFILE(obj)->fptr);\
 	RFILE(obj)->fptr = 0;\
     }\
     fp = 0;\
-    fp = ALLOC(rb_io_t);\
-    GC_WB(&RFILE(obj)->fptr, fp);\
+    fp = RFILE(obj)->fptr = ALLOC(rb_io_t);\
     fp->fd = -1;\
     fp->stdio_file = NULL;\
     fp->mode = 0;\
@@ -95,34 +61,24 @@
     fp->enc2 = 0;\
 } while (0)
 
-FILE *rb_io_stdio_file(rb_io_t *fptr);
+#define HAVE_RB_IO_T 1
 
-FILE *rb_fopen(const char*, const char*);
-FILE *rb_fdopen(int, const char*);
-int  rb_io_mode_flags(const char*);
-int  rb_io_modenum_flags(int);
-void rb_io_check_writable(rb_io_t*);
-void rb_io_check_readable(rb_io_t*);
-int rb_io_fptr_finalize(rb_io_t*);
-void rb_io_synchronized(rb_io_t*);
-void rb_io_check_initialized(rb_io_t*);
-void rb_io_check_closed(rb_io_t*);
-int rb_io_wait_readable(int);
-int rb_io_wait_writable(int);
-void rb_io_set_nonblock(rb_io_t *fptr);
+#define FMODE_READABLE  1
+#define FMODE_WRITABLE  2
+#define FMODE_READWRITE 3
+#define FMODE_APPEND   64
+#define FMODE_CREATE  128
+#define FMODE_BINMODE   4
+#define FMODE_SYNC      8
+#define FMODE_TTY      16
+#define FMODE_DUPLEX   32
+#define FMODE_WSPLIT  0x200
+#define FMODE_WSPLIT_INITIALIZED  0x400
 
 VALUE rb_io_taint_check(VALUE);
 NORETURN(void rb_eof_error(void));
 
-void rb_io_read_check(rb_io_t*);
-int rb_io_read_pending(rb_io_t*);
-void rb_read_check(FILE*);
 
-DEPRECATED(int rb_getc(FILE*));
-DEPRECATED(long rb_io_fread(char *, long, FILE *));
-DEPRECATED(long rb_io_fwrite(const char *, long, FILE *));
-DEPRECATED(int rb_read_pending(FILE*));
-
 #if defined(__cplusplus)
 #if 0
 { /* satisfy cc-mode */

Modified: MacRuby/branches/experimental/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/ruby.h	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/include/ruby/ruby.h	2009-03-12 01:47:48 UTC (rev 884)
@@ -355,6 +355,11 @@
 #define StringValuePtr(v) rb_string_value_ptr(&(v))
 #define StringValueCStr(v) rb_string_value_cstr(&(v))
 
+VALUE rb_bytestring_new();
+CFMutableDataRef rb_bytestring_wrapped_data(VALUE);
+UInt8 *rb_bytestring_byte_pointer(VALUE);
+VALUE rb_coerce_to_bytestring(VALUE);
+
 void rb_check_safe_obj(VALUE);
 void rb_check_safe_str(VALUE);
 #define SafeStringValue(v) do {\
@@ -666,6 +671,8 @@
     void *data;
 };
 
+#define ExtractIOStruct(obj) RFILE(rb_io_taint_check(obj))->fptr
+
 #define DATA_PTR(dta) (RDATA(dta)->data)
 
 /*
@@ -917,7 +924,7 @@
 const char *rb_class2name(VALUE);
 const char *rb_obj_classname(VALUE);
 
-void rb_p(VALUE);
+void rb_p(VALUE, SEL);
 
 VALUE rb_eval_string(const char*);
 VALUE rb_eval_string_protect(const char*, int*);
@@ -974,6 +981,8 @@
 
 VALUE rb_require(const char*);
 
+void rb_objc_keep_for_exit_finalize(VALUE);
+
 #ifdef __ia64
 void ruby_init_stack(VALUE*, void*);
 #define ruby_init_stack(addr) ruby_init_stack(addr, rb_ia64_bsp())
@@ -1035,6 +1044,7 @@
 RUBY_EXTERN VALUE rb_cSet;
 RUBY_EXTERN VALUE rb_cStat;
 RUBY_EXTERN VALUE rb_cString;
+RUBY_EXTERN VALUE rb_cByteString;
 RUBY_EXTERN VALUE rb_cStruct;
 RUBY_EXTERN VALUE rb_cSymbol;
 RUBY_EXTERN VALUE rb_cThread;
@@ -1103,6 +1113,8 @@
 }
 #define NATIVE(obj) (rb_is_native((VALUE)obj))
 
+#define CONDITION_TO_BOOLEAN(c) (c ? Qtrue : Qfalse)
+
 VALUE rb_box_fixnum(VALUE);
 
 static inline id
@@ -1167,6 +1179,7 @@
 #define RARRAY_AT(a,i) (rb_ary_elt_fast((CFArrayRef)a, (long)i))
 #endif
 
+
 static inline VALUE
 rb_class_of(VALUE obj)
 {

Modified: MacRuby/branches/experimental/inits.c
===================================================================
--- MacRuby/branches/experimental/inits.c	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/inits.c	2009-03-12 01:47:48 UTC (rev 884)
@@ -17,7 +17,7 @@
 void Init_Comparable(void);
 void Init_Complex(void);
 void Init_transcode(void);
-void Init_Dir(void);
+//void Init_Dir(void);
 void Init_Enumerable(void);
 void Init_Enumerator(void);
 void Init_Exception(void);
@@ -30,14 +30,14 @@
 void Init_Hash(void);
 void Init_IO(void);
 void Init_Math(void);
-void Init_marshal(void);
+// void Init_marshal(void);
 void Init_Numeric(void);
 void Init_Object(void);
 void Init_pack(void);
 void Init_Precision(void);
 void Init_sym(void);
 void Init_id(void);
-void Init_process(void);
+//void Init_process(void);
 void Init_Random(void);
 void Init_Range(void);
 void Init_Rational(void);
@@ -46,7 +46,7 @@
 void Init_String(void);
 void Init_Struct(void);
 void Init_Set(void);
-void Init_Time(void);
+void Init_Time(void);   
 void Init_var_tables(void);
 void Init_version(void);
 void Init_VM(void);
@@ -82,14 +82,14 @@
     Init_Regexp();
     Init_pack();
     Init_transcode();
-    Init_marshal();
+    // Init_marshal();
     Init_Range();
     Init_IO();
-    Init_Dir();
+    // Init_Dir();
     Init_Time();
     Init_Random();
     Init_signal();
-    Init_process();
+//    Init_process();
     Init_load();
     Init_Proc();
     Init_Binding();

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/io.c	2009-03-12 01:47:48 UTC (rev 884)
@@ -19,79 +19,26 @@
 #include <ctype.h>
 #include <errno.h>
 
-#if defined(DOSISH) || defined(__CYGWIN__)
-#include <io.h>
-#endif
-
 #include <sys/types.h>
-#if !defined(_WIN32) && !defined(__DJGPP__)
-# if defined(__BEOS__)
-#  include <net/socket.h>
-# else
-#  include <sys/socket.h>
-# endif
-#endif
-
-#if defined(MSDOS) || defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__human68k__) || defined(__EMX__) || defined(__BEOS__)
-# define NO_SAFE_RENAME
-#endif
-
-#if defined(MSDOS) || defined(__CYGWIN__) || defined(_WIN32)
-# define NO_LONG_FNAME
-#endif
-
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(sun) || defined(_nec_ews)
-# define USE_SETVBUF
-#endif
-
-#ifdef __QNXNTO__
-#include "unix.h"
-#endif
-
+#include <sys/socket.h>
+#include <sys/select.h>
 #include <sys/types.h>
-#if defined(HAVE_SYS_IOCTL_H) && !defined(DJGPP) && !defined(_WIN32) && !defined(__human68k__)
 #include <sys/ioctl.h>
-#endif
-#if defined(HAVE_FCNTL_H) || defined(_WIN32)
 #include <fcntl.h>
-#elif defined(HAVE_SYS_FCNTL_H)
-#include <sys/fcntl.h>
-#endif
 
-#if !HAVE_OFF_T && !defined(off_t)
-# define off_t  long
-#endif
-
 #include <sys/stat.h>
 
-/* EMX has sys/param.h, but.. */
-#if defined(HAVE_SYS_PARAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__))
-# include <sys/param.h>
-#endif
+#include <sys/param.h>
 
 #if !defined NOFILE
 # define NOFILE 64
 #endif
 
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
-
-#ifdef HAVE_SYSCALL_H
-#include <syscall.h>
-#elif defined HAVE_SYS_SYSCALL_H
 #include <sys/syscall.h>
-#endif
 
 extern void Init_File(void);
 
-#ifdef __BEOS__
-# ifndef NOFILE
-#  define NOFILE (OPEN_MAX)
-# endif
-#include <net/socket.h>
-#endif
-
 #include "ruby/util.h"
 
 #ifndef O_ACCMODE
@@ -102,14 +49,6 @@
 # error off_t is bigger than long, but you have no long long...
 #endif
 
-#ifndef PIPE_BUF
-# ifdef _POSIX_PIPE_BUF
-#  define PIPE_BUF _POSIX_PIPE_BUF
-# else
-#  define PIPE_BUF 512 /* is this ok? */
-# endif
-#endif
-
 VALUE rb_cIO;
 VALUE rb_eEOFError;
 VALUE rb_eIOError;
@@ -140,7 +79,7 @@
     rb_encoding *enc, *enc2;
 };
 
-static int max_file_descriptor = NOFILE;
+//static int max_file_descriptor = NOFILE;
 #define UPDATE_MAXFD(fd) \
     do { \
         if (max_file_descriptor < (fd)) max_file_descriptor = (fd); \
@@ -155,73 +94,15 @@
 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
 #define ARGF argf_of(argf)
 
-#ifdef _STDIO_USES_IOSTREAM  /* GNU libc */
-#  ifdef _IO_fpos_t
-#    define STDIO_READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
-#  else
-#    define STDIO_READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
-#  endif
-#elif defined(FILE_COUNT)
-#  define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
-#elif defined(FILE_READEND)
-#  define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
-#elif defined(__BEOS__)
-#  define STDIO_READ_DATA_PENDING(fp) (fp->_state._eof == 0)
-#elif defined(__VMS)
-#  define STDIO_READ_DATA_PENDING(fp) (((unsigned int)(*(fp))->_cnt) > 0)
-#else
-#  define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
-#endif
+// static int
+// is_socket(int fd, const char *path)
+// {
+//     struct stat sbuf;
+//     if (fstat(fd, &sbuf) < 0)
+//         rb_sys_fail(path);
+//     return S_ISSOCK(sbuf.st_mode);
+// }
 
-#if defined(__VMS)
-#define fopen(file_spec, mode)  fopen(file_spec, mode, "rfm=stmlf")
-#define open(file_spec, flags, mode)  open(file_spec, flags, mode, "rfm=stmlf")
-#endif
-
-#define GetWriteIO(io) rb_io_get_write_io(io)
-
-#define READ_DATA_PENDING(fptr) ((fptr)->rbuf_len)
-#define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf_len)
-#define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf+(fptr)->rbuf_off)
-#define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
-
-#define READ_CHECK(fptr) do {\
-    if (!READ_DATA_PENDING(fptr)) {\
-	rb_thread_wait_fd((fptr)->fd);\
-	rb_io_check_closed(fptr);\
-     }\
-} while(0)
-
-#ifndef S_ISSOCK
-#  ifdef _S_ISSOCK
-#    define S_ISSOCK(m) _S_ISSOCK(m)
-#  else
-#    ifdef _S_IFSOCK
-#      define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
-#    else
-#      ifdef S_IFSOCK
-#	 define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
-#      endif
-#    endif
-#  endif
-#endif
-
-#if defined(_WIN32)
-#define is_socket(fd, path)	rb_w32_is_socket(fd)
-#elif !defined(S_ISSOCK)
-#define is_socket(fd, path)	0
-#define shutdown(a,b)	0
-#else
-static int
-is_socket(int fd, const char *path)
-{
-    struct stat sbuf;
-    if (fstat(fd, &sbuf) < 0)
-        rb_sys_fail(path);
-    return S_ISSOCK(sbuf.st_mode);
-}
-#endif
-
 void
 rb_eof_error(void)
 {
@@ -241,45 +122,57 @@
 rb_io_check_initialized(rb_io_t *fptr)
 {
     if (!fptr) {
-	rb_raise(rb_eIOError, "uninitialized stream");
+	    rb_raise(rb_eIOError, "uninitialized stream");
     }
 }
 
-void
-rb_io_check_closed(rb_io_t *fptr)
-{
-    rb_io_check_initialized(fptr);
-    if (fptr->fd < 0) {
-	rb_raise(rb_eIOError, "closed stream");
+void rb_io_assert_writable(rb_io_t *io_struct) {
+    rb_io_check_initialized(io_struct);
+    if(CFWriteStreamGetStatus(io_struct->writeStream) != kCFStreamStatusOpen) {
+        rb_raise(rb_eIOError, "unable to read stream");
     }
 }
 
-static int io_fflush(rb_io_t *);
+void rb_io_assert_readable(rb_io_t *io_struct) {
+    rb_io_check_initialized(io_struct);
+    if(CFReadStreamGetStatus(io_struct->readStream) != kCFStreamStatusOpen) {
+        rb_raise(rb_eIOError, "unable to read stream");
+    }
+}
 
-VALUE
-rb_io_get_io(VALUE io)
+bool rb_io_is_open(rb_io_t *io_struct) {
+    return ((CFReadStreamGetStatus(io_struct->readStream) == kCFStreamStatusOpen) &&
+            (CFWriteStreamGetStatus(io_struct->writeStream) == kCFStreamStatusOpen));
+}
+
+FILE* rb_io_get_write_stream_file_struct(rb_io_t *io_struct)
 {
-    return rb_convert_type(io, T_FILE, "IO", "to_io");
+    return (FILE*)CFWriteStreamCopyProperty(io_struct->writeStream, 
+        kCFStreamPropertySocketNativeHandle);
 }
 
-static VALUE
-rb_io_check_io(VALUE io)
+
+FILE* rb_io_get_read_stream_file_struct(rb_io_t *io_struct)
 {
-    return rb_check_convert_type(io, T_FILE, "IO", "to_io");
+    return (FILE*)CFReadStreamCopyProperty(io_struct->readStream, 
+        kCFStreamPropertySocketNativeHandle);
 }
 
-VALUE
-rb_io_get_write_io(VALUE io)
+int rb_io_get_write_stream_fd(rb_io_t *io_struct)
 {
-    VALUE write_io;
-    rb_io_check_initialized(RFILE(io)->fptr);
-    write_io = RFILE(io)->fptr->tied_io_for_writing;
-    if (write_io) {
-        return write_io;
-    }
-    return io;
+    return fileno(rb_io_get_write_stream_file_struct(io_struct));
 }
 
+int rb_io_get_read_stream_fd(rb_io_t *io_struct)
+{
+    return fileno(rb_io_get_read_stream_file_struct(io_struct));
+}
+
+#define FMODE_PREP (1<<16)
+#define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
+#define PREP_STDIO_NAME(f) ((f)->path)
+
+
 /*
  *  call-seq:
  *     IO.try_convert(obj) -> io or nil
@@ -292,81 +185,11 @@
  *     IO.try_convert("STDOUT")   # => nil
  */
 static VALUE
-rb_io_s_try_convert(VALUE dummy, VALUE io)
+rb_io_s_try_convert(VALUE dummy, SEL sel, VALUE io)
 {
-    return rb_io_check_io(io);
+rb_notimplement();
 }
 
-static void
-io_unread(rb_io_t *fptr)
-{
-    off_t r;
-    rb_io_check_closed(fptr);
-    if (fptr->rbuf_len == 0 || fptr->mode & FMODE_DUPLEX)
-        return;
-    /* xxx: target position may be negative if buffer is filled by ungetc */
-#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
-    if (!(fptr->mode & FMODE_BINMODE)) {
-	int len = fptr->rbuf_len;
-	while (fptr->rbuf_len-- > 0) {
-	    if (fptr->rbuf[fptr->rbuf_len] == '\n')
-		++len;
-	}
-	r = lseek(fptr->fd, -len, SEEK_CUR);
-    }
-    else
-#endif
-    r = lseek(fptr->fd, -fptr->rbuf_len, SEEK_CUR);
-    if (r < 0) {
-        if (errno == ESPIPE)
-            fptr->mode |= FMODE_DUPLEX;
-        return;
-    }
-    fptr->rbuf_off = 0;
-    fptr->rbuf_len = 0;
-    return;
-}
-
-static void
-io_ungetc(VALUE str, rb_io_t *fptr)
-{
-    int len = RSTRING_BYTELEN(str);
-
-    if (fptr->rbuf == NULL) {
-        fptr->rbuf_off = 0;
-        fptr->rbuf_len = 0;
-	if (len > 8192)
-	    fptr->rbuf_capa = len;
-	else
-	    fptr->rbuf_capa = 8192;
-        GC_WB(&fptr->rbuf, ALLOC_N(char, fptr->rbuf_capa));
-    }
-    if (fptr->rbuf_capa < len + fptr->rbuf_len) {
-	rb_raise(rb_eIOError, "ungetc failed");
-    }
-    if (fptr->rbuf_off < len) {
-        MEMMOVE(fptr->rbuf+fptr->rbuf_capa-fptr->rbuf_len,
-                fptr->rbuf+fptr->rbuf_off,
-                char, fptr->rbuf_len);
-        fptr->rbuf_off = fptr->rbuf_capa-fptr->rbuf_len;
-    }
-    fptr->rbuf_off-=len;
-    fptr->rbuf_len+=len;
-    MEMMOVE(fptr->rbuf+fptr->rbuf_off, RSTRING_BYTEPTR(str), char, len);
-}
-
-static rb_io_t *
-flush_before_seek(rb_io_t *fptr)
-{
-    io_fflush(fptr);
-    io_unread(fptr);
-    errno = 0;
-    return fptr;
-}
-
-#define io_seek(fptr, ofs, whence) lseek(flush_before_seek(fptr)->fd, ofs, whence)
-#define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
-
 #ifndef SEEK_CUR
 # define SEEK_SET 0
 # define SEEK_CUR 1
@@ -375,428 +198,41 @@
 
 #define FMODE_SYNCWRITE (FMODE_SYNC|FMODE_WRITABLE)
 
-void
-rb_io_check_readable(rb_io_t *fptr)
-{
-    rb_io_check_closed(fptr);
-    if (!(fptr->mode & FMODE_READABLE)) {
-	rb_raise(rb_eIOError, "not opened for reading");
-    }
-    if (fptr->wbuf_len) {
-        io_fflush(fptr);
-    }
-    if (fptr->tied_io_for_writing) {
-	rb_io_t *wfptr;
-	GetOpenFile(fptr->tied_io_for_writing, wfptr);
-	io_fflush(wfptr);
-    }
-    if (!fptr->enc && fptr->fd == 0) {
-	fptr->enc = rb_default_external_encoding();
-    }
-}
 
-static rb_encoding*
-io_read_encoding(rb_io_t *fptr)
-{
-    if (fptr->enc) {
-	return fptr->enc;
-    }
-    return rb_default_external_encoding();
-}
-
-static rb_encoding*
-io_input_encoding(rb_io_t *fptr)
-{
-    if (fptr->enc2) {
-	return fptr->enc2;
-    }
-    return io_read_encoding(fptr);
-}
-
-void
-rb_io_check_writable(rb_io_t *fptr)
-{
-    rb_io_check_closed(fptr);
-    if (!(fptr->mode & FMODE_WRITABLE)) {
-	rb_raise(rb_eIOError, "not opened for writing");
-    }
-    if (fptr->rbuf_len) {
-        io_unread(fptr);
-    }
-}
-
-int
-rb_read_pending(FILE *fp)
-{
-    return STDIO_READ_DATA_PENDING(fp);
-}
-
-int
-rb_io_read_pending(rb_io_t *fptr)
-{
-    return READ_DATA_PENDING(fptr);
-}
-
-void
-rb_read_check(FILE *fp)
-{
-    if (!STDIO_READ_DATA_PENDING(fp)) {
-	rb_thread_wait_fd(fileno(fp));
-    }
-}
-
-void
-rb_io_read_check(rb_io_t *fptr)
-{
-    if (!READ_DATA_PENDING(fptr)) {
-	rb_thread_wait_fd(fptr->fd);
-    }
-    return;
-}
-
-static int
-ruby_dup(int orig)
-{
-    int fd;
-
-    fd = dup(orig);
-    if (fd < 0) {
-	if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
-	    rb_gc();
-	    fd = dup(orig);
-	}
-	if (fd < 0) {
-	    rb_sys_fail(0);
-	}
-    }
-    return fd;
-}
-
 static VALUE
 io_alloc(VALUE klass, SEL sel)
 {
-    NEWOBJ(io, struct RFile);
+    struct RFile *io = ALLOC(struct RFile);
     OBJSETUP(io, klass, T_FILE);
-
-    io->fptr = 0;
-
-#if WITH_OBJC
-    void rb_objc_keep_for_exit_finalize(VALUE);
-    rb_objc_keep_for_exit_finalize((VALUE)io);
-#endif
-
+    io->fptr = ALLOC(rb_io_t);
+    MEMZERO(io->fptr, rb_io_t, 1);
     return (VALUE)io;
 }
 
-#ifndef S_ISREG
-#   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
-#endif
-
-static int
-wsplit_p(rb_io_t *fptr)
-{
-#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
-    int r;
-#endif
-
-    if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) {
-        struct stat buf;
-        if (fstat(fptr->fd, &buf) == 0 &&
-            !S_ISREG(buf.st_mode)
-#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
-            && (r = fcntl(fptr->fd, F_GETFL)) != -1 &&
-            !(r & O_NONBLOCK)
-#endif
-            ) {
-            fptr->mode |= FMODE_WSPLIT;
-        }
-        fptr->mode |= FMODE_WSPLIT_INITIALIZED;
-    }
-    return fptr->mode & FMODE_WSPLIT;
-}
-
-struct io_internal_struct {
-    int fd;
-    void *buf;
-    size_t capa;
-};
-
 static VALUE
-internal_read_func(void *ptr)
+prep_io(int fd, int mode, VALUE klass, const char *path)
 {
-    struct io_internal_struct *iis = (struct io_internal_struct*)ptr;
-    return read(iis->fd, iis->buf, iis->capa);
+    VALUE io = io_alloc(rb_cIO, 0);
+    CFReadStreamRef r;
+    CFWriteStreamRef w;
+    CFStreamCreatePairWithSocket(NULL, fd, &r, &w);
+    CFReadStreamOpen(r);
+    CFWriteStreamOpen(w);
+    // Do I need to use GC_WB?
+    RFILE(io)->fptr->readStream = r;
+    RFILE(io)->fptr->writeStream = w;
+    rb_objc_keep_for_exit_finalize((VALUE)io);
+    
+    return io;
 }
 
 static VALUE
-internal_write_func(void *ptr)
+prep_stdio(FILE *f, int mode, VALUE klass, const char *path)
 {
-    struct io_internal_struct *iis = (struct io_internal_struct*)ptr;
-    return write(iis->fd, iis->buf, iis->capa);
+    VALUE io = prep_io(fileno(f), mode|FMODE_PREP, klass, path);
+    return io;
 }
 
-static int
-rb_read_internal(int fd, void *buf, size_t count)
-{
-    struct io_internal_struct iis;
-    iis.fd = fd;
-    iis.buf = buf;
-    iis.capa = count;
-
-    return internal_read_func(&iis);
-    //return rb_thread_blocking_region(bnternal_read_func, &iis, RB_UBF_DFL, 0);
-}
-
-static int
-rb_write_internal(int fd, void *buf, size_t count)
-{
-    struct io_internal_struct iis;
-    iis.fd = fd;
-    iis.buf = buf;
-    iis.capa = count;
-
-    return internal_write_func(&iis);
-    //return rb_thread_blocking_region(internal_write_func, &iis, RB_UBF_DFL, 0);
-}
-
-static int
-io_fflush(rb_io_t *fptr)
-{
-    int r, l;
-    int wbuf_off, wbuf_len;
-
-    rb_io_check_closed(fptr);
-    if (fptr->wbuf_len == 0)
-        return 0;
-    if (!rb_thread_fd_writable(fptr->fd)) {
-        rb_io_check_closed(fptr);
-    }
-  retry:
-    if (fptr->wbuf_len == 0)
-        return 0;
-    wbuf_off = fptr->wbuf_off;
-    wbuf_len = fptr->wbuf_len;
-    l = wbuf_len;
-    if (PIPE_BUF < l &&
-        !rb_thread_critical &&
-        !rb_thread_alone() &&
-        wsplit_p(fptr)) {
-        l = PIPE_BUF;
-    }
-    r = rb_write_internal(fptr->fd, fptr->wbuf+wbuf_off, l);
-    /* xxx: Other threads may modify wbuf.
-     * A lock is required, definitely. */
-    rb_io_check_closed(fptr);
-    if (fptr->wbuf_len <= r) {
-        fptr->wbuf_off = 0;
-        fptr->wbuf_len = 0;
-        return 0;
-    }
-    if (0 <= r) {
-        fptr->wbuf_off += r;
-        fptr->wbuf_len -= r;
-        errno = EAGAIN;
-    }
-    if (rb_io_wait_writable(fptr->fd)) {
-        rb_io_check_closed(fptr);
-        goto retry;
-    }
-    return -1;
-}
-
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-wait_readable(VALUE p)
-{
-    rb_fdset_t *rfds = (rb_fdset_t *)p;
-
-    return rb_thread_select(rb_fd_max(rfds), rb_fd_ptr(rfds), NULL, NULL, NULL);
-}
-#endif
-
-int
-rb_io_wait_readable(int f)
-{
-    rb_fdset_t rfds;
-
-    switch (errno) {
-      case EINTR:
-#if defined(ERESTART)
-      case ERESTART:
-#endif
-	rb_thread_wait_fd(f);
-	return Qtrue;
-
-      case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
-      case EWOULDBLOCK:
-#endif
-	rb_fd_init(&rfds);
-	rb_fd_set(f, &rfds);
-#ifdef HAVE_RB_FD_INIT
-	rb_ensure(wait_readable, (VALUE)&rfds,
-		  (VALUE (*)(VALUE))rb_fd_term, (VALUE)&rfds);
-#else
-	rb_thread_select(f + 1, &rfds, NULL, NULL, NULL);
-#endif
-	return Qtrue;
-
-      default:
-	return Qfalse;
-    }
-}
-
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-wait_writable(VALUE p)
-{
-    rb_fdset_t *wfds = (rb_fdset_t *)p;
-
-    return rb_thread_select(rb_fd_max(wfds), NULL, rb_fd_ptr(wfds), NULL, NULL);
-}
-#endif
-
-int
-rb_io_wait_writable(int f)
-{
-    rb_fdset_t *wfds = xmalloc(sizeof(rb_fdset_t));
-
-    switch (errno) {
-      case EINTR:
-#if defined(ERESTART)
-      case ERESTART:
-#endif
-	rb_thread_fd_writable(f);
-	return Qtrue;
-
-      case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
-      case EWOULDBLOCK:
-#endif
-	rb_fd_init(wfds);
-	rb_fd_set(f, wfds);
-#ifdef HAVE_RB_FD_INIT
-	rb_ensure(wait_writable, (VALUE)wfds,
-		  (VALUE (*)(VALUE))rb_fd_term, (VALUE)wfds);
-#else
-	rb_thread_select(f + 1, NULL, wfds, NULL, NULL);
-#endif
-	return Qtrue;
-
-      default:
-	return Qfalse;
-    }
-}
-
-/* writing functions */
-static long
-io_fwrite(VALUE str, rb_io_t *fptr)
-{
-    long len, n, r, l, offset = 0;
-    void *cstr;
-
-    /*
-     * If an external encoding was specified and it differs from
-     * the strings encoding then we must transcode before writing.
-     * We must also transcode if two encodings were specified
-     */
-    if (fptr->enc) {
-	/* transcode str before output */
-	/* the methods in transcode.c are static, so call indirectly */
-	/* Can't use encode! because puts writes a frozen newline */
-	if (fptr->enc2) {
-	    str = rb_funcall(str, id_encode, 2,
-			     rb_enc_from_encoding(fptr->enc2),
-			     rb_enc_from_encoding(fptr->enc));
-	}
-	else {
-	    str = rb_funcall(str, id_encode, 1,
-			     rb_enc_from_encoding(fptr->enc));
-	}
-    }
-
-    cstr = (void *)RSTRING_PTR(str); /* generate bytestring if needed */
-    len = RSTRING_LEN(str);
-    if ((n = len) <= 0) {
-	return n;
-    }
-    if (fptr->wbuf == NULL && !(fptr->mode & FMODE_SYNC)) {
-        fptr->wbuf_off = 0;
-        fptr->wbuf_len = 0;
-        fptr->wbuf_capa = 8192;
-        GC_WB(&fptr->wbuf, ALLOC_N(char, fptr->wbuf_capa));
-    }
-    if ((fptr->mode & (FMODE_SYNC|FMODE_TTY)) ||
-        (fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len)) {
-        /* xxx: use writev to avoid double write if available */
-        if (fptr->wbuf_len && fptr->wbuf_len+len <= fptr->wbuf_capa) {
-            if (fptr->wbuf_capa < fptr->wbuf_off+fptr->wbuf_len+len) {
-                MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len);
-                fptr->wbuf_off = 0;
-            }
-            MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, cstr+offset, char, len);
-            fptr->wbuf_len += len;
-            n = 0;
-        }
-        if (io_fflush(fptr) < 0) {
-            return -1L;
-	}
-        if (n == 0) {
-            return len;
-	}
-        /* avoid context switch between "a" and "\n" in STDERR.puts "a".
-           [ruby-dev:25080] */
-	if (fptr->stdio_file != stderr && !rb_thread_fd_writable(fptr->fd)) {
-	    rb_io_check_closed(fptr);
-	}
-      retry:
-        l = n;
-        if (PIPE_BUF < l &&
-            !rb_thread_critical &&
-            !rb_thread_alone() &&
-            wsplit_p(fptr)) {
-            l = PIPE_BUF;
-        }
-	r = rb_write_internal(fptr->fd, cstr+offset, l);
-	/* xxx: other threads may modify given string. */
-        if (r == n) {
-	    return len;
-	}
-        if (0 <= r) {
-            offset += r;
-            n -= r;
-            errno = EAGAIN;
-        }
-        if (rb_io_wait_writable(fptr->fd)) {
-            rb_io_check_closed(fptr);
-	    if (offset < RSTRING_LEN(str))
-		goto retry;
-        }
-        return -1L;
-    }
-
-    if (fptr->wbuf_off) {
-        if (fptr->wbuf_len)
-            MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len);
-        fptr->wbuf_off = 0;
-    }
-    MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, cstr+offset, char, len);
-    fptr->wbuf_len += len;
-    return len;
-}
-
-long
-rb_io_fwrite(const char *ptr, long len, FILE *f)
-{
-    rb_io_t of;
-
-    of.fd = fileno(f);
-    of.stdio_file = f;
-    of.mode = FMODE_WRITABLE;
-    of.path = NULL;
-    return io_fwrite(rb_str_new(ptr, len), &of);
-}
-
 /*
  *  call-seq:
  *     ios.write(string)    => integer
@@ -815,39 +251,30 @@
  *     That was 15 bytes of data
  */
 
+
 static VALUE
-io_write(VALUE io, SEL sel, VALUE str)
+io_write(VALUE io, SEL sel, VALUE to_write)
 {
-    rb_io_t *fptr;
-    long n;
-    VALUE tmp;
-
+    rb_io_t *io_struct;
+    UInt8 *buffer;
+    CFIndex length;
+    
     rb_secure(4);
-    io = GetWriteIO(io);
-    str = rb_obj_as_string(str);
-    tmp = rb_io_check_io(io);
-    if (NIL_P(tmp)) {
-	/* port is not IO, call write method for it. */
-	return rb_funcall(io, id_write, 1, str);
+    
+    io_struct = ExtractIOStruct(io);
+    rb_io_assert_writable(io_struct);
+    // TODO: Account for the port not being IO, use funcall to call .write()
+    // instead.
+    to_write = rb_obj_as_string(to_write);
+    buffer = (UInt8*)rb_str_byteptr(to_write);
+    length = (CFIndex)rb_str_bytelen(to_write);
+    
+    if(length == 0) {
+        return INT2FIX(0);
     }
-    io = tmp;
-    if (RSTRING_LEN(str) == 0) return INT2FIX(0);
-
-    GetOpenFile(io, fptr);
-    rb_io_check_writable(fptr);
-
-    n = io_fwrite(str, fptr);
-    if (n == -1L) rb_sys_fail(fptr->path);
-
-    return LONG2FIX(n);
+    return LONG2FIX(CFWriteStreamWrite(io_struct->writeStream, buffer, length));
 }
 
-VALUE
-rb_io_write(VALUE io, VALUE str)
-{
-    return rb_funcall(io, id_write, 1, str);
-}
-
 /*
  *  call-seq:
  *     ios << obj     => ios
@@ -865,9 +292,9 @@
 
 
 VALUE
-rb_io_addstr(VALUE io, VALUE str)
+rb_io_addstr(VALUE io, SEL sel, VALUE str)
 {
-    rb_io_write(io, str);
+    io_write(io, sel, str);
     return io;
 }
 
@@ -888,25 +315,9 @@
  */
 
 VALUE
-rb_io_flush(VALUE io)
+rb_io_flush(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    if (TYPE(io) != T_FILE) {
-        return rb_funcall(io, id_flush, 0);
-    }
-
-    io = GetWriteIO(io);
-    GetOpenFile(io, fptr);
-
-    if (fptr->mode & FMODE_WRITABLE) {
-        io_fflush(fptr);
-    }
-    if (fptr->mode & FMODE_READABLE) {
-        io_unread(fptr);
-    }
-
-    return io;
+    rb_notimplement();
 }
 
 /*
@@ -923,29 +334,32 @@
  */
 
 static VALUE
-rb_io_tell(VALUE io)
+rb_io_tell(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    off_t pos;
-
-    GetOpenFile(io, fptr);
-    pos = io_tell(fptr);
-    if (pos < 0 && errno) rb_sys_fail(fptr->path);
-    return OFFT2NUM(pos);
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    rb_io_assert_readable(io_struct);
+    
+    CFNumberRef pos = CFReadStreamCopyProperty(io_struct->readStream, kCFStreamPropertyFileCurrentOffset);
+    long result = 0L;
+    CFNumberGetValue(pos, kCFNumberSInt32Type, &result);
+    
+    return LONG2FIX(result);
+    
 }
 
 static VALUE
 rb_io_seek(VALUE io, VALUE offset, int whence)
 {
-    rb_io_t *fptr;
-    off_t pos;
-
-    pos = NUM2OFFT(offset);
-    GetOpenFile(io, fptr);
-    pos = io_seek(fptr, pos, whence);
-    if (pos < 0 && errno) rb_sys_fail(fptr->path);
-
-    return INT2FIX(0);
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    rb_io_assert_readable(io_struct); 
+    rb_io_assert_writable(io_struct);
+    
+    long position = FIX2LONG(offset);
+    
+    // TODO: make this work with IO::SEEK_CUR, SEEK_END, etc.
+    CFNumberRef pos_property = CFNumberCreate(NULL, kCFNumberSInt32Type, &position);
+    CFReadStreamSetProperty(io_struct->readStream, kCFStreamPropertyFileCurrentOffset, pos_property);
+    return INT2FIX(0); // is this right?
 }
 
 /*
@@ -970,15 +384,15 @@
  */
 
 static VALUE
-rb_io_seek_m(int argc, VALUE *argv, VALUE io)
+rb_io_seek_m(VALUE io, SEL sel, int argc, VALUE *argv)
 {
     VALUE offset, ptrname;
     int whence = SEEK_SET;
-
+ 
     if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
-	whence = NUM2INT(ptrname);
+        whence = NUM2INT(ptrname);
     }
-
+ 
     return rb_io_seek(io, offset, whence);
 }
 
@@ -994,17 +408,9 @@
  */
 
 static VALUE
-rb_io_set_pos(VALUE io, VALUE offset)
+rb_io_set_pos(VALUE io, SEL sel, VALUE offset)
 {
-    rb_io_t *fptr;
-    off_t pos;
-
-    pos = NUM2OFFT(offset);
-    GetOpenFile(io, fptr);
-    pos = io_seek(fptr, pos, SEEK_SET);
-    if (pos < 0) rb_sys_fail(fptr->path);
-
-    return OFFT2NUM(pos);
+    return rb_io_seek(io, offset, SEEK_SET);
 }
 
 /*
@@ -1022,49 +428,14 @@
  */
 
 static VALUE
-rb_io_rewind(VALUE io)
+rb_io_rewind(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail(fptr->path);
-    if (io == ARGF.current_file) {
-	ARGF.gets_lineno -= fptr->lineno;
-    }
-    fptr->lineno = 0;
-
-    return INT2FIX(0);
+    // minor inefficiency here in that i'm creating and then destroying
+    // a Fixnum containing zero.
+    return rb_io_seek(io, INT2FIX(0), SEEK_SET);
 }
 
-static int
-io_fillbuf(rb_io_t *fptr)
-{
-    int r;
 
-    if (fptr->rbuf == NULL) {
-        fptr->rbuf_off = 0;
-        fptr->rbuf_len = 0;
-        fptr->rbuf_capa = 8192;
-        GC_WB(&fptr->rbuf, ALLOC_N(char, fptr->rbuf_capa));
-    }
-    if (fptr->rbuf_len == 0) {
-      retry:
-	{
-	    r = rb_read_internal(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
-	}
-        if (r < 0) {
-            if (rb_io_wait_readable(fptr->fd))
-                goto retry;
-            rb_sys_fail(fptr->path);
-        }
-        fptr->rbuf_off = 0;
-        fptr->rbuf_len = r;
-        if (r == 0)
-            return -1; /* EOF */
-    }
-    return 0;
-}
-
 /*
  *  call-seq:
  *     ios.eof     => true or false
@@ -1098,19 +469,11 @@
  */
 
 VALUE
-rb_io_eof(VALUE io)
+rb_io_eof(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-
-    if (READ_DATA_PENDING(fptr)) return Qfalse;
-    READ_CHECK(fptr);
-    if (io_fillbuf(fptr) < 0) {
-	return Qtrue;
-    }
-    return Qfalse;
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    rb_io_assert_readable(io_struct);
+    return CONDITION_TO_BOOLEAN((CFReadStreamGetStatus(io_struct->readStream) == kCFStreamStatusAtEnd));
 }
 
 /*
@@ -1127,13 +490,9 @@
  */
 
 static VALUE
-rb_io_sync(VALUE io)
+rb_io_sync(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    io = GetWriteIO(io);
-    GetOpenFile(io, fptr);
-    return (fptr->mode & FMODE_SYNC) ? Qtrue : Qfalse;
+    rb_notimplement();
 }
 
 /*
@@ -1152,19 +511,9 @@
  */
 
 static VALUE
-rb_io_set_sync(VALUE io, VALUE mode)
+rb_io_set_sync(VALUE io, SEL sel, VALUE mode)
 {
-    rb_io_t *fptr;
-
-    io = GetWriteIO(io);
-    GetOpenFile(io, fptr);
-    if (RTEST(mode)) {
-	fptr->mode |= FMODE_SYNC;
-    }
-    else {
-	fptr->mode &= ~FMODE_SYNC;
-    }
-    return mode;
+    rb_notimplement();
 }
 
 /*
@@ -1180,22 +529,9 @@
  */
 
 static VALUE
-rb_io_fsync(VALUE io)
+rb_io_fsync(VALUE io, SEL sel)
 {
-#ifdef HAVE_FSYNC
-    rb_io_t *fptr;
-
-    io = GetWriteIO(io);
-    GetOpenFile(io, fptr);
-
-    io_fflush(fptr);
-    if (fsync(fptr->fd) < 0)
-	rb_sys_fail(fptr->path);
-    return INT2FIX(0);
-#else
-    rb_notimplement();
-    return Qnil;		/* not reached */
-#endif
+     rb_notimplement();   
 }
 
 /*
@@ -1213,12 +549,8 @@
 static VALUE
 rb_io_fileno(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    int fd;
-
-    GetOpenFile(io, fptr);
-    fd = fptr->fd;
-    return INT2FIX(fd);
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    return INT2FIX(rb_io_get_read_stream_fd(io_struct));
 }
 
 
@@ -1243,14 +575,9 @@
  */
 
 static VALUE
-rb_io_pid(VALUE io)
+rb_io_pid(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    if (!fptr->pid)
-	return Qnil;
-    return INT2FIX(fptr->pid);
+    rb_notimplement();
 }
 
 
@@ -1262,19 +589,16 @@
  */
 
 static VALUE
-rb_io_inspect(VALUE obj)
+rb_io_inspect(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    const char *cname;
-    const char *st = "";
-
-    fptr = RFILE(rb_io_taint_check(obj))->fptr;
-    if (!fptr || !fptr->path) return rb_any_to_s(obj);
-    cname = rb_obj_classname(obj);
-    if (fptr->fd < 0) {
-	st = " (closed)";
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    if((io_struct == NULL) || (io_struct->path == NULL)) {
+        return rb_any_to_s(io);
     }
-    return rb_sprintf("#<%s:%s%s>", cname, fptr->path, st);
+    const char *status = (rb_io_is_open(io_struct) ? "" : " (closed)");
+    // CFStringCreateWithFormat can handle formatting CFStringRefs, so I chose it
+    // pretty much arbitrarily here.
+    return OC2RB(CFStringCreateWithFormat(NULL, NULL, CFSTR("#<%s:%@%s>"), rb_obj_classname(io), io_struct->path, status));
 }
 
 /*
@@ -1285,241 +609,13 @@
  */
 
 static VALUE
-rb_io_to_io(VALUE io)
+rb_io_to_io(VALUE io, SEL sel)
 {
     return io;
 }
 
-/* reading functions */
-static long
-read_buffered_data(char *ptr, long len, rb_io_t *fptr)
-{
-    long n;
-
-    n = READ_DATA_PENDING_COUNT(fptr);
-    if (n <= 0) return 0;
-    if (n > len) n = len;
-    MEMMOVE(ptr, fptr->rbuf+fptr->rbuf_off, char, n);
-    fptr->rbuf_off += n;
-    fptr->rbuf_len -= n;
-    return n;
-}
-
-static long
-io_fread(VALUE str, long offset, rb_io_t *fptr)
-{
-    long len = RSTRING_BYTELEN(str) - offset;
-    long n = len;
-    int c;
-    char *ptr = RSTRING_BYTEPTR(str);
-
-    while (n > 0) {
-	c = read_buffered_data(ptr+offset, n, fptr);
-	if (c > 0) {
-	    offset += c;
-	    if ((n -= c) <= 0) break;
-	}
-	rb_thread_wait_fd(fptr->fd);
-	rb_io_check_closed(fptr);
-	if (io_fillbuf(fptr) < 0) {
-	    break;
-	}
-    }
-    return len - n;
-}
-
-long
-rb_io_fread(char *ptr, long len, FILE *f)
-{
-    rb_io_t of;
-    VALUE str;
-    long n;
-
-    of.fd = fileno(f);
-    of.stdio_file = f;
-    of.mode = FMODE_READABLE;
-    str = rb_str_new(ptr, len);
-    n = io_fread(str, 0, &of);
-    MEMCPY(ptr, RSTRING_BYTEPTR(str), char, n);
-    RSTRING_SYNC(str);
-    return n;
-}
-
 #define SMALLBUF 100
 
-static long
-remain_size(rb_io_t *fptr)
-{
-    struct stat st;
-    off_t siz = READ_DATA_PENDING_COUNT(fptr);
-    off_t pos;
-
-    if (fstat(fptr->fd, &st) == 0  && S_ISREG(st.st_mode)
-#ifdef __BEOS__
-	&& (st.st_dev > 3)
-#endif
-	)
-    {
-	io_fflush(fptr);
-	pos = lseek(fptr->fd, 0, SEEK_CUR);
-	if (st.st_size >= pos && pos >= 0) {
-	    siz += st.st_size - pos + 1;
-	    if (siz > LONG_MAX) {
-		rb_raise(rb_eIOError, "file too big for single read");
-	    }
-	}
-    }
-    else {
-	siz += BUFSIZ;
-    }
-    return (long)siz;
-}
-
-static VALUE
-io_enc_str(VALUE str, rb_io_t *fptr)
-{
-    OBJ_TAINT(str);
-#if !WITH_OBJC
-    if (fptr->enc2) {
-	/* two encodings, so transcode from enc2 to enc */
-	/* the methods in transcode.c are static, so call indirectly */
-	str = rb_funcall(str, id_encode, 2,
-			 rb_enc_from_encoding(fptr->enc),
-			 rb_enc_from_encoding(fptr->enc2));
-    }
-    else {
-	/* just one encoding, so associate it with the string */
-	rb_enc_associate(str, io_read_encoding(fptr));
-    }
-#endif
-    return str;
-}
-
-static VALUE
-read_all(rb_io_t *fptr, long siz, VALUE str)
-{
-    long bytes = 0;
-    long n;
-#if !WITH_OBJC
-    long pos = 0;
-    rb_encoding *enc = io_input_encoding(fptr);
-    int cr = fptr->enc2 ? ENC_CODERANGE_BROKEN : 0;
-#endif
-
-    if (siz == 0) siz = BUFSIZ;
-    if (NIL_P(str)) {
-	str = rb_str_new(0, siz);
-    }
-    else {
-	rb_str_resize(str, siz);
-    }
-    for (;;) {
-	READ_CHECK(fptr);
-	n = io_fread(str, bytes, fptr);
-	if (n == 0 && bytes == 0) {
-	    break;
-	}
-	bytes += n;
-#if !WITH_OBJC
-	if (cr != ENC_CODERANGE_BROKEN)
-	    pos = rb_str_coderange_scan_restartable(RSTRING_BYTEPTR(str) + pos, RSTRING_BYTEPTR(str) + bytes, enc, &cr);
-#endif
-	if (bytes < siz) break;
-	siz += BUFSIZ;
-	rb_str_resize(str, siz);
-    }
-    if (bytes != siz) rb_str_resize(str, bytes);
-    str = io_enc_str(str, fptr);
-#if !WITH_OBJC
-    if (!fptr->enc2) {
-	ENC_CODERANGE_SET(str, cr);
-    }
-#endif
-    RSTRING_SYNC(str);
-    return str;
-}
-
-void
-rb_io_set_nonblock(rb_io_t *fptr)
-{
-    int flags;
-#ifdef F_GETFL
-    flags = fcntl(fptr->fd, F_GETFL);
-    if (flags == -1) {
-        rb_sys_fail(fptr->path);
-    }
-#else
-    flags = 0;
-#endif
-    if ((flags & O_NONBLOCK) == 0) {
-        flags |= O_NONBLOCK;
-        if (fcntl(fptr->fd, F_SETFL, flags) == -1) {
-            rb_sys_fail(fptr->path);
-        }
-    }
-}
-
-static VALUE
-io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
-{
-    rb_io_t *fptr;
-    VALUE length, str;
-    long n, len;
-
-    rb_scan_args(argc, argv, "11", &length, &str);
-
-    if ((len = NUM2LONG(length)) < 0) {
-	rb_raise(rb_eArgError, "negative length %ld given", len);
-    }
-
-    if (NIL_P(str)) {
-	str = rb_str_new(0, len);
-    }
-    else {
-	StringValue(str);
-	rb_str_modify(str);
-        rb_str_resize(str, len);
-    }
-    OBJ_TAINT(str);
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-
-    if (len == 0)
-	return str;
-
-    if (!nonblock)
-        READ_CHECK(fptr);
-    if (RSTRING_BYTELEN(str) != len) {
-      modified:
-	rb_raise(rb_eRuntimeError, "buffer string modified");
-    }
-    n = read_buffered_data(RSTRING_BYTEPTR(str), len, fptr);
-    if (n <= 0) {
-      again:
-	if (RSTRING_BYTELEN(str) != len) goto modified;
-        if (nonblock) {
-            rb_io_set_nonblock(fptr);
-	    n = rb_read_internal(fptr->fd, RSTRING_BYTEPTR(str), len);
-        }
-        else {
-            n = rb_read_internal(fptr->fd, RSTRING_BYTEPTR(str), len);
-	}
-        if (n < 0) {
-            if (!nonblock && rb_io_wait_readable(fptr->fd))
-                goto again;
-            rb_sys_fail(fptr->path);
-        }
-    }
-    rb_str_resize(str, n);
-    RSTRING_SYNC(str);
-
-    if (n == 0)
-        return Qnil;
-    else
-        return str;
-}
-
 /*
  *  call-seq:
  *     ios.readpartial(maxlen)              => string
@@ -1578,15 +674,29 @@
  */
 
 static VALUE
-io_readpartial(int argc, VALUE *argv, VALUE io)
+io_readpartial(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE ret;
-
-    ret = io_getpartial(argc, argv, io, 0);
-    if (NIL_P(ret))
-        rb_eof_error();
-    else
-        return ret;
+    VALUE len, outbuf;
+    rb_io_t *io_struct;
+    // NONE OF THIS RDOC IS ACCURATE REGARDING BLOCKING AND WHATNOT.
+    // FOR THE LOVE OF GOD, FIX ME.
+    if((argc == 0) || (argc > 2)) {
+        rb_raise(rb_eArgError, "wrong number of parameters"); // FIXME: be more informative.
+    }
+    rb_scan_args(argc, argv, "11", &len, &outbuf);
+    io_struct = ExtractIOStruct(io);
+    // this is wrong, i think.
+    // i want to dereference outbuf and make it into a bytestring...
+    if(NIL_P(outbuf)) {
+        outbuf = rb_bytestring_new();
+    } else {
+        outbuf = rb_coerce_to_bytestring(outbuf);
+    }
+    CFMutableDataRef data = rb_bytestring_wrapped_data(outbuf);
+    // we need to tell the data how much we read
+    CFDataIncreaseLength(data, FIX2LONG(len)); // sentinel byte?
+    CFReadStreamRead(io_struct->readStream, CFDataGetMutableBytePtr(data), FIX2LONG(len));
+    return outbuf; 
 }
 
 /*
@@ -1614,15 +724,9 @@
  */
 
 static VALUE
-io_read_nonblock(int argc, VALUE *argv, VALUE io)
+io_read_nonblock(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE ret;
-
-    ret = io_getpartial(argc, argv, io, 1);
-    if (NIL_P(ret))
-        rb_eof_error();
-    else
-        return ret;
+    rb_notimplement();
 }
 
 /*
@@ -1643,27 +747,9 @@
  */
 
 static VALUE
-rb_io_write_nonblock(VALUE io, VALUE str)
+rb_io_write_nonblock(VALUE io, SEL sel, VALUE str)
 {
-    rb_io_t *fptr;
-    long n;
-
-    rb_secure(4);
-    if (TYPE(str) != T_STRING)
-	str = rb_obj_as_string(str);
-
-    io = GetWriteIO(io);
-    GetOpenFile(io, fptr);
-    rb_io_check_writable(fptr);
-
-    io_fflush(fptr);
-
-    rb_io_set_nonblock(fptr);
-    n = write(fptr->fd, RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str));
-
-    if (n == -1) rb_sys_fail(fptr->path);
-
-    return LONG2FIX(n);
+    rb_notimplement();
 }
 
 /*
@@ -1689,395 +775,31 @@
  */
 
 static VALUE
-io_read(int argc, VALUE *argv, VALUE io)
+io_read(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    rb_io_t *fptr;
-    long n, len;
-    VALUE length, str;
-
-    rb_scan_args(argc, argv, "02", &length, &str);
-
-    if (NIL_P(length)) {
-	if (!NIL_P(str)) StringValue(str);
-	GetOpenFile(io, fptr);
-	rb_io_check_readable(fptr);
-	return read_all(fptr, remain_size(fptr), str);
+    VALUE len, outbuf;
+    rb_io_t *io_struct;
+    // NONE OF THIS RDOC IS ACCURATE REGARDING BLOCKING AND WHATNOT.
+    // FOR THE LOVE OF GOD, FIX ME.
+    if((argc == 0) || (argc > 2)) {
+        rb_raise(rb_eArgError, "wrong number of parameters"); // FIXME: be more informative.
     }
-    len = NUM2LONG(length);
-    if (len < 0) {
-	rb_raise(rb_eArgError, "negative length %ld given", len);
+    rb_scan_args(argc, argv, "11", &len, &outbuf);
+    io_struct = ExtractIOStruct(io);
+    // this is wrong, i think.
+    // i want to dereference outbuf and make it into a bytestring...
+    if(NIL_P(outbuf)) {
+        outbuf = rb_bytestring_new();
+    } else {
+        outbuf = rb_coerce_to_bytestring(outbuf);
     }
-
-    if (NIL_P(str)) {
-	str = rb_str_new(0, len);
-    }
-    else {
-	StringValue(str);
-	rb_str_modify(str);
-	rb_str_resize(str,len);
-    }
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-    if (len == 0) return str;
-
-    READ_CHECK(fptr);
-    if (RSTRING_BYTELEN(str) != len) {
-	rb_raise(rb_eRuntimeError, "buffer string modified");
-    }
-    n = io_fread(str, 0, fptr);
-    if (n == 0) {
-	if (fptr->fd < 0) return Qnil;
-        rb_str_resize(str, 0);
-        return Qnil;
-    }
-    rb_str_resize(str, n);
-    RSTRING_SYNC(str);
-
-    return str;
+    CFMutableDataRef data = rb_bytestring_wrapped_data(outbuf);
+    // we need to tell the data how much we read
+    CFDataIncreaseLength(data, FIX2LONG(len)); // sentinel byte?
+    CFReadStreamRead(io_struct->readStream, CFDataGetMutableBytePtr(data), FIX2LONG(len));
+    return outbuf;
 }
 
-static void
-rscheck(const char *rsptr, long rslen, VALUE rs)
-{
-    if (!rs) return;
-    if (RSTRING_BYTEPTR(rs) != rsptr && RSTRING_BYTELEN(rs) != rslen)
-	rb_raise(rb_eRuntimeError, "rs modified");
-}
-
-static int
-appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp)
-{
-    VALUE str = *strp;
-    int c = EOF;
-    long limit = *lp;
-
-    do {
-	long pending = READ_DATA_PENDING_COUNT(fptr);
-	if (pending > 0) {
-	    const char *p = READ_DATA_PENDING_PTR(fptr);
-	    const char *e;
-	    long last = 0, len = (c != EOF);
-#if !WITH_OBJC
-	    rb_encoding *enc = io_read_encoding(fptr);
-#endif
-
-	    if (limit > 0 && pending > limit) pending = limit;
-	    e = memchr(p, delim, pending);
-	    if (e) pending = e - p + 1;
-	    len += pending;
-	    if (!NIL_P(str)) {
-		last = RSTRING_BYTELEN(str);
-		rb_str_resize(str, last + len);
-	    }
-	    else {
-		*strp = str = rb_str_buf_new(len);
-		rb_str_set_len(str, len);
-	    }
-	    if (c != EOF) {
-		RSTRING_BYTEPTR(str)[last++] = c;
-	    }
-	    if (limit > 0 && limit == pending) {
-#if !WITH_OBJC
-		char *p = fptr->rbuf+fptr->rbuf_off;
-		char *pp = p + limit;
-		char *pl = rb_enc_left_char_head(p, pp, enc);
-
-		if (pl < pp) {
-		    int diff = pp - pl;
-		    pending -= diff;
-		    limit = pending;
-		    rb_str_set_len(str, RSTRING_BYTELEN(str)-diff);
-		}
-#endif
-	    }
-	    read_buffered_data(RSTRING_BYTEPTR(str) + last, pending, fptr); /* must not fail */
-	    limit -= pending;
-	    *lp = limit;
-	    if (limit == 0) return RSTRING_BYTEPTR(str)[RSTRING_BYTELEN(str)-1];
-	    if (e) return delim;
-	}
-	else if (c != EOF) {
-	    if (!NIL_P(str)) {
-		char ch = c;
-		rb_str_buf_cat(str, &ch, 1);
-	    }
-	    else {
-		*strp = str = rb_str_buf_new(1);
-		rb_str_resize(str, 1);
-		RSTRING_BYTEPTR(str)[0] = c;
-	    }
-	}
-	rb_thread_wait_fd(fptr->fd);
-	rb_io_check_closed(fptr);
-	if (io_fillbuf(fptr) < 0) {
-	    *lp = limit;
-	    return c;
-	}
-    } while (c != delim);
-
-    {
-	char ch = c;
-	if (!NIL_P(str)) {
-	    rb_str_cat(str, &ch, 1);
-	}
-	else {
-#if WITH_OBJC
-	    char buf[2];
-	    buf[0] = ch;
-	    buf[1] = '\0';
-	    *strp = str = rb_str_new(buf, 1);
-#else
-	    *strp = str = rb_str_new(&ch, 1);
-#endif
-	}
-    }
-
-    return c;
-}
-
-static inline int
-swallow(rb_io_t *fptr, int term)
-{
-    do {
-	long cnt;
-	while ((cnt = READ_DATA_PENDING_COUNT(fptr)) > 0) {
-	    char buf[1024];
-	    const char *p = READ_DATA_PENDING_PTR(fptr);
-	    int i;
-	    if (cnt > sizeof buf) cnt = sizeof buf;
-	    if (*p != term) return Qtrue;
-	    i = cnt;
-	    while (--i && *++p == term);
-	    if (!read_buffered_data(buf, cnt - i, fptr)) /* must not fail */
-		rb_sys_fail(fptr->path);
-	}
-	rb_thread_wait_fd(fptr->fd);
-	rb_io_check_closed(fptr);
-    } while (io_fillbuf(fptr) == 0);
-    return Qfalse;
-}
-
-static VALUE
-rb_io_getline_fast(rb_io_t *fptr)
-{
-    VALUE str = Qnil;
-    int len = 0;
-#if !WITH_OBJC
-    long pos = 0;
-    rb_encoding *enc = io_input_encoding(fptr);
-    int cr = fptr->enc2 ? ENC_CODERANGE_BROKEN : 0;
-#endif
-
-    for (;;) {
-	long pending = READ_DATA_PENDING_COUNT(fptr);
-
-	if (pending > 0) {
-	    const char *p = READ_DATA_PENDING_PTR(fptr);
-	    const char *e;
-
-	    e = memchr(p, '\n', pending);
-	    if (e) {
-                pending = e - p + 1;
-	    }
-	    if (NIL_P(str)) {
-		str = rb_str_new(p, pending);
-		fptr->rbuf_off += pending;
-		fptr->rbuf_len -= pending;
-	    }
-	    else {
-		rb_str_resize(str, len + pending);
-		read_buffered_data(RSTRING_BYTEPTR(str)+len, pending, fptr);
-	    }
-	    len += pending;
-#if !WITH_OBJC
-	    if (cr != ENC_CODERANGE_BROKEN)
-		pos = rb_str_coderange_scan_restartable(RSTRING_BYTEPTR(str) + pos, RSTRING_BYTEPTR(str) + len, enc, &cr);
-#endif
-	    if (e) break;
-	}
-	rb_thread_wait_fd(fptr->fd);
-	rb_io_check_closed(fptr);
-	if (io_fillbuf(fptr) < 0) {
-	    if (NIL_P(str)) return Qnil;
-	    break;
-	}
-    }
-
-    RSTRING_SYNC(str);
-    str = io_enc_str(str, fptr);
-#if !WITH_OBJC
-    if (!fptr->enc2) ENC_CODERANGE_SET(str, cr);
-#endif
-    fptr->lineno++;
-    ARGF.lineno = INT2FIX(fptr->lineno);
-    return str;
-}
-
-static void
-prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io)
-{
-    VALUE lim, rs;
-#if !WITH_OBJC
-    rb_io_t *fptr;
-#endif
-
-    if (argc == 0) {
-	rs = rb_rs;
-	lim = Qnil;
-    }
-    else {
-	rb_scan_args(argc, argv, "11", &rs, &lim);
-	if (NIL_P(lim) && !NIL_P(rs) && TYPE(rs) != T_STRING) {
-	    VALUE tmp = rb_check_string_type(rs);
-
-	    if (NIL_P(tmp)) {
-		lim = rs;
-		rs = rb_rs;
-	    }
-	    else {
-		rs = tmp;
-	    }
-	}
-    }
-    if (!NIL_P(rs)) {
-#if !WITH_OBJC
-	rb_encoding *enc_rs, *enc_io;
-
-	GetOpenFile(io, fptr);
-	enc_rs = rb_enc_get(rs);
-	enc_io = io_read_encoding(fptr);
-	if (enc_io != enc_rs &&
-	    (rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
-	     !rb_enc_asciicompat(enc_io))) {
-            if (rs == rb_default_rs) {
-                rs = rb_enc_str_new(0, 0, enc_io);
-                rb_str_buf_cat_ascii(rs, "\n");
-            }
-            else {
-                rb_raise(rb_eArgError, "encoding mismatch: %s IO with %s RS",
-                         rb_enc_name(enc_io),
-                         rb_enc_name(enc_rs));
-            }
-	}
-	if (fptr->enc2) {
-            VALUE rs2;
-	    rs2 = rb_funcall(rs, id_encode, 2,
-			    rb_enc_from_encoding(fptr->enc2),
-			    rb_enc_from_encoding(fptr->enc));
-            if (!RTEST(rb_str_equal(rs, rs2))) {
-                rs = rs2;
-            }
-	}
-#endif
-    }
-    *rsp = rs;
-    *limit = NIL_P(lim) ? -1L : NUM2LONG(lim);
-}
-
-static VALUE
-rb_io_getline_1(VALUE rs, long limit, VALUE io)
-{
-    VALUE str = Qnil;
-    rb_io_t *fptr;
-    int nolimit = 0;
-    rb_encoding *enc;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-    enc = io_input_encoding(fptr);
-    if (NIL_P(rs)) {
-	str = read_all(fptr, 0, Qnil);
-	if (RSTRING_BYTELEN(str) == 0) return Qnil;
-    }
-    else if (limit == 0) {
-	return rb_enc_str_new(0, 0, io_read_encoding(fptr));
-    }
-    else if (rs == rb_default_rs && limit < 0
-#if WITH_OBJC
-	    ) {
-#else	
-	     && rb_enc_asciicompat(io_read_encoding(fptr))) {
-#endif
-	return rb_io_getline_fast(fptr);
-    }
-    else {
-	int c, newline;
-	const char *rsptr;
-	long rslen;
-	int rspara = 0;
-
-	rslen = RSTRING_BYTELEN(rs);
-	if (rslen == 0) {
-	    rsptr = "\n\n";
-	    rslen = 2;
-	    rspara = 1;
-	    swallow(fptr, '\n');
-	    rs = 0;
-	}
-	else {
-	    rsptr = RSTRING_BYTEPTR(rs);
-	}
-	newline = rsptr[rslen - 1];
-
-	while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
-	    if (c == newline) {
-		const char *s, *p;
-
-		if (RSTRING_BYTELEN(str) < rslen) continue;
-		s = RSTRING_BYTEPTR(str);
-		p = s +  RSTRING_BYTELEN(str) - rslen;
-#if !WITH_OBJC
-		pp = rb_enc_left_char_head(s, p, enc);
-		if (pp != p) continue;
-#endif
-		if (!rspara) rscheck(rsptr, rslen, rs);
-		if (memcmp(p, rsptr, rslen) == 0) break;
-	    }
-	    if (limit == 0) {
-		nolimit = 1;
-		break;
-	    }
-	}
-
-	if (rspara) {
-	    if (c != EOF) {
-		swallow(fptr, '\n');
-	    }
-	}
-	if (!NIL_P(str)) str = io_enc_str(str, fptr);
-    }
-
-    if (!NIL_P(str)) {
-	if (!nolimit) {
-	    fptr->lineno++;
-	    ARGF.lineno = INT2FIX(fptr->lineno);
-	}
-    }
-
-    return str;
-}
-
-static VALUE
-rb_io_getline(int argc, VALUE *argv, VALUE io)
-{
-    VALUE rs;
-    long limit;
-
-    prepare_getline_args(argc, argv, &rs, &limit, io);
-    return rb_io_getline_1(rs, limit, io);
-}
-
-VALUE
-rb_io_gets(VALUE io)
-{
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-    return rb_io_getline_fast(fptr);
-}
-
 /*
  *  call-seq:
  *     ios.gets(sep=$/)     => string or nil
@@ -2102,12 +824,7 @@
 static VALUE
 rb_io_gets_m(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE str;
-
-    str = rb_io_getline(argc, argv, io);
-    rb_lastline_set(str);
-
-    return str;
+    rb_notimplement();
 }
 
 /*
@@ -2130,13 +847,9 @@
  */
 
 static VALUE
-rb_io_lineno(VALUE io)
+rb_io_lineno(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-    return INT2NUM(fptr->lineno);
+rb_notimplement();
 }
 
 /*
@@ -2157,14 +870,9 @@
  */
 
 static VALUE
-rb_io_set_lineno(VALUE io, VALUE lineno)
+rb_io_set_lineno(VALUE io, SEL sel, VALUE lineno)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-    fptr->lineno = NUM2INT(lineno);
-    return lineno;
+rb_notimplement();
 }
 
 /*
@@ -2178,14 +886,9 @@
  */
 
 static VALUE
-rb_io_readline(int argc, VALUE *argv, VALUE io)
+rb_io_readline(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE line = rb_io_gets_m(io, 0, argc, argv);
-
-    if (NIL_P(line)) {
-	rb_eof_error();
-    }
-    return line;
+rb_notimplement();
 }
 
 /*
@@ -2209,15 +912,7 @@
 static VALUE
 rb_io_readlines(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE line, ary, rs;
-    long limit;
-
-    prepare_getline_args(argc, argv, &rs, &limit, io);
-    ary = rb_ary_new();
-    while (!NIL_P(line = rb_io_getline_1(rs, limit, io))) {
-	rb_ary_push(ary, line);
-    }
-    return ary;
+rb_notimplement();
 }
 
 /*
@@ -2245,18 +940,9 @@
  */
 
 static VALUE
-rb_io_each_line(int argc, VALUE *argv, VALUE io)
+rb_io_each_line(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE str, rs;
-    long limit;
-
-    RETURN_ENUMERATOR(io, argc, argv);
-    prepare_getline_args(argc, argv, &rs, &limit, io);
-    while (!NIL_P(str = rb_io_getline_1(rs, limit, io))) {
-	rb_yield(str);
-	RETURN_IF_BROKEN();
-    }
-    return io;
+rb_notimplement();
 }
 
 /*
@@ -2274,99 +960,11 @@
  */
 
 static VALUE
-rb_io_each_byte(VALUE io)
+rb_io_each_byte(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    char *p, *e;
-
-    RETURN_ENUMERATOR(io, 0, 0);
-    GetOpenFile(io, fptr);
-
-    for (;;) {
-	p = fptr->rbuf+fptr->rbuf_off;
-	e = p + fptr->rbuf_len;
-	while (p < e) {
-	    fptr->rbuf_off++;
-	    fptr->rbuf_len--;
-	    rb_yield(INT2FIX(*p & 0xff));
-	    RETURN_IF_BROKEN();
-	    p++;
-	    errno = 0;
-	}
-	rb_io_check_readable(fptr);
-	READ_CHECK(fptr);
-	if (io_fillbuf(fptr) < 0) {
-	    break;
-	}
-    }
-    return io;
+    rb_notimplement();
 }
 
-static VALUE
-io_getc(rb_io_t *fptr, rb_encoding *enc)
-{
-#if !WITH_OBJC
-    int r, n, cr = 0;
-#endif
-    VALUE str;
-
-    if (io_fillbuf(fptr) < 0) {
-	return Qnil;
-    }
-#if WITH_OBJC
-    str = rb_str_new(fptr->rbuf+fptr->rbuf_off, 1);
-    fptr->rbuf_off += 1;
-    fptr->rbuf_len -= 1;
-#else
-    if (rb_enc_asciicompat(enc) && ISASCII(fptr->rbuf[fptr->rbuf_off])) {
-	str = rb_str_new(fptr->rbuf+fptr->rbuf_off, 1);
-	fptr->rbuf_off += 1;
-	fptr->rbuf_len -= 1;
-	cr = ENC_CODERANGE_7BIT;
-    }
-    else {
-	r = rb_enc_precise_mbclen(fptr->rbuf+fptr->rbuf_off, fptr->rbuf+fptr->rbuf_off+fptr->rbuf_len, enc);
-	if (MBCLEN_CHARFOUND_P(r) &&
-	    (n = MBCLEN_CHARFOUND_LEN(r)) <= fptr->rbuf_len) {
-	    str = rb_str_new(fptr->rbuf+fptr->rbuf_off, n);
-	    fptr->rbuf_off += n;
-	    fptr->rbuf_len -= n;
-	    cr = ENC_CODERANGE_VALID;
-	}
-	else if (MBCLEN_NEEDMORE_P(r)) {
-	    str = rb_str_new(fptr->rbuf+fptr->rbuf_off, fptr->rbuf_len);
-	    fptr->rbuf_len = 0;
-	  getc_needmore:
-	    if (io_fillbuf(fptr) != -1) {
-		rb_str_cat(str, fptr->rbuf+fptr->rbuf_off, 1);
-		fptr->rbuf_off++;
-		fptr->rbuf_len--;
-		r = rb_enc_precise_mbclen(RSTRING_BYTEPTR(str), RSTRING_BYTEPTR(str)+RSTRING_BYTELEN(str), enc);
-		if (MBCLEN_NEEDMORE_P(r)) {
-		    goto getc_needmore;
-		}
-		else if (MBCLEN_CHARFOUND_P(r)) {
-		    cr = ENC_CODERANGE_VALID;
-		}
-	    }
-	}
-	else {
-	    str = rb_str_new(fptr->rbuf+fptr->rbuf_off, 1);
-	    fptr->rbuf_off++;
-	    fptr->rbuf_len--;
-	}
-    }
-    if (!cr) cr = ENC_CODERANGE_BROKEN;
-#endif
-    str = io_enc_str(str, fptr);
-#if !WITH_OBJC
-    if (!fptr->enc2) {
-	ENC_CODERANGE_SET(str, cr);
-    }
-#endif
-    return str;
-}
-
 /*
  *  call-seq:
  *     ios.each_char {|c| block }  => ios
@@ -2380,23 +978,9 @@
  */
 
 static VALUE
-rb_io_each_char(VALUE io)
+rb_io_each_char(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    rb_encoding *enc;
-    VALUE c;
-
-    RETURN_ENUMERATOR(io, 0, 0);
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-
-    enc = io_input_encoding(fptr);
-    READ_CHECK(fptr);
-    while (!NIL_P(c = io_getc(fptr, enc))) {
-        rb_yield(c);
-	RETURN_IF_BROKEN();
-    }
-    return io;
+rb_notimplement();
 }
 
 
@@ -2418,9 +1002,9 @@
  */
 
 static VALUE
-rb_io_lines(int argc, VALUE *argv, VALUE io)
+rb_io_lines(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
+rb_notimplement();
 }
 
 /*
@@ -2438,9 +1022,9 @@
  */
 
 static VALUE
-rb_io_bytes(VALUE io)
+rb_io_bytes(VALUE io, SEL sel)
 {
-    return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
+rb_notimplement();
 }
 
 /*
@@ -2458,9 +1042,9 @@
  */
 
 static VALUE
-rb_io_chars(VALUE io)
+rb_io_chars(VALUE io, SEL sel)
 {
-    return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0);
+rb_notimplement();
 }
 
 /*
@@ -2476,31 +1060,11 @@
  */
 
 static VALUE
-rb_io_getc(VALUE io)
+rb_io_getc(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    rb_encoding *enc;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-
-    enc = io_input_encoding(fptr);
-    READ_CHECK(fptr);
-    return io_getc(fptr, enc);
+    rb_notimplement();
 }
-int
-rb_getc(FILE *f)
-{
-    int c;
 
-    rb_read_check(f);
-    TRAP_BEG;
-    c = getc(f);
-    TRAP_END;
-
-    return c;
-}
-
 /*
  *  call-seq:
  *     ios.readchar   => string
@@ -2514,14 +1078,9 @@
  */
 
 static VALUE
-rb_io_readchar(VALUE io)
+rb_io_readchar(VALUE io, SEL sel)
 {
-    VALUE c = rb_io_getc(io);
-
-    if (NIL_P(c)) {
-	rb_eof_error();
-    }
-    return c;
+    rb_notimplement();
 }
 
 /*
@@ -2537,28 +1096,9 @@
  */
 
 VALUE
-rb_io_getbyte(VALUE io)
+rb_io_getbyte(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    int c;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-    READ_CHECK(fptr);
-    if (fptr->fd == 0 && (fptr->mode & FMODE_TTY) && TYPE(rb_stdout) == T_FILE) {
-        rb_io_t *ofp;
-        GetOpenFile(rb_stdout, ofp);
-        if (ofp->mode & FMODE_TTY) {
-            rb_io_flush(rb_stdout);
-        }
-    }
-    if (io_fillbuf(fptr) < 0) {
-	return Qnil;
-    }
-    fptr->rbuf_off++;
-    fptr->rbuf_len--;
-    c = (unsigned char)fptr->rbuf[fptr->rbuf_off-1];
-    return INT2FIX(c & 0xff);
+    rb_notimplement();
 }
 
 /*
@@ -2570,14 +1110,9 @@
  */
 
 static VALUE
-rb_io_readbyte(VALUE io)
+rb_io_readbyte(VALUE io, SEL sel)
 {
-    VALUE c = rb_io_getbyte(io);
-
-    if (NIL_P(c)) {
-	rb_eof_error();
-    }
-    return c;
+    rb_notimplement();
 }
 
 /*
@@ -2597,32 +1132,9 @@
  */
 
 VALUE
-rb_io_ungetc(VALUE io, VALUE c)
+rb_io_ungetc(VALUE io, SEL sel, VALUE c)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-    if (NIL_P(c)) return Qnil;
-    if (FIXNUM_P(c)) {
-	int cc = FIX2INT(c);
-#if WITH_OBJC
-	char buf[2];
-	buf[0] = cc;
-	buf[1] = '\0';
-	c = rb_str_new(buf, 1);
-#else
-	rb_encoding *enc = io_read_encoding(fptr);
-	char buf[16];
-
-	c = rb_str_new(buf, rb_enc_mbcput(cc, buf, enc));
-#endif
-    }
-    else {
-	SafeStringValue(c);
-    }
-    io_ungetc(c, fptr);
-    return Qnil;
+    rb_notimplement();
 }
 
 /*
@@ -2638,14 +1150,9 @@
  */
 
 static VALUE
-rb_io_isatty(VALUE io)
+rb_io_isatty(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    if (isatty(fptr->fd) == 0)
-	return Qfalse;
-    return Qtrue;
+    rb_notimplement();
 }
 
 /*
@@ -2663,32 +1170,9 @@
  */
 
 static VALUE
-rb_io_close_on_exec_p(VALUE io)
+rb_io_close_on_exec_p(VALUE io, SEL sel)
 {
-#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
-    rb_io_t *fptr;
-    VALUE write_io;
-    int fd, ret;
-
-    write_io = GetWriteIO(io);
-    if (io != write_io) {
-        GetOpenFile(write_io, fptr);
-        if (fptr && 0 <= (fd = fptr->fd)) {
-            if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
-            if (!(ret & FD_CLOEXEC)) return Qfalse;
-        }
-    }
-
-    GetOpenFile(io, fptr);
-    if (fptr && 0 <= (fd = fptr->fd)) {
-        if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
-        if (!(ret & FD_CLOEXEC)) return Qfalse;
-    }
-    return Qtrue;
-#else
-    rb_notimplement();
-    return Qnil;		/* not reached */
-#endif
+rb_notimplement();
 }
 
 /*
@@ -2704,179 +1188,20 @@
  */
 
 static VALUE
-rb_io_set_close_on_exec(VALUE io, VALUE arg)
+rb_io_set_close_on_exec(VALUE io, SEL sel, VALUE arg)
 {
-#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
-    int flag = RTEST(arg) ? FD_CLOEXEC : 0;
-    rb_io_t *fptr;
-    VALUE write_io;
-    int fd, ret;
-
-    write_io = GetWriteIO(io);
-    if (io != write_io) {
-        GetOpenFile(write_io, fptr);
-        if (fptr && 0 <= (fd = fptr->fd)) {
-            if ((ret = fcntl(fptr->fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
-            if ((ret & FD_CLOEXEC) != flag) {
-                ret = (ret & ~FD_CLOEXEC) | flag;
-                ret = fcntl(fd, F_SETFD, ret);
-                if (ret == -1) rb_sys_fail(fptr->path);
-            }
-        }
-
-    }
-
-    GetOpenFile(io, fptr);
-    if (fptr && 0 <= (fd = fptr->fd)) {
-        if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
-        if ((ret & FD_CLOEXEC) != flag) {
-            ret = (ret & ~FD_CLOEXEC) | flag;
-            ret = fcntl(fd, F_SETFD, ret);
-            if (ret == -1) rb_sys_fail(fptr->path);
-        }
-    }
-#else
-    rb_notimplement();
-#endif
-    return Qnil;
+rb_notimplement();
 }
 
-#define FMODE_PREP (1<<16)
-#define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
-#define PREP_STDIO_NAME(f) ((f)->path)
-
-static void
-fptr_finalize(rb_io_t *fptr, int noraise)
-{
-    if (fptr->wbuf_len) {
-        io_fflush(fptr);
-    }
-    if (IS_PREP_STDIO(fptr) ||
-        fptr->fd <= 2) {
-	return;
-    }
-    if (fptr->stdio_file) {
-        if (fclose(fptr->stdio_file) < 0 && !noraise) {
-            /* fptr->stdio_file is deallocated anyway */
-            fptr->stdio_file = 0;
-            fptr->fd = -1;
-            rb_sys_fail(fptr->path);
-        }
-    }
-    else if (0 <= fptr->fd) {
-        if (close(fptr->fd) < 0 && !noraise) {
-            /* fptr->fd is still not closed */
-            rb_sys_fail(fptr->path);
-        }
-    }
-    fptr->fd = -1;
-    fptr->stdio_file = 0;
-    fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
-}
-
-static void
-rb_io_fptr_cleanup(rb_io_t *fptr, int noraise)
-{
-    if (fptr->finalize) {
-	(*fptr->finalize)(fptr, noraise);
-    }
-    else {
-	fptr_finalize(fptr, noraise);
-    }
-}
-
-int
-rb_io_fptr_finalize(rb_io_t *fptr)
-{
-    if (!fptr) return 0;
-    if (fptr->refcnt <= 0 || --fptr->refcnt) return 0;
-    if (fptr->path) {
-	free(fptr->path);
-	fptr->path = 0;
-    }
-    if (0 <= fptr->fd)
-	rb_io_fptr_cleanup(fptr, Qtrue);
-    if (fptr->rbuf) {
-        xfree(fptr->rbuf);
-        fptr->rbuf = 0;
-    }
-    if (fptr->wbuf) {
-        xfree(fptr->wbuf);
-        fptr->wbuf = 0;
-    }
-    xfree(fptr);
-    return 1;
-}
-
-VALUE
-rb_io_close(VALUE io)
-{
-    rb_io_t *fptr;
-    int fd;
-    VALUE write_io;
-    rb_io_t *write_fptr;
-
-    write_io = GetWriteIO(io);
-    if (io != write_io) {
-        write_fptr = RFILE(write_io)->fptr;
-        if (write_fptr && 0 <= write_fptr->fd) {
-            rb_io_fptr_cleanup(write_fptr, Qtrue);
-        }
-    }
-
-    fptr = RFILE(io)->fptr;
-    if (!fptr) return Qnil;
-    if (fptr->fd < 0) return Qnil;
-
-    fd = fptr->fd;
-    rb_io_fptr_cleanup(fptr, Qfalse);
-    //rb_thread_fd_close(fd);
-
-    if (fptr->pid) {
-	rb_syswait(fptr->pid);
-	fptr->pid = 0;
-    }
-
-    return Qnil;
-}
-
-/*
- *  call-seq:
- *     ios.close   => nil
- *
- *  Closes <em>ios</em> and flushes any pending writes to the operating
- *  system. The stream is unavailable for any further data operations;
- *  an <code>IOError</code> is raised if such an attempt is made. I/O
- *  streams are automatically closed when they are claimed by the
- *  garbage collector.
- *
- *  If <em>ios</em> is opened by <code>IO.popen</code>,
- *  <code>close</code> sets <code>$?</code>.
- */
-
 static VALUE
-rb_io_close_m(VALUE io)
+rb_io_close_m(VALUE io, SEL sel)
 {
-    if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
-	rb_raise(rb_eSecurityError, "Insecure: can't close");
-    }
-    rb_io_check_closed(RFILE(io)->fptr);
-    rb_io_close(io);
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    CFReadStreamClose(io_struct->readStream);
+    CFWriteStreamClose(io_struct->writeStream);
     return Qnil;
 }
 
-static VALUE
-io_call_close(VALUE io)
-{
-    return rb_funcall(io, rb_intern("close"), 0, 0);
-}
-
-static VALUE
-io_close(VALUE io)
-{
-    return rb_rescue(io_call_close, io, 0, 0);
-}
-
 /*
  *  call-seq:
  *     ios.closed?    => true or false
@@ -2897,23 +1222,9 @@
 
 
 static VALUE
-rb_io_closed(VALUE io)
+rb_io_closed(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    VALUE write_io;
-    rb_io_t *write_fptr;
-
-    write_io = GetWriteIO(io);
-    if (io != write_io) {
-        write_fptr = RFILE(write_io)->fptr;
-        if (write_fptr && 0 <= write_fptr->fd) {
-            return Qfalse;
-        }
-    }
-
-    fptr = RFILE(io)->fptr;
-    rb_io_check_initialized(fptr);
-    return 0 <= fptr->fd ? Qfalse : Qtrue;
+    rb_notimplement();
 }
 
 /*
@@ -2935,44 +1246,9 @@
  */
 
 static VALUE
-rb_io_close_read(VALUE io)
+rb_io_close_read(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    VALUE write_io;
-
-    if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
-	rb_raise(rb_eSecurityError, "Insecure: can't close");
-    }
-    GetOpenFile(io, fptr);
-    if (is_socket(fptr->fd, fptr->path)) {
-#ifndef SHUT_RD
-# define SHUT_RD 0
-#endif
-        if (shutdown(fptr->fd, SHUT_RD) < 0)
-            rb_sys_fail(fptr->path);
-        fptr->mode &= ~FMODE_READABLE;
-        if (!(fptr->mode & FMODE_WRITABLE))
-            return rb_io_close(io);
-        return Qnil;
-    }
-
-    write_io = GetWriteIO(io);
-    if (io != write_io) {
-	rb_io_t *wfptr;
-        fptr_finalize(fptr, Qfalse);
-	GetOpenFile(write_io, wfptr);
-	if (fptr->refcnt < LONG_MAX) {
-	    wfptr->refcnt++;
-	    GC_WB(&RFILE(io)->fptr, wfptr);
-	    rb_io_fptr_finalize(fptr);
-	}
-        return Qnil;
-    }
-
-    if (fptr->mode & FMODE_WRITABLE) {
-	rb_raise(rb_eIOError, "closing non-duplex IO for reading");
-    }
-    return rb_io_close(io);
+rb_notimplement();
 }
 
 /*
@@ -2995,39 +1271,25 @@
  */
 
 static VALUE
-rb_io_close_write(VALUE io)
+rb_io_close_write(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-    VALUE write_io;
+rb_notimplement();
+}
 
-    if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
-	rb_raise(rb_eSecurityError, "Insecure: can't close");
-    }
-    write_io = GetWriteIO(io);
-    GetOpenFile(write_io, fptr);
-    if (is_socket(fptr->fd, fptr->path)) {
-#ifndef SHUT_WR
-# define SHUT_WR 1
-#endif
-        if (shutdown(fptr->fd, SHUT_WR) < 0)
-            rb_sys_fail(fptr->path);
-        fptr->mode &= ~FMODE_WRITABLE;
-        if (!(fptr->mode & FMODE_READABLE))
-	    return rb_io_close(write_io);
-        return Qnil;
-    }
+VALUE
+rb_io_close(VALUE io, SEL sel)
+{
+    rb_notimplement();
+}
 
-    if (fptr->mode & FMODE_READABLE) {
-	rb_raise(rb_eIOError, "closing non-duplex IO for writing");
-    }
+VALUE rb_io_fdopen(int a, int b, const char* c)
+{
+    rb_notimplement();
+}
 
-    rb_io_close(write_io);
-    if (io != write_io) {
-	GetOpenFile(io, fptr);
-	fptr->tied_io_for_writing = 0;
-	fptr->mode &= ~FMODE_DUPLEX;
-    }
-    return Qnil;
+VALUE rb_io_gets(VALUE v, SEL s)
+{
+    rb_notimplement();
 }
 
 /*
@@ -3044,28 +1306,9 @@
  */
 
 static VALUE
-rb_io_sysseek(int argc, VALUE *argv, VALUE io)
+rb_io_sysseek(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE offset, ptrname;
-    int whence = SEEK_SET;
-    rb_io_t *fptr;
-    off_t pos;
-
-    if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
-	whence = NUM2INT(ptrname);
-    }
-    pos = NUM2OFFT(offset);
-    GetOpenFile(io, fptr);
-    if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr)) {
-	rb_raise(rb_eIOError, "sysseek for buffered IO");
-    }
-    if ((fptr->mode & FMODE_WRITABLE) && fptr->wbuf_len) {
-	rb_warn("sysseek for buffered IO");
-    }
-    pos = lseek(fptr->fd, pos, whence);
-    if (pos == -1) rb_sys_fail(fptr->path);
-
-    return OFFT2NUM(pos);
+rb_notimplement();
 }
 
 /*
@@ -3082,32 +1325,9 @@
  */
 
 static VALUE
-rb_io_syswrite(VALUE io, VALUE str)
+rb_io_syswrite(VALUE io, SEL sel, VALUE str)
 {
-    rb_io_t *fptr;
-    long n;
-
-    rb_secure(4);
-    if (TYPE(str) != T_STRING)
-	str = rb_obj_as_string(str);
-
-    io = GetWriteIO(io);
-    GetOpenFile(io, fptr);
-    rb_io_check_writable(fptr);
-
-    if (fptr->wbuf_len) {
-	rb_warn("syswrite for buffered IO");
-    }
-    if (!rb_thread_fd_writable(fptr->fd)) {
-        rb_io_check_closed(fptr);
-    }
-    TRAP_BEG;
-    n = write(fptr->fd, RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str));
-    TRAP_END;
-
-    if (n == -1) rb_sys_fail(fptr->path);
-
-    return LONG2FIX(n);
+rb_notimplement();
 }
 
 /*
@@ -3127,72 +1347,11 @@
  */
 
 static VALUE
-rb_io_sysread(int argc, VALUE *argv, VALUE io)
+rb_io_sysread(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE len, str;
-    rb_io_t *fptr;
-    long n, ilen;
-
-    rb_scan_args(argc, argv, "11", &len, &str);
-    ilen = NUM2LONG(len);
-
-    if (NIL_P(str)) {
-	str = rb_str_new(0, ilen);
-    }
-    else {
-	StringValue(str);
-	rb_str_modify(str);
-	rb_str_resize(str, ilen);
-    }
-    if (ilen == 0) return str;
-
-    GetOpenFile(io, fptr);
-    rb_io_check_readable(fptr);
-
-    if (READ_DATA_BUFFERED(fptr)) {
-	rb_raise(rb_eIOError, "sysread for buffered IO");
-    }
-
-    n = fptr->fd;
-    rb_thread_wait_fd(fptr->fd);
-    rb_io_check_closed(fptr);
-    if (RSTRING_BYTELEN(str) != ilen) {
-	rb_raise(rb_eRuntimeError, "buffer string modified");
-    }
-
-    n = rb_read_internal(fptr->fd, RSTRING_BYTEPTR(str), ilen);
-
-    if (n == -1) {
-	rb_sys_fail(fptr->path);
-    }
-    rb_str_set_len(str, n);
-    if (n == 0 && ilen > 0) {
-	rb_eof_error();
-    }
-    rb_str_resize(str, n);
-    OBJ_TAINT(str);
-    RSTRING_SYNC(str);
-
-    return str;
+rb_notimplement();
 }
 
-VALUE
-rb_io_binmode(VALUE io)
-{
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
-    if (!(fptr->mode & FMODE_BINMODE) && READ_DATA_BUFFERED(fptr)) {
-	rb_raise(rb_eIOError, "buffer already filled with text-mode content");
-    }
-    if (0 <= fptr->fd && setmode(fptr->fd, O_BINARY) == -1)
-	rb_sys_fail(fptr->path);
-#endif
-    fptr->mode |= FMODE_BINMODE;
-    return io;
-}
-
 /*
  *  call-seq:
  *     ios.binmode    => ios
@@ -3203,830 +1362,11 @@
  */
 
 static VALUE
-rb_io_binmode_m(VALUE io)
+rb_io_binmode_m(VALUE io, SEL sel)
 {
-#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
-    VALUE write_io;
-#endif
-
-    rb_io_binmode(io);
-
-#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
-    write_io = GetWriteIO(io);
-    if (write_io != io)
-        rb_io_binmode(write_io);
-#endif
-    return io;
+rb_notimplement();
 }
 
-static const char*
-rb_io_flags_mode(int flags)
-{
-#ifdef O_BINARY
-# define MODE_BINMODE(a,b) ((flags & FMODE_BINMODE) ? (b) : (a))
-#else
-# define MODE_BINMODE(a,b) (a)
-#endif
-    if (flags & FMODE_APPEND) {
-	if ((flags & FMODE_READWRITE) == FMODE_READWRITE) {
-	    return MODE_BINMODE("a+", "ab+");
-	}
-	return MODE_BINMODE("a", "ab");
-    }
-    switch (flags & FMODE_READWRITE) {
-      case FMODE_READABLE:
-	return MODE_BINMODE("r", "rb");
-      case FMODE_WRITABLE:
-	return MODE_BINMODE("w", "wb");
-      case FMODE_READWRITE:
-	if (flags & FMODE_CREATE) {
-	    return MODE_BINMODE("w+", "wb+");
-	}
-	return MODE_BINMODE("r+", "rb+");
-    }
-    rb_raise(rb_eArgError, "invalid access modenum %o", flags);
-    return NULL;		/* not reached */
-}
-
-int
-rb_io_mode_flags(const char *mode)
-{
-    int flags = 0;
-    const char *m = mode;
-
-    switch (*m++) {
-      case 'r':
-	flags |= FMODE_READABLE;
-	break;
-      case 'w':
-	flags |= FMODE_WRITABLE | FMODE_CREATE;
-	break;
-      case 'a':
-	flags |= FMODE_WRITABLE | FMODE_APPEND | FMODE_CREATE;
-	break;
-      default:
-      error:
-	rb_raise(rb_eArgError, "invalid access mode %s", mode);
-    }
-
-    while (*m) {
-        switch (*m++) {
-	  case 'b':
-            flags |= FMODE_BINMODE;
-            break;
-	  case '+':
-            flags |= FMODE_READWRITE;
-            break;
-	  default:
-            goto error;
-	  case ':':
-	    return flags;
-        }
-    }
-
-    return flags;
-}
-
-int
-rb_io_modenum_flags(int mode)
-{
-    int flags = 0;
-
-    switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) {
-      case O_RDONLY:
-	flags = FMODE_READABLE;
-	break;
-      case O_WRONLY:
-	flags = FMODE_WRITABLE;
-	break;
-      case O_RDWR:
-	flags = FMODE_READWRITE;
-	break;
-    }
-
-    if (mode & O_APPEND) {
-	flags |= FMODE_APPEND;
-    }
-    if (mode & O_CREAT) {
-	flags |= FMODE_CREATE;
-    }
-#ifdef O_BINARY
-    if (mode & O_BINARY) {
-	flags |= FMODE_BINMODE;
-    }
-#endif
-
-    return flags;
-}
-
-int
-rb_io_mode_modenum(const char *mode)
-{
-    int flags = 0;
-    const char *m = mode;
-
-    switch (*m++) {
-      case 'r':
-	flags |= O_RDONLY;
-	break;
-      case 'w':
-	flags |= O_WRONLY | O_CREAT | O_TRUNC;
-	break;
-      case 'a':
-	flags |= O_WRONLY | O_CREAT | O_APPEND;
-	break;
-      default:
-      error:
-	rb_raise(rb_eArgError, "invalid access mode %s", mode);
-    }
-
-    while (*m) {
-        switch (*m++) {
-	  case 'b':
-#ifdef O_BINARY
-            flags |= O_BINARY;
-#endif
-            break;
-	  case '+':
-            flags = (flags & ~O_ACCMODE) | O_RDWR;
-            break;
-	  default:
-            goto error;
-	  case ':':
-	    return flags;
-        }
-    }
-
-    return flags;
-}
-
-#define MODENUM_MAX 4
-
-static const char*
-rb_io_modenum_mode(int flags)
-{
-#ifdef O_BINARY
-# define MODE_BINARY(a,b) ((flags & O_BINARY) ? (b) : (a))
-#else
-# define MODE_BINARY(a,b) (a)
-#endif
-    if (flags & O_APPEND) {
-	if ((flags & O_RDWR) == O_RDWR) {
-	    return MODE_BINARY("a+", "ab+");
-	}
-	return MODE_BINARY("a", "ab");
-    }
-    switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) {
-      case O_RDONLY:
-	return MODE_BINARY("r", "rb");
-      case O_WRONLY:
-	return MODE_BINARY("w", "wb");
-      case O_RDWR:
-	return MODE_BINARY("r+", "rb+");
-    }
-    rb_raise(rb_eArgError, "invalid access modenum %o", flags);
-    return NULL;		/* not reached */
-}
-
-static void
-mode_enc(rb_io_t *fptr, const char *estr)
-{
-    const char *p0, *p1;
-    char *enc2name;
-#if WITH_OBJC
-    rb_encoding *enc1, *enc2;
-#else
-    int idx, idx2;
-#endif
-
-    p0 = strrchr(estr, ':');
-    if (!p0) p1 = estr;
-    else     p1 = p0 + 1;
-#if WITH_OBJC
-    enc1 = rb_enc_find(p1);
-    if (enc1 != NULL) {
-	fptr->enc = enc1;
-    }
-    else {
-	rb_warn("Unsupported encoding %s ignored", p1);
-    }
-#else
-    idx = rb_enc_find_index(p1);
-    if (idx >= 0) {
-	fptr->enc = rb_enc_from_index(idx);
-    }
-    else {
-	rb_warn("Unsupported encoding %s ignored", p1);
-    }
-#endif
-
-    if (p0) {
-	int n = p0 - estr;
-	if (n > ENCODING_MAXNAMELEN) {
-#if WITH_OBJC
-	    enc2 = NULL;
-#else
-	    idx2 = -1;
-#endif
-	}
-	else {
-	    enc2name = ALLOCA_N(char, n+1);
-	    memcpy(enc2name, estr, n);
-	    enc2name[n] = '\0';
-	    estr = enc2name;
-#if WITH_OBJC
-	    enc2 = rb_enc_find(enc2name);
-#else
-	    idx2 = rb_enc_find_index(enc2name);
-#endif
-	}
-#if WITH_OBJC
-	if (enc2 == NULL) {
-#else
-	if (idx2 < 0) {
-#endif
-	    rb_warn("Unsupported encoding %.*s ignored", n, estr);
-	}
-#if WITH_OBJC
-	else if (enc1 == enc2) {
-#else
-	else if (idx2 == idx) {
-#endif
-	    rb_warn("Ignoring internal encoding %.*s: it is identical to external encoding %s",
-		    n, estr, p1);
-	}
-	else {
-#if WITH_OBJC
-	    fptr->enc2 = enc2;
-#else
-	    fptr->enc2 = rb_enc_from_index(idx2);
-#endif
-	}
-    }
-}
-
-void
-rb_io_mode_enc(rb_io_t *fptr, const char *mode)
-{
-    const char *p = strchr(mode, ':');
-    if (p) {
-	mode_enc(fptr, p+1);
-    }
-}
-
-struct sysopen_struct {
-    char *fname;
-    int flag;
-    unsigned int mode;
-};
-
-static VALUE
-sysopen_func(void *ptr)
-{
-    struct sysopen_struct *data = ptr;
-    return (VALUE)open(data->fname, data->flag, data->mode);
-}
-
-static int
-rb_sysopen_internal(char *fname, int flags, unsigned int mode)
-{
-    struct sysopen_struct data;
-    data.fname = fname;
-    data.flag = flags;
-    data.mode = mode;
-    return sysopen_func(&data);
-    //return (int)rb_thread_blocking_region(sysopen_func, &data, RB_UBF_DFL, 0);
-}
-
-static int
-rb_sysopen(char *fname, int flags, unsigned int mode)
-{
-    int fd;
-
-    fd = rb_sysopen_internal(fname, flags, mode);
-    if (fd < 0) {
-	if (errno == EMFILE || errno == ENFILE) {
-	    rb_gc();
-	    fd = rb_sysopen_internal(fname, flags, mode);
-	}
-	if (fd < 0) {
-	    rb_sys_fail(fname);
-	}
-    }
-    UPDATE_MAXFD(fd);
-    return fd;
-}
-
-FILE *
-rb_fopen(const char *fname, const char *mode)
-{
-    FILE *file;
-
-    file = fopen(fname, mode);
-    if (!file) {
-	if (errno == EMFILE || errno == ENFILE) {
-	    rb_gc();
-	    file = fopen(fname, mode);
-	}
-	if (!file) {
-	    rb_sys_fail(fname);
-	}
-    }
-#ifdef USE_SETVBUF
-    if (setvbuf(file, NULL, _IOFBF, 0) != 0)
-	rb_warn("setvbuf() can't be honoured for %s", fname);
-#endif
-#ifdef __human68k__
-    setmode(fileno(file), O_TEXT);
-#endif
-    return file;
-}
-
-FILE *
-rb_fdopen(int fd, const char *mode)
-{
-    FILE *file;
-
-#if defined(sun)
-    errno = 0;
-#endif
-    file = fdopen(fd, mode);
-    if (!file) {
-	if (
-#if defined(sun)
-	    errno == 0 ||
-#endif
-	    errno == EMFILE || errno == ENFILE) {
-	    rb_gc();
-#if defined(sun)
-	    errno = 0;
-#endif
-	    file = fdopen(fd, mode);
-	}
-	if (!file) {
-#ifdef _WIN32
-	    if (errno == 0) errno = EINVAL;
-#elif defined(sun)
-	    if (errno == 0) errno = EMFILE;
-#endif
-	    rb_sys_fail(0);
-	}
-    }
-
-    /* xxx: should be _IONBF?  A buffer in FILE may have trouble. */
-#ifdef USE_SETVBUF
-    if (setvbuf(file, NULL, _IOFBF, 0) != 0)
-	rb_warn("setvbuf() can't be honoured (fd=%d)", fd);
-#endif
-    return file;
-}
-
-static void
-io_check_tty(rb_io_t *fptr)
-{
-    if (isatty(fptr->fd))
-        fptr->mode |= FMODE_TTY|FMODE_DUPLEX;
-}
-
-static VALUE
-rb_file_open_internal(VALUE io, const char *fname, const char *mode)
-{
-    rb_io_t *fptr;
-
-    MakeOpenFile(io, fptr);
-    fptr->mode = rb_io_mode_flags(mode);
-    rb_io_mode_enc(fptr, mode);
-    fptr->path = strdup(fname);
-    fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(rb_io_flags_mode(fptr->mode)), 0666);
-    io_check_tty(fptr);
-
-    return io;
-}
-
-VALUE
-rb_file_open(const char *fname, const char *mode)
-{
-    return rb_file_open_internal(io_alloc(rb_cFile, 0), fname, mode);
-}
-
-static VALUE
-rb_file_sysopen_internal(VALUE io, const char *fname, int flags, int mode)
-{
-    rb_io_t *fptr;
-
-    MakeOpenFile(io, fptr);
-
-    fptr->path = strdup(fname);
-    fptr->mode = rb_io_modenum_flags(flags);
-    fptr->fd = rb_sysopen(fptr->path, flags, mode);
-    io_check_tty(fptr);
-
-    return io;
-}
-
-VALUE
-rb_file_sysopen(const char *fname, int flags, int mode)
-{
-    return rb_file_sysopen_internal(io_alloc(rb_cFile, 0), fname, flags, mode);
-}
-
-#if defined(__CYGWIN__) || !defined(HAVE_FORK)
-static struct pipe_list {
-    rb_io_t *fptr;
-    struct pipe_list *next;
-} *pipe_list;
-
-static void
-pipe_add_fptr(rb_io_t *fptr)
-{
-    struct pipe_list *list;
-
-    list = ALLOC(struct pipe_list);
-    list->fptr = fptr;
-    list->next = pipe_list;
-    pipe_list = list;
-}
-
-static void
-pipe_del_fptr(rb_io_t *fptr)
-{
-    struct pipe_list *list = pipe_list;
-    struct pipe_list *tmp;
-
-    if (list->fptr == fptr) {
-	pipe_list = list->next;
-	free(list);
-	return;
-    }
-
-    while (list->next) {
-	if (list->next->fptr == fptr) {
-	    tmp = list->next;
-	    list->next = list->next->next;
-	    free(tmp);
-	    return;
-	}
-	list = list->next;
-    }
-}
-
-static void
-pipe_atexit(void)
-{
-    struct pipe_list *list = pipe_list;
-    struct pipe_list *tmp;
-
-    while (list) {
-	tmp = list->next;
-	rb_io_fptr_finalize(list->fptr);
-	list = tmp;
-    }
-}
-
-static void
-pipe_finalize(rb_io_t *fptr, int noraise)
-{
-#if !defined(HAVE_FORK) && !defined(_WIN32)
-    int status;
-    if (fptr->stdio_file) {
-	status = pclose(fptr->stdio_file);
-    }
-    fptr->fd = -1;
-    fptr->stdio_file = 0;
-#if defined DJGPP
-    status <<= 8;
-#endif
-    rb_last_status_set(status, fptr->pid);
-#else
-    fptr_finalize(fptr, noraise);
-#endif
-    pipe_del_fptr(fptr);
-}
-#endif
-
-void
-rb_io_synchronized(rb_io_t *fptr)
-{
-    rb_io_check_initialized(fptr);
-    fptr->mode |= FMODE_SYNC;
-}
-
-void
-rb_io_unbuffered(rb_io_t *fptr)
-{
-    rb_io_synchronized(fptr);
-}
-
-#ifdef HAVE_FORK
-struct popen_arg {
-    struct rb_exec_arg *execp;
-    int modef;
-    int pair[2];
-    int write_pair[2];
-};
-
-static void
-popen_redirect(struct popen_arg *p)
-{
-    if ((p->modef & FMODE_READABLE) && (p->modef & FMODE_WRITABLE)) {
-        close(p->write_pair[1]);
-        if (p->write_pair[0] != 0) {
-            dup2(p->write_pair[0], 0);
-            close(p->write_pair[0]);
-        }
-        close(p->pair[0]);
-        if (p->pair[1] != 1) {
-            dup2(p->pair[1], 1);
-            close(p->pair[1]);
-        }
-    }
-    else if (p->modef & FMODE_READABLE) {
-        close(p->pair[0]);
-        if (p->pair[1] != 1) {
-            dup2(p->pair[1], 1);
-            close(p->pair[1]);
-        }
-    }
-    else {
-        close(p->pair[1]);
-        if (p->pair[0] != 0) {
-            dup2(p->pair[0], 0);
-            close(p->pair[0]);
-        }
-    }
-}
-
-void
-rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds)
-{
-    int fd, ret;
-    int max = max_file_descriptor;
-    if (max < maxhint)
-        max = maxhint;
-    for (fd = lowfd; fd <= max; fd++) {
-        if (!NIL_P(noclose_fds) &&
-            RTEST(rb_hash_lookup(noclose_fds, INT2FIX(fd))))
-            continue;
-#ifdef FD_CLOEXEC
-	ret = fcntl(fd, F_GETFD);
-	if (ret != -1 && !(ret & FD_CLOEXEC)) {
-            fcntl(fd, F_SETFD, ret|FD_CLOEXEC);
-        }
-#else
-	close(fd);
-#endif
-    }
-}
-
-static int
-popen_exec(void *pp)
-{
-    struct popen_arg *p = (struct popen_arg*)pp;
-
-    //rb_thread_atfork_before_exec();
-    return rb_exec(p->execp);
-}
-#endif
-
-static VALUE
-pipe_open(struct rb_exec_arg *eargp, VALUE prog, const char *mode)
-{
-    int modef = rb_io_mode_flags(mode);
-    int pid = 0;
-    rb_io_t *fptr;
-    VALUE port;
-    rb_io_t *write_fptr;
-    VALUE write_port;
-#if defined(HAVE_FORK)
-    int status;
-    struct popen_arg arg;
-#elif defined(_WIN32)
-    int openmode = rb_io_mode_modenum(mode);
-    const char *exename = NULL;
-    volatile VALUE cmdbuf;
-    struct rb_exec_arg sarg;
-#endif
-    FILE *fp = 0;
-    int fd = -1;
-    int write_fd = -1;
-    const char *cmd = 0;
-    int argc;
-    VALUE *argv;
-
-    if (prog)
-        cmd = StringValueCStr(prog);
-
-    if (!eargp) {
-        /* fork : IO.popen("-") */
-        argc = 0;
-        argv = 0;
-    }
-    else if (eargp->argc) {
-        /* no shell : IO.popen([prog, arg0], arg1, ...) */
-        argc = eargp->argc;
-        argv = eargp->argv;
-    }
-    else {
-        /* with shell : IO.popen(prog) */
-        argc = 0;
-        argv = 0;
-    }
-
-#if defined(HAVE_FORK)
-    arg.execp = eargp;
-    arg.modef = modef;
-    arg.pair[0] = arg.pair[1] = -1;
-    arg.write_pair[0] = arg.write_pair[1] = -1;
-    switch (modef & (FMODE_READABLE|FMODE_WRITABLE)) {
-      case FMODE_READABLE|FMODE_WRITABLE:
-        if (pipe(arg.write_pair) < 0)
-            rb_sys_fail(cmd);
-        UPDATE_MAXFD_PIPE(arg.write_pair);
-        if (pipe(arg.pair) < 0) {
-            int e = errno;
-            close(arg.write_pair[0]);
-            close(arg.write_pair[1]);
-            errno = e;
-            rb_sys_fail(cmd);
-        }
-        UPDATE_MAXFD_PIPE(arg.pair);
-        if (eargp) {
-            rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.write_pair[0]));
-            rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(arg.pair[1]));
-        }
-	break;
-      case FMODE_READABLE:
-        if (pipe(arg.pair) < 0)
-            rb_sys_fail(cmd);
-        UPDATE_MAXFD_PIPE(arg.pair);
-        if (eargp)
-            rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(arg.pair[1]));
-	break;
-      case FMODE_WRITABLE:
-        if (pipe(arg.pair) < 0)
-            rb_sys_fail(cmd);
-        UPDATE_MAXFD_PIPE(arg.pair);
-        if (eargp)
-            rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.pair[0]));
-	break;
-      default:
-        rb_sys_fail(cmd);
-    }
-    if (eargp) {
-        rb_exec_arg_fixup(arg.execp);
-	pid = rb_fork(&status, popen_exec, &arg, arg.execp->redirect_fds);
-    }
-    else {
-	fflush(stdin);		/* is it really needed? */
-	rb_io_flush(rb_stdout);
-	rb_io_flush(rb_stderr);
-	pid = rb_fork(&status, 0, 0, Qnil);
-	if (pid == 0) {		/* child */
-	    popen_redirect(&arg);
-	    rb_io_synchronized(RFILE(orig_stdout)->fptr);
-	    rb_io_synchronized(RFILE(orig_stderr)->fptr);
-	    return Qnil;
-	}
-    }
-
-    /* parent */
-    if (pid == -1) {
-	int e = errno;
-	close(arg.pair[0]);
-	close(arg.pair[1]);
-        if ((modef & (FMODE_READABLE|FMODE_WRITABLE)) == (FMODE_READABLE|FMODE_WRITABLE)) {
-            close(arg.write_pair[0]);
-            close(arg.write_pair[1]);
-        }
-	errno = e;
-	rb_sys_fail(cmd);
-    }
-    if ((modef & FMODE_READABLE) && (modef & FMODE_WRITABLE)) {
-        close(arg.pair[1]);
-        fd = arg.pair[0];
-        close(arg.write_pair[0]);
-        write_fd = arg.write_pair[1];
-    }
-    else if (modef & FMODE_READABLE) {
-        close(arg.pair[1]);
-        fd = arg.pair[0];
-    }
-    else {
-        close(arg.pair[0]);
-        fd = arg.pair[1];
-    }
-#elif defined(_WIN32)
-    if (argc) {
-	volatile VALUE argbuf;
-	char **args;
-	int i;
-
-	if (argc >= FIXNUM_MAX / sizeof(char *)) {
-	    rb_raise(rb_eArgError, "too many arguments");
-	}
-	argbuf = rb_str_tmp_new((argc+1) * sizeof(char *));
-	args = (void *)RSTRING_BYTEPTR(argbuf);
-	for (i = 0; i < argc; ++i) {
-	    args[i] = StringValueCStr(argv[i]);
-	}
-	args[i] = NULL;
-	exename = cmd;
-	cmdbuf = rb_str_tmp_new(rb_w32_argv_size(args));
-	cmd = rb_w32_join_argv(RSTRING_BYTEPTR(cmdbuf), args);
-	rb_str_resize(argbuf, 0);
-    }
-    if (eargp) {
-	rb_exec_arg_fixup(eargp);
-	rb_run_exec_options(eargp, &sarg);
-    }
-    while ((pid = rb_w32_pipe_exec(cmd, exename, openmode, &fd, &write_fd)) == -1) {
-	/* exec failed */
-	switch (errno) {
-	  case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
-	  case EWOULDBLOCK:
-#endif
-	    rb_thread_sleep(1);
-	    break;
-	  default:
-	    if (eargp)
-		rb_run_exec_options(&sarg, NULL);
-	    rb_sys_fail(cmd);
-	    break;
-	}
-    }
-    if (eargp)
-	rb_run_exec_options(&sarg, NULL);
-#else
-    if (argc) {
-	prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
-	cmd = StringValueCStr(prog);
-    }
-    if (eargp) {
-	rb_exec_arg_fixup(eargp);
-	rb_run_exec_options(eargp, &sarg);
-    }
-    fp = popen(cmd, mode);
-    if (eargp)
-	rb_run_exec_options(&sarg, NULL);
-    if (!fp) rb_sys_fail(RSTRING_BYTEPTR(prog));
-    fd = fileno(fp);
-#endif
-
-    port = io_alloc(rb_cIO, 0);
-    MakeOpenFile(port, fptr);
-    fptr->fd = fd;
-    fptr->stdio_file = fp;
-    fptr->mode = modef | FMODE_SYNC|FMODE_DUPLEX;
-    rb_io_mode_enc(fptr, mode);
-    fptr->pid = pid;
-
-    if (0 <= write_fd) {
-        write_port = io_alloc(rb_cIO, 0);
-        MakeOpenFile(write_port, write_fptr);
-        write_fptr->fd = write_fd;
-        write_fptr->mode = (modef & ~FMODE_READABLE)| FMODE_SYNC|FMODE_DUPLEX;
-        fptr->mode &= ~FMODE_WRITABLE;
-        GC_WB(&fptr->tied_io_for_writing, write_port);
-        rb_ivar_set(port, rb_intern("@tied_io_for_writing"), write_port);
-    }
-
-#if defined (__CYGWIN__) || !defined(HAVE_FORK)
-    fptr->finalize = pipe_finalize;
-    pipe_add_fptr(fptr);
-#endif
-    return port;
-}
-
-static VALUE
-pipe_open_v(int argc, VALUE *argv, const char *mode)
-{
-    VALUE prog;
-    struct rb_exec_arg earg;
-    prog = rb_exec_arg_init(argc, argv, Qfalse, &earg);
-    return pipe_open(&earg, prog, mode);
-}
-
-static VALUE
-pipe_open_s(VALUE prog, const char *mode)
-{
-    const char *cmd = RSTRING_PTR(prog);
-    int argc = 1;
-    VALUE *argv = &prog;
-    struct rb_exec_arg earg;
-
-    if (RSTRING_LEN(prog) == 1 && cmd[0] == '-') {
-#if !defined(HAVE_FORK)
-	rb_raise(rb_eNotImpError,
-		 "fork() function is unimplemented on this machine");
-#endif
-        return pipe_open(0, 0, mode);
-    }
-
-    rb_exec_arg_init(argc, argv, Qtrue, &earg);
-    return pipe_open(&earg, prog, mode);
-}
-
 /*
  *  call-seq:
  *     IO.popen(cmd, mode="r")               => io
@@ -4083,80 +1423,11 @@
  */
 
 static VALUE
-rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
+rb_io_s_popen(VALUE klass, SEL sel, int argc, VALUE *argv)
 {
-    const char *mode;
-    VALUE pname, pmode, port, tmp;
-
-    if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
-	mode = "r";
-    }
-    else if (FIXNUM_P(pmode)) {
-	mode = rb_io_modenum_mode(FIX2INT(pmode));
-    }
-    else {
-	mode = StringValueCStr(pmode);
-    }
-    tmp = rb_check_array_type(pname);
-    if (!NIL_P(tmp)) {
-	tmp = rb_ary_dup(tmp);
-#if !WITH_OBJC
-	RBASIC(tmp)->klass = 0;
-#endif
-	port = pipe_open_v(RARRAY_LEN(tmp), (VALUE *)RARRAY_PTR(tmp), mode);
-	rb_ary_clear(tmp);
-    }
-    else {
-	SafeStringValue(pname);
-	port = pipe_open_s(pname, mode);
-    }
-    if (NIL_P(port)) {
-	/* child */
-	if (rb_block_given_p()) {
-	    rb_yield(Qnil);
-            rb_io_flush(rb_stdout);
-            rb_io_flush(rb_stderr);
-	    _exit(0);
-	}
-	return Qnil;
-    }
-    RBASIC(port)->klass = klass;
-    if (rb_block_given_p()) {
-	return rb_ensure(rb_yield, port, io_close, port);
-    }
-    return port;
+rb_notimplement();
 }
 
-static VALUE
-rb_open_file(int argc, VALUE *argv, VALUE io)
-{
-    VALUE fname, vmode, perm;
-    const char *mode;
-    int flags, fmode;
-
-    rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
-    FilePathValue(fname);
-
-    if (FIXNUM_P(vmode) || !NIL_P(perm)) {
-	if (FIXNUM_P(vmode)) {
-	    flags = FIX2INT(vmode);
-	}
-	else {
-	    SafeStringValue(vmode);
-	    flags = rb_io_mode_modenum(StringValueCStr(vmode));
-	}
-	fmode = NIL_P(perm) ? 0666 :  NUM2INT(perm);
-
-	rb_file_sysopen_internal(io, RSTRING_PTR(fname), flags, fmode);
-    }
-    else {
-
-	mode = NIL_P(vmode) ? "r" : StringValueCStr(vmode);
-	rb_file_open_internal(io, RSTRING_PTR(fname), mode);
-    }
-    return io;
-}
-
 /*
  *  call-seq:
  *     IO.open(fd, mode_string="r" )               => io
@@ -4171,15 +1442,9 @@
  */
 
 static VALUE
-rb_io_s_open(int argc, VALUE *argv, VALUE klass)
+rb_io_s_open(VALUE klass, SEL sel, int argc, VALUE *argv)
 {
-    VALUE io = rb_class_new_instance(argc, argv, klass);
-
-    if (rb_block_given_p()) {
-	return rb_ensure(rb_yield, io, io_close, io);
-    }
-
-    return io;
+rb_notimplement();
 }
 
 /*
@@ -4194,28 +1459,9 @@
  */
 
 static VALUE
-rb_io_s_sysopen(int argc, VALUE *argv)
+rb_io_s_sysopen(VALUE klass, SEL sel, int argc, VALUE *argv)
 {
-    VALUE fname, vmode, perm;
-    int flags, fmode, fd;
-    const char *path;
-
-    rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
-    FilePathValue(fname);
-
-    if (NIL_P(vmode)) flags = O_RDONLY;
-    else if (FIXNUM_P(vmode)) flags = FIX2INT(vmode);
-    else {
-	SafeStringValue(vmode);
-	flags = rb_io_mode_modenum(StringValueCStr(vmode));
-    }
-    if (NIL_P(perm)) fmode = 0666;
-    else             fmode = NUM2INT(perm);
-
-    RB_GC_GUARD(fname) = rb_str_new4(fname);
-    path = RSTRING_PTR(fname);
-    fd = rb_sysopen((char *)path, flags, fmode);
-    return INT2NUM(fd);
+rb_notimplement();
 }
 
 /*
@@ -4326,161 +1572,11 @@
  */
 
 static VALUE
-rb_f_open(int argc, VALUE *argv)
+rb_f_open(VALUE klass, SEL sel, int argc, VALUE *argv)
 {
-    ID to_open;
-    int redirect = Qfalse;
-
-    if (argc >= 1) {
-	to_open = rb_intern("to_open");
-	if (rb_respond_to(argv[0], to_open)) {
-	    redirect = Qtrue;
-	}
-	else {
-	    VALUE tmp = argv[0];
-	    FilePathValue(tmp);
-	    if (NIL_P(tmp)) {
-		redirect = Qtrue;
-	    }
-	    else {
-		char *str = StringValuePtr(tmp);
-		if (str && str[0] == '|') {
-		    argv[0] = rb_str_new(str+1, RSTRING_BYTELEN(tmp)-1);
-		    OBJ_INFECT(argv[0], tmp);
-		    return rb_io_s_popen(argc, argv, rb_cIO);
-		}
-	    }
-	}
-    }
-    if (redirect) {
-	VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1);
-
-	if (rb_block_given_p()) {
-	    return rb_ensure(rb_yield, io, io_close, io);
-	}
-	return io;
-    }
-    return rb_io_s_open(argc, argv, rb_cFile);
+rb_notimplement();
 }
 
-static VALUE
-rb_io_open(const char *fname, const char *mode)
-{
-    if (fname[0] == '|') {
-	VALUE cmd = rb_str_new2(fname+1);
-	return pipe_open_s(cmd, mode);
-    }
-    else {
-	return rb_file_open(fname, mode);
-    }
-}
-
-static VALUE
-rb_io_open_with_args(int argc, VALUE *argv)
-{
-    const char *mode;
-    VALUE pname, pmode;
-
-    if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
-	mode = "r";
-    }
-    else if (FIXNUM_P(pmode)) {
-	mode = rb_io_modenum_mode(FIX2INT(pmode));
-    }
-    else {
-	mode = StringValueCStr(pmode);
-    }
-    return rb_io_open(StringValueCStr(pname), mode);
-}
-
-static VALUE
-io_reopen(VALUE io, VALUE nfile)
-{
-    rb_io_t *fptr, *orig;
-    int fd, fd2;
-    off_t pos = 0;
-
-    nfile = rb_io_get_io(nfile);
-    if (rb_safe_level() >= 4 && (!OBJ_TAINTED(io) || !OBJ_TAINTED(nfile))) {
-	rb_raise(rb_eSecurityError, "Insecure: can't reopen");
-    }
-    GetOpenFile(io, fptr);
-    GetOpenFile(nfile, orig);
-
-    if (fptr == orig) return io;
-#if !defined __CYGWIN__
-    if (IS_PREP_STDIO(fptr)) {
-        if ((fptr->stdio_file == stdin && !(orig->mode & FMODE_READABLE)) ||
-            (fptr->stdio_file == stdout && !(orig->mode & FMODE_WRITABLE)) ||
-            (fptr->stdio_file == stderr && !(orig->mode & FMODE_WRITABLE))) {
-	    rb_raise(rb_eArgError,
-		     "%s can't change access mode from \"%s\" to \"%s\"",
-		     PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
-		     rb_io_flags_mode(orig->mode));
-	}
-    }
-#endif
-    if (orig->mode & FMODE_READABLE) {
-	pos = io_tell(orig);
-    }
-    if (orig->mode & FMODE_WRITABLE) {
-	io_fflush(orig);
-    }
-    if (fptr->mode & FMODE_WRITABLE) {
-	io_fflush(fptr);
-    }
-
-    /* copy rb_io_t structure */
-    fptr->mode = orig->mode | (fptr->mode & FMODE_PREP);
-    fptr->pid = orig->pid;
-    fptr->lineno = orig->lineno;
-    if (fptr->path) free(fptr->path);
-    if (orig->path) fptr->path = strdup(orig->path);
-    else fptr->path = 0;
-    fptr->finalize = orig->finalize;
-
-    fd = fptr->fd;
-    fd2 = orig->fd;
-    if (fd != fd2) {
-#if !defined __CYGWIN__
-	if (IS_PREP_STDIO(fptr)) {
-	    /* need to keep stdio objects */
-	    if (dup2(fd2, fd) < 0)
-		rb_sys_fail(orig->path);
-	}
-	else {
-#endif
-            if (fptr->stdio_file)
-                fclose(fptr->stdio_file);
-            else
-                close(fptr->fd);
-            fptr->stdio_file = 0;
-            fptr->fd = -1;
-	    if (dup2(fd2, fd) < 0)
-		rb_sys_fail(orig->path);
-            fptr->fd = fd;
-#if !defined __CYGWIN__
-	}
-#endif
-	//rb_thread_fd_close(fd);
-	if ((orig->mode & FMODE_READABLE) && pos >= 0) {
-	    if (io_seek(fptr, pos, SEEK_SET) < 0) {
-		rb_sys_fail(fptr->path);
-	    }
-	    if (io_seek(orig, pos, SEEK_SET) < 0) {
-		rb_sys_fail(orig->path);
-	    }
-	}
-    }
-
-    if (fptr->mode & FMODE_BINMODE) {
-	rb_io_binmode(io);
-    }
-
-    RBASIC(io)->klass = RBASIC(nfile)->klass;
-    return io;
-}
-
 /*
  *  call-seq:
  *     ios.reopen(other_IO)         => ios
@@ -4498,117 +1594,16 @@
  */
 
 static VALUE
-rb_io_reopen(int argc, VALUE *argv, VALUE file)
+rb_io_reopen(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE fname, nmode;
-    const char *mode;
-    rb_io_t *fptr;
-
-    rb_secure(4);
-    if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
-	VALUE tmp = rb_io_check_io(fname);
-	if (!NIL_P(tmp)) {
-	    return io_reopen(file, tmp);
-	}
-    }
-
-    FilePathValue(fname);
-    rb_io_taint_check(file);
-    fptr = RFILE(file)->fptr;
-    if (!fptr) {
-	GC_WB(&RFILE(file)->fptr, ALLOC(rb_io_t));
-	fptr = RFILE(file)->fptr;
-	MEMZERO(fptr, rb_io_t, 1);
-    }
-
-    if (!NIL_P(nmode)) {
-	int flags = rb_io_mode_flags(StringValueCStr(nmode));
-	if (IS_PREP_STDIO(fptr) &&
-            ((fptr->mode & FMODE_READWRITE) & (flags & FMODE_READWRITE)) !=
-            (fptr->mode & FMODE_READWRITE)) {
-	    rb_raise(rb_eArgError,
-		     "%s can't change access mode from \"%s\" to \"%s\"",
-		     PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
-		     rb_io_flags_mode(flags));
-	}
-	fptr->mode = flags;
-	rb_io_mode_enc(fptr, StringValueCStr(nmode));
-    }
-
-    if (fptr->path) {
-	free(fptr->path);
-	fptr->path = 0;
-    }
-
-    fptr->path = strdup(StringValueCStr(fname));
-    mode = rb_io_flags_mode(fptr->mode);
-    if (fptr->fd < 0) {
-        fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(mode), 0666);
-	fptr->stdio_file = 0;
-	return file;
-    }
-
-    if (fptr->mode & FMODE_WRITABLE) {
-        io_fflush(fptr);
-    }
-
-    if (fptr->stdio_file) {
-        if (freopen(fptr->path, mode, fptr->stdio_file) == 0) {
-            rb_sys_fail(fptr->path);
-        }
-        fptr->fd = fileno(fptr->stdio_file);
-#ifdef USE_SETVBUF
-        if (setvbuf(fptr->stdio_file, NULL, _IOFBF, 0) != 0)
-            rb_warn("setvbuf() can't be honoured for %s", fptr->path);
-#endif
-    }
-    else {
-        if (close(fptr->fd) < 0)
-            rb_sys_fail(fptr->path);
-        fptr->fd = -1;
-        fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(mode), 0666);
-    }
-
-    return file;
+rb_notimplement();
 }
 
 /* :nodoc: */
 static VALUE
 rb_io_init_copy(VALUE dest, VALUE io)
 {
-    rb_io_t *fptr, *orig;
-    int fd;
-    VALUE write_io;
-
-    io = rb_io_get_io(io);
-    if (dest == io) return dest;
-    GetOpenFile(io, orig);
-    MakeOpenFile(dest, fptr);
-
-    rb_io_flush(io);
-
-    /* copy rb_io_t structure */
-    fptr->mode = orig->mode & ~FMODE_PREP;
-    fptr->pid = orig->pid;
-    fptr->lineno = orig->lineno;
-    if (orig->path) fptr->path = strdup(orig->path);
-    fptr->finalize = orig->finalize;
-
-    fd = ruby_dup(orig->fd);
-    fptr->fd = fd;
-    io_seek(fptr, io_tell(orig), SEEK_SET);
-    if (fptr->mode & FMODE_BINMODE) {
-	rb_io_binmode(dest);
-    }
-
-    write_io = GetWriteIO(io);
-    if (io != write_io) {
-        write_io = rb_obj_dup(write_io);
-        GC_WB(&fptr->tied_io_for_writing, write_io);
-        rb_ivar_set(dest, rb_intern("@tied_io_for_writing"), write_io);
-    }
-
-    return dest;
+rb_notimplement();
 }
 
 /*
@@ -4621,10 +1616,9 @@
  */
 
 VALUE
-rb_io_printf(int argc, VALUE *argv, VALUE out)
+rb_io_printf(VALUE out, SEL sel, int argc, VALUE *argv)
 {
-    rb_io_write(out, rb_f_sprintf(argc, argv));
-    return Qnil;
+    rb_notimplement();
 }
 
 /*
@@ -4641,20 +1635,7 @@
 static VALUE
 rb_f_printf(VALUE klass, SEL sel, int argc, VALUE *argv)
 {
-    VALUE out;
-
-    if (argc == 0) return Qnil;
-    if (TYPE(argv[0]) == T_STRING) {
-	out = rb_stdout;
-    }
-    else {
-	out = argv[0];
-	argv++;
-	argc--;
-    }
-    rb_io_write(out, rb_f_sprintf(argc, argv));
-
-    return Qnil;
+rb_notimplement();
 }
 
 /*
@@ -4678,30 +1659,29 @@
  */
 
 VALUE
-rb_io_print(int argc, VALUE *argv, VALUE out)
+rb_io_print(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    int i;
     VALUE line;
-
-    /* if no argument given, print `$_' */
-    if (argc == 0) {
-	argc = 1;
-	line = rb_lastline_get();
-	argv = &line;
+    if(argc == 0) {
+        // No arguments? Bloody Perlisms...
+        argc = 1;
+        line = rb_lastline_get();
+        argv = &line;
     }
-    for (i=0; i<argc; i++) {
-	rb_io_write(out, argv[i]);
-	if (!NIL_P(rb_output_fs)) {
-	    rb_io_write(out, rb_output_fs);
-	}
+    while(argc--) {
+        rb_io_write(rb_stdout, sel, *argv++);
+        if(!NIL_P(rb_output_fs)) {
+            rb_io_write(rb_stdout, sel, rb_output_fs);
+        }
     }
-    if (argc > 0 && !NIL_P(rb_output_rs)) {
-	rb_io_write(out, rb_output_rs);
+    if(!NIL_P(rb_output_rs)) {
+        rb_io_write(rb_stdout, sel, rb_output_rs);
     }
-
     return Qnil;
 }
 
+
+
 /*
  *  call-seq:
  *     print(obj, ...)    => nil
@@ -4728,7 +1708,7 @@
 static VALUE
 rb_f_print(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    rb_io_print(argc, argv, rb_stdout);
+    rb_io_print(rb_stdout, sel, argc, argv);
     return Qnil;
 }
 
@@ -4749,12 +1729,9 @@
  */
 
 static VALUE
-rb_io_putc(VALUE io, VALUE ch)
+rb_io_putc(VALUE io, SEL sel, VALUE ch)
 {
-    char c = NUM2CHR(ch);
-
-    rb_io_write(io, rb_str_new(&c, 1));
-    return ch;
+rb_notimplement();
 }
 
 /*
@@ -4767,34 +1744,11 @@
  */
 
 static VALUE
-rb_f_putc(VALUE recv, VALUE ch)
+rb_f_putc(VALUE recv, SEL sel, VALUE ch)
 {
-    if (recv == rb_stdout) {
-	return rb_io_putc(recv, ch);
-    }
-    return rb_funcall2(rb_stdout, rb_intern("putc"), 1, &ch);
+rb_notimplement();
 }
 
-VALUE rb_io_puts(VALUE out, SEL sel, int argc, VALUE *argv);
-
-static VALUE
-io_puts_ary(VALUE ary, VALUE out, int recur)
-{
-    VALUE tmp;
-    long i;
-
-    if (recur) {
-	tmp = rb_str_new2("[...]");
-	rb_io_puts(out, 0, 1, &tmp);
-	return Qnil;
-    }
-    for (i=0; i<RARRAY_LEN(ary); i++) {
-	tmp = RARRAY_AT(ary, i);
-	rb_io_puts(out, 0, 1, &tmp);
-    }
-    return Qnil;
-}
-
 /*
  *  call-seq:
  *     ios.puts(obj, ...)    => nil
@@ -4818,29 +1772,7 @@
 VALUE
 rb_io_puts(VALUE out, SEL sel, int argc, VALUE *argv)
 {
-    int i;
-    VALUE line;
-
-    /* if no argument given, print newline. */
-    if (argc == 0) {
-	rb_io_write(out, rb_default_rs);
-	return Qnil;
-    }
-    for (i=0; i<argc; i++) {
-	line = rb_check_array_type(argv[i]);
-	if (!NIL_P(line)) {
-	    rb_exec_recursive(io_puts_ary, line, out);
-	    continue;
-	}
-	line = rb_obj_as_string(argv[i]);
-	rb_io_write(out, line);
-	if (RSTRING_LEN(line) == 0 ||
-            RSTRING_PTR(line)[RSTRING_LEN(line)-1] != '\n') {
-	    rb_io_write(out, rb_default_rs);
-	}
-    }
-
-    return Qnil;
+rb_notimplement();
 }
 
 /*
@@ -4855,19 +1787,26 @@
 static VALUE
 rb_f_puts(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    if (recv == rb_stdout) {
-	return rb_io_puts(recv, 0, argc, argv);
+    while(argc--) {
+        rb_io_write(rb_stdout, sel, *argv++);
+        rb_io_write(rb_stdout, sel, rb_default_rs);
     }
-    return rb_funcall2(rb_stdout, rb_intern("puts"), argc, argv);
+    return Qnil;
 }
 
 void
-rb_p(VALUE obj) /* for debug print within C code */
+rb_p(VALUE obj, SEL sel) /* for debug print within C code */
 {
-    rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj)));
-    rb_io_write(rb_stdout, rb_default_rs);
+    rb_io_write(rb_stdout, sel, rb_obj_as_string(rb_inspect(obj)));
+    rb_io_write(rb_stdout, sel, rb_default_rs);
 }
 
+VALUE rb_io_write(VALUE v, SEL sel, VALUE i)
+{
+    io_write(v, sel, i);
+    return Qnil;
+}
+
 /*
  *  call-seq:
  *     p(obj)              => obj
@@ -4888,23 +1827,20 @@
  */
 
 static VALUE
-rb_f_p(VALUE self, SEL sel, int argc, VALUE *argv)
-{
+rb_f_p(VALUE self, SEL sel, int argc, VALUE *argv) {
     int i;
     VALUE ret = Qnil;
 
     for (i=0; i<argc; i++) {
-	rb_p(argv[i]);
+	    rb_p(argv[i], (SEL)0);
     }
     if (argc == 1) {
-	ret = argv[0];
+	    ret = argv[0];
     }
     else if (argc > 1) {
-	ret = rb_ary_new4(argc, argv);
+	    ret = rb_ary_new4(argc, argv);
     }
-    if (TYPE(rb_stdout) == T_FILE) {
-	rb_io_flush(rb_stdout);
-    }
+
     return ret;
 }
 
@@ -4932,102 +1868,22 @@
  */
 
 static VALUE
-rb_obj_display(int argc, VALUE *argv, VALUE self)
+rb_obj_display(VALUE self, SEL sel, int argc, VALUE *argv)
 {
-    VALUE out;
-
-    if (argc == 0) {
-	out = rb_stdout;
-    }
-    else {
-	rb_scan_args(argc, argv, "01", &out);
-    }
-    rb_io_write(out, self);
-
-    return Qnil;
+rb_notimplement();
 }
 
-void
-rb_write_error2(const char *mesg, long len)
-{
-    if (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0) {
-	fwrite(mesg, sizeof(char), len, stderr);
-    }
-    else {
-	rb_io_write(rb_stderr, rb_str_new(mesg, len));
-    }
-}
+// static void
+// must_respond_to(ID mid, VALUE val, ID id)
+// {
+//     if (!rb_respond_to(val, mid)) {
+//  rb_raise(rb_eTypeError, "%s must have %s method, %s given",
+//       rb_id2name(id), rb_id2name(mid),
+//       rb_obj_classname(val));
+//     }
+// }
 
-void
-rb_write_error(const char *mesg)
-{
-    rb_write_error2(mesg, strlen(mesg));
-}
 
-static void
-must_respond_to(ID mid, VALUE val, ID id)
-{
-    if (!rb_respond_to(val, mid)) {
-	rb_raise(rb_eTypeError, "%s must have %s method, %s given",
-		 rb_id2name(id), rb_id2name(mid),
-		 rb_obj_classname(val));
-    }
-}
-
-static void
-stdout_setter(VALUE val, ID id, VALUE *variable)
-{
-    must_respond_to(id_write, val, id);
-    *variable = val;
-}
-
-static VALUE
-prep_io(int fd, int mode, VALUE klass, const char *path)
-{
-    rb_io_t *fp;
-    VALUE io = io_alloc(klass, 0);
-
-    MakeOpenFile(io, fp);
-    fp->fd = fd;
-    fp->mode = mode;
-    io_check_tty(fp);
-    if (path) {
-	fp->path = strdup(path);
-    }
-
-    return io;
-}
-
-VALUE
-rb_io_fdopen(int fd, int mode, const char *path)
-{
-    VALUE klass = rb_cIO;
-
-    if (path && strcmp(path, "-")) klass = rb_cFile;
-    return prep_io(fd, rb_io_modenum_flags(mode), klass, path);
-}
-
-static VALUE
-prep_stdio(FILE *f, int mode, VALUE klass, const char *path)
-{
-    rb_io_t *fptr;
-    VALUE io = prep_io(fileno(f), mode|FMODE_PREP, klass, path);
-
-    GetOpenFile(io, fptr);
-    fptr->stdio_file = f;
-
-    return io;
-}
-
-FILE *
-rb_io_stdio_file(rb_io_t *fptr)
-{
-    if (!fptr->stdio_file) {
-        fptr->stdio_file = rb_fdopen(fptr->fd, rb_io_flags_mode(fptr->mode));
-    }
-    return fptr->stdio_file;
-}
-
 /*
  *  call-seq:
  *     IO.new(fd, mode)   => io
@@ -5052,61 +1908,7 @@
 static VALUE
 rb_io_initialize(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    VALUE fnum, mode, orig;
-    rb_io_t *fp, *ofp = NULL;
-    int fd, fmode, flags = O_RDONLY;
-
-    rb_secure(4);
-    rb_scan_args(argc, argv, "11", &fnum, &mode);
-    if (argc == 2) {
-	if (FIXNUM_P(mode)) {
-	    flags = FIX2LONG(mode);
-	}
-	else {
-	    SafeStringValue(mode);
-	    flags = rb_io_mode_modenum(StringValueCStr(mode));
-	}
-    }
-    orig = rb_io_check_io(fnum);
-    if (NIL_P(orig)) {
-	fd = NUM2INT(fnum);
-        UPDATE_MAXFD(fd);
-	if (argc != 2) {
-#if defined(HAVE_FCNTL) && defined(F_GETFL)
-	    flags = fcntl(fd, F_GETFL);
-	    if (flags == -1) rb_sys_fail(0);
-#endif
-	}
-	MakeOpenFile(io, fp);
-        fp->fd = fd;
-	fp->mode = rb_io_modenum_flags(flags);
-        io_check_tty(fp);
-    }
-    else if (RFILE(io)->fptr) {
-	rb_raise(rb_eRuntimeError, "reinitializing IO");
-    }
-    else {
-	GetOpenFile(orig, ofp);
-	if (ofp->refcnt == LONG_MAX) {
-	    VALUE s = rb_inspect(orig);
-	    rb_raise(rb_eIOError, "too many shared IO for %s", StringValueCStr(s));
-	}
-	if (argc == 2) {
-	    fmode = rb_io_modenum_flags(flags);
-	    if ((ofp->mode ^ fmode) & (FMODE_READWRITE|FMODE_BINMODE)) {
-		if (FIXNUM_P(mode)) {
-		    rb_raise(rb_eArgError, "incompatible mode 0%o", flags);
-		}
-		else {
-		    rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING_BYTEPTR(mode));
-		}
-	    }
-	}
-	ofp->refcnt++;
-	GC_WB(&RFILE(io)->fptr, ofp);
-    }
-
-    return io;
+rb_notimplement();
 }
 
 
@@ -5131,25 +1933,12 @@
  *     f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
  */
 
-static VALUE
-rb_file_initialize(int argc, VALUE *argv, VALUE io)
-{
-    if (RFILE(io)->fptr) {
-	rb_raise(rb_eRuntimeError, "reinitializing File");
-    }
-    if (0 < argc && argc < 3) {
-	VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int");
+// static VALUE
+// rb_file_initialize(VALUE io, SEL sel, int argc, VALUE *argv)
+// {
+// rb_notimplement();
+// }
 
-	if (!NIL_P(fd)) {
-	    argv[0] = fd;
-	    return rb_io_initialize(io, 0, argc, argv);
-	}
-    }
-    rb_open_file(argc, argv, io);
-
-    return io;
-}
-
 /*
  *  call-seq:
  *     IO.new(fd, mode_string)   => io
@@ -5169,15 +1958,9 @@
  */
 
 static VALUE
-rb_io_s_new(int argc, VALUE *argv, VALUE klass)
+rb_io_s_new(VALUE klass, SEL sel, VALUE fd, VALUE mode)
 {
-    if (rb_block_given_p()) {
-	const char *cname = rb_class2name(klass);
-
-	rb_warn("%s::new() does not take block; use %s::open() instead",
-		cname, cname);
-    }
-    return rb_class_new_instance(argc, argv, klass);
+    rb_notimplement();
 }
 
 
@@ -5189,300 +1972,78 @@
  *
  */
 
-static VALUE
-rb_io_s_for_fd(int argc, VALUE *argv, VALUE klass)
-{
-    VALUE io = rb_obj_alloc(klass);
-    rb_io_initialize(io, 0, argc, argv);
-    return io;
-}
+// removed.
 
-static void
-argf_mark(void *ptr)
-{
-#if !WITH_OBJC
-    struct argf *p = ptr;
-#endif
-    rb_gc_mark(p->filename);
-    rb_gc_mark(p->current_file);
-    rb_gc_mark(p->lineno);
-    rb_gc_mark(p->argv);
-}
 
-static void
-argf_free(void *ptr)
-{
-    struct argf *p = ptr;
-    free(p->inplace);
-}
-
-static inline void
-argf_init(struct argf *p, VALUE v)
-{
-    p->filename = Qnil;
-    p->current_file = Qnil;
-    p->lineno = Qnil;
-    GC_WB(&p->argv, v);
-}
-
 static VALUE
 argf_alloc(VALUE klass)
 {
-    struct argf *p;
-    VALUE argf = Data_Make_Struct(klass, struct argf, argf_mark, argf_free, p);
-
-    argf_init(p, Qnil);
-    return argf;
+rb_notimplement();
 }
 
 #undef rb_argv
-#define filename          ARGF.filename
-#define current_file      ARGF.current_file
-#define gets_lineno       ARGF.gets_lineno
-#define init_p            ARGF.init_p
-#define next_p            ARGF.next_p
-#define lineno            ARGF.lineno
-#define ruby_inplace_mode ARGF.inplace
-#define argf_binmode      ARGF.binmode
-#define argf_enc          ARGF.enc
-#define argf_enc2         ARGF.enc2
 #define rb_argv           ARGF.argv
 
 static VALUE
 argf_initialize(VALUE argf, SEL sel, VALUE argv)
 {
-    memset(&ARGF, 0, sizeof(ARGF));
-    argf_init(&ARGF, argv);
-
-    return argf;
+rb_notimplement();
 }
 
 static VALUE
-argf_initialize_copy(VALUE argf, VALUE orig)
+argf_initialize_copy(VALUE argf, SEL sel, VALUE orig)
 {
-    ARGF = argf_of(orig);
-    GC_WB(&rb_argv, rb_obj_dup(rb_argv));
-    if (ARGF.inplace) {
-	const char *inplace = ARGF.inplace;
-	ARGF.inplace = 0;
-	GC_WB(&ARGF.inplace, ruby_strdup(inplace));
-    }
-    return argf;
+    rb_notimplement();
 }
 
 static VALUE
-argf_set_lineno(VALUE argf, VALUE val)
+argf_set_lineno(VALUE argf, SEL sel, VALUE val)
 {
-    gets_lineno = NUM2INT(val);
-    lineno = INT2FIX(gets_lineno);
-    return Qnil;
+rb_notimplement();
 }
 
 static VALUE
-argf_lineno(VALUE argf)
+argf_lineno(VALUE argf, SEL sel)
 {
-    return lineno;
+rb_notimplement();
 }
 
-static VALUE
-argf_forward(int argc, VALUE *argv, VALUE argf)
-{
-    return rb_funcall3(current_file, rb_frame_this_func(), argc, argv);
-}
+// static VALUE
+// argf_forward(VALUE argf, SEL sel, int argc, VALUE *argv)
+// {
+//     rb_notimplement();
+// }
+// 
+// static void
+// argf_close(VALUE file, SEL sel)
+// {
+//     rb_notimplement();
+// }
+// 
+// static int
+// argf_next_argv(VALUE argf, SEL sel)
+// {
+// rb_notimplement();
+// }
+// 
+// static VALUE
+// argf_getline(VALUE argf, SEL sel, int argc, VALUE *argv)
+// {
+// rb_notimplement();
+// }
 
-#define next_argv() argf_next_argv(argf)
-#define ARGF_GENERIC_INPUT_P() \
-    (current_file == rb_stdin && TYPE(current_file) != T_FILE)
-#define ARGF_FORWARD(argc, argv) do {\
-    if (ARGF_GENERIC_INPUT_P())\
-	return argf_forward(argc, argv, argf);\
-} while (0)
-#define NEXT_ARGF_FORWARD(argc, argv) do {\
-    if (!next_argv()) return Qnil;\
-    ARGF_FORWARD(argc, argv);\
-} while (0)
-
-static void
-argf_close(VALUE file)
-{
-    rb_funcall3(file, rb_intern("close"), 0, 0);
-}
-
-static int
-argf_next_argv(VALUE argf)
-{
-    char *fn;
-    rb_io_t *fptr;
-    int stdout_binmode = 0;
-
-    if (TYPE(rb_stdout) == T_FILE) {
-        GetOpenFile(rb_stdout, fptr);
-        if (fptr->mode & FMODE_BINMODE)
-            stdout_binmode = 1;
-    }
-
-    if (init_p == 0) {
-	if (!NIL_P(rb_argv) && RARRAY_LEN(rb_argv) > 0) {
-	    next_p = 1;
-	}
-	else {
-	    next_p = -1;
-	}
-	init_p = 1;
-	gets_lineno = 0;
-    }
-
-    if (next_p == 1) {
-	next_p = 0;
-      retry:
-	if (RARRAY_LEN(rb_argv) > 0) {
-	    filename = rb_ary_shift(rb_argv);
-	    fn = StringValueCStr(filename);
-	    if (strlen(fn) == 1 && fn[0] == '-') {
-		current_file = rb_stdin;
-		if (ruby_inplace_mode) {
-		    rb_warn("Can't do inplace edit for stdio; skipping");
-		    goto retry;
-		}
-	    }
-	    else {
-		int fr = rb_sysopen(fn, O_RDONLY, 0);
-
-		if (ruby_inplace_mode) {
-		    struct stat st;
-#ifndef NO_SAFE_RENAME
-		    struct stat st2;
-#endif
-		    VALUE str;
-		    int fw;
-
-		    if (TYPE(rb_stdout) == T_FILE && rb_stdout != orig_stdout) {
-			rb_io_close(rb_stdout);
-		    }
-		    fstat(fr, &st);
-		    if (*ruby_inplace_mode) {
-			str = rb_str_new2(fn);
-#ifdef NO_LONG_FNAME
-                        ruby_add_suffix(str, ruby_inplace_mode);
-#else
-			rb_str_cat2(str, ruby_inplace_mode);
-#endif
-#ifdef NO_SAFE_RENAME
-			(void)close(fr);
-			(void)unlink(RSTRING_PTR(str));
-			(void)rename(fn, RSTRING_PTR(str));
-			fr = rb_sysopen(RSTRING_PTR(str), O_RDONLY, 0);
-#else
-			if (rename(fn, RSTRING_PTR(str)) < 0) {
-			    rb_warn("Can't rename %s to %s: %s, skipping file",
-				    fn, RSTRING_PTR(str), strerror(errno));
-			    close(fr);
-			    goto retry;
-			}
-#endif
-		    }
-		    else {
-#ifdef NO_SAFE_RENAME
-			rb_fatal("Can't do inplace edit without backup");
-#else
-			if (unlink(fn) < 0) {
-			    rb_warn("Can't remove %s: %s, skipping file",
-				    fn, strerror(errno));
-			    close(fr);
-			    goto retry;
-			}
-#endif
-		    }
-		    fw = rb_sysopen(fn, O_WRONLY|O_CREAT|O_TRUNC, 0666);
-#ifndef NO_SAFE_RENAME
-		    fstat(fw, &st2);
-#ifdef HAVE_FCHMOD
-		    fchmod(fw, st.st_mode);
-#else
-		    chmod(fn, st.st_mode);
-#endif
-		    if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
-			fchown(fw, st.st_uid, st.st_gid);
-		    }
-#endif
-		    rb_stdout = prep_io(fw, FMODE_WRITABLE, rb_cFile, fn);
-		    if (stdout_binmode) rb_io_binmode(rb_stdout);
-		}
-		current_file = prep_io(fr, FMODE_READABLE, rb_cFile, fn);
-	    }
-	    if (argf_binmode) rb_io_binmode(current_file);
-	    if (argf_enc) {
-		rb_io_t *fptr;
-
-		GetOpenFile(current_file, fptr);
-		fptr->enc = argf_enc;
-		fptr->enc2 = argf_enc2;
-	    }
-	}
-	else {
-	    next_p = 1;
-	    return Qfalse;
-	}
-    }
-    else if (next_p == -1) {
-	current_file = rb_stdin;
-	filename = rb_str_new2("-");
-	if (ruby_inplace_mode) {
-	    rb_warn("Can't do inplace edit for stdio");
-	    rb_stdout = orig_stdout;
-	}
-    }
-    return Qtrue;
-}
-
 static VALUE
-argf_getline(int argc, VALUE *argv, VALUE argf)
-{
-    VALUE line;
-
-  retry:
-    if (!next_argv()) return Qnil;
-    if (ARGF_GENERIC_INPUT_P()) {
-	line = rb_funcall3(current_file, rb_intern("gets"), argc, argv);
-    }
-    else {
-	if (argc == 0 && rb_rs == rb_default_rs) {
-	    line = rb_io_gets(current_file);
-	}
-	else {
-	    line = rb_io_getline(argc, argv, current_file);
-	}
-	if (NIL_P(line) && next_p != -1) {
-	    argf_close(current_file);
-	    next_p = 1;
-	    goto retry;
-	}
-    }
-    if (!NIL_P(line)) {
-	gets_lineno++;
-	lineno = INT2FIX(gets_lineno);
-    }
-    return line;
-}
-
-static VALUE
 argf_lineno_getter(ID id, VALUE *var)
 {
-    VALUE argf = *var;
-    return lineno;
+rb_notimplement();
 }
 
 static void
 argf_lineno_setter(VALUE val, ID id, VALUE *var)
 {
-    VALUE argf = *var;
-    int n = NUM2INT(val);
-    gets_lineno = n;
-    lineno = INT2FIX(n);
+rb_notimplement();
 }
 
-static VALUE argf_gets(int, VALUE *, VALUE);
-
 /*
  *  call-seq:
  *     gets(sep=$/)    => string or nil
@@ -5517,52 +2078,17 @@
  */
 
 static VALUE
-rb_f_gets(int argc, VALUE *argv, VALUE recv)
+rb_f_gets(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    if (recv == argf) {
-	return argf_gets(argc, argv, argf);
-    }
-    return rb_funcall2(argf, rb_intern("gets"), argc, argv);
+rb_notimplement();
 }
 
 static VALUE
-argf_gets(int argc, VALUE *argv, VALUE argf)
+argf_gets(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    VALUE line;
-
-    line = argf_getline(argc, argv, argf);
-    rb_lastline_set(line);
-    return line;
+rb_notimplement();
 }
 
-VALUE
-rb_gets(void)
-{
-    VALUE line;
-
-    if (rb_rs != rb_default_rs) {
-	return rb_f_gets(0, 0, argf);
-    }
-
-  retry:
-    if (!next_argv()) return Qnil;
-    line = rb_io_gets(current_file);
-    if (NIL_P(line) && next_p != -1) {
-	rb_io_close(current_file);
-	next_p = 1;
-	goto retry;
-    }
-    rb_lastline_set(line);
-    if (!NIL_P(line)) {
-	gets_lineno++;
-	lineno = INT2FIX(gets_lineno);
-    }
-
-    return line;
-}
-
-static VALUE argf_readline(int, VALUE *, VALUE);
-
 /*
  *  call-seq:
  *     readline(sep=$/)     => string
@@ -5574,31 +2100,17 @@
  */
 
 static VALUE
-rb_f_readline(int argc, VALUE *argv, VALUE recv)
+rb_f_readline(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    if (recv == argf) {
-	return argf_readline(argc, argv, argf);
-    }
-    return rb_funcall2(argf, rb_intern("readline"), argc, argv);
+rb_notimplement();
 }
 
 static VALUE
-argf_readline(int argc, VALUE *argv, VALUE argf)
+argf_readline(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    VALUE line;
-
-    if (!next_argv()) rb_eof_error();
-    ARGF_FORWARD(argc, argv);
-    line = argf_gets(argc, argv, argf);
-    if (NIL_P(line)) {
-	rb_eof_error();
-    }
-
-    return line;
+rb_notimplement();
 }
 
-static VALUE argf_readlines(int, VALUE *, VALUE);
-
 /*
  *  call-seq:
  *     readlines(sep=$/)    => array
@@ -5610,25 +2122,15 @@
  */
 
 static VALUE
-rb_f_readlines(int argc, VALUE *argv, VALUE recv)
+rb_f_readlines(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    if (recv == argf) {
-	return argf_readlines(argc, argv, argf);
-    }
-    return rb_funcall2(argf, rb_intern("readlines"), argc, argv);
+rb_notimplement();
 }
 
 static VALUE
-argf_readlines(int argc, VALUE *argv, VALUE argf)
+argf_readlines(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    VALUE line, ary;
-
-    ary = rb_ary_new();
-    while (!NIL_P(line = argf_getline(argc, argv, argf))) {
-	rb_ary_push(ary, line);
-    }
-
-    return ary;
+rb_notimplement();
 }
 
 /*
@@ -5648,180 +2150,23 @@
 static VALUE
 rb_f_backquote(VALUE obj, SEL sel, VALUE str)
 {
-    volatile VALUE port;
-    VALUE result;
-    rb_io_t *fptr;
-
-    SafeStringValue(str);
-    port = pipe_open_s(str, "r");
-    if (NIL_P(port)) return rb_str_new(0,0);
-
-    GetOpenFile(port, fptr);
-    result = read_all(fptr, remain_size(fptr), Qnil);
-    rb_io_close(port);
-
-    return result;
+rb_notimplement();
 }
 
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
 
-static VALUE
-select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
-{
-    VALUE res, list;
-    fd_set *rp, *wp, *ep;
-    rb_io_t *fptr;
-    long i;
-    int max = 0, n;
-    int interrupt_flag = 0;
-    int pending = 0;
-    struct timeval timerec;
+// static VALUE
+// select_call(VALUE arg)
+// {
+// rb_notimplement();
+// }
+// 
+// static VALUE
+// select_end(VALUE arg)
+// {
+// rb_notimplement();
+// }
 
-    if (!NIL_P(read)) {
-	Check_Type(read, T_ARRAY);
-	for (i=0; i<RARRAY_LEN(read); i++) {
-	    GetOpenFile(rb_io_get_io(RARRAY_AT(read, i)), fptr);
-	    rb_fd_set(fptr->fd, &fds[0]);
-	    if (READ_DATA_PENDING(fptr)) { /* check for buffered data */
-		pending++;
-		rb_fd_set(fptr->fd, &fds[3]);
-	    }
-	    if (max < fptr->fd) max = fptr->fd;
-	}
-	if (pending) {		/* no blocking if there's buffered data */
-	    timerec.tv_sec = timerec.tv_usec = 0;
-	    tp = &timerec;
-	}
-	rp = rb_fd_ptr(&fds[0]);
-    }
-    else
-	rp = 0;
 
-    if (!NIL_P(write)) {
-	Check_Type(write, T_ARRAY);
-	for (i=0; i<RARRAY_LEN(write); i++) {
-            VALUE write_io = GetWriteIO(rb_io_get_io(RARRAY_AT(write, i)));
-	    GetOpenFile(write_io, fptr);
-	    rb_fd_set(fptr->fd, &fds[1]);
-	    if (max < fptr->fd) max = fptr->fd;
-	}
-	wp = rb_fd_ptr(&fds[1]);
-    }
-    else
-	wp = 0;
-
-    if (!NIL_P(except)) {
-	Check_Type(except, T_ARRAY);
-	for (i=0; i<RARRAY_LEN(except); i++) {
-            VALUE io = rb_io_get_io(RARRAY_AT(except, i));
-            VALUE write_io = GetWriteIO(io);
-	    GetOpenFile(io, fptr);
-	    rb_fd_set(fptr->fd, &fds[2]);
-	    if (max < fptr->fd) max = fptr->fd;
-            if (io != write_io) {
-                GetOpenFile(write_io, fptr);
-                rb_fd_set(fptr->fd, &fds[2]);
-                if (max < fptr->fd) max = fptr->fd;
-            }
-	}
-	ep = rb_fd_ptr(&fds[2]);
-    }
-    else {
-	ep = 0;
-    }
-
-    max++;
-
-    n = rb_thread_select(max, rp, wp, ep, tp);
-    if (n < 0) {
-	rb_sys_fail(0);
-    }
-    if (!pending && n == 0) return Qnil; /* returns nil on timeout */
-
-    res = rb_ary_new2(3);
-    rb_ary_push(res, rp?rb_ary_new():rb_ary_new2(0));
-    rb_ary_push(res, wp?rb_ary_new():rb_ary_new2(0));
-    rb_ary_push(res, ep?rb_ary_new():rb_ary_new2(0));
-
-    if (interrupt_flag == 0) {
-	if (rp) {
-	    list = RARRAY_AT(res, 0);
-	    for (i=0; i< RARRAY_LEN(read); i++) {
-                VALUE obj = rb_ary_entry(read, i);
-                VALUE io = rb_io_get_io(obj);
-		GetOpenFile(io, fptr);
-		if (rb_fd_isset(fptr->fd, &fds[0]) ||
-		    rb_fd_isset(fptr->fd, &fds[3])) {
-		    rb_ary_push(list, obj);
-		}
-	    }
-	}
-
-	if (wp) {
-	    list = RARRAY_AT(res, 1);
-	    for (i=0; i< RARRAY_LEN(write); i++) {
-                VALUE obj = rb_ary_entry(write, i);
-                VALUE io = rb_io_get_io(obj);
-                VALUE write_io = GetWriteIO(io);
-		GetOpenFile(write_io, fptr);
-		if (rb_fd_isset(fptr->fd, &fds[1])) {
-		    rb_ary_push(list, obj);
-		}
-	    }
-	}
-
-	if (ep) {
-	    list = RARRAY_AT(res, 2);
-	    for (i=0; i< RARRAY_LEN(except); i++) {
-                VALUE obj = rb_ary_entry(except, i);
-                VALUE io = rb_io_get_io(obj);
-                VALUE write_io = GetWriteIO(io);
-		GetOpenFile(io, fptr);
-		if (rb_fd_isset(fptr->fd, &fds[2])) {
-		    rb_ary_push(list, obj);
-		}
-                else if (io != write_io) {
-                    GetOpenFile(write_io, fptr);
-                    if (rb_fd_isset(fptr->fd, &fds[2])) {
-                        rb_ary_push(list, obj);
-                    }
-                }
-	    }
-	}
-    }
-
-    return res;			/* returns an empty array on interrupt */
-}
-
-struct select_args {
-    VALUE read, write, except;
-    struct timeval *timeout;
-    rb_fdset_t fdsets[4];
-};
-
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-select_call(VALUE arg)
-{
-    struct select_args *p = (struct select_args *)arg;
-
-    return select_internal(p->read, p->write, p->except, p->timeout, p->fdsets);
-}
-
-static VALUE
-select_end(VALUE arg)
-{
-    struct select_args *p = (struct select_args *)arg;
-    int i;
-
-    for (i = 0; i < sizeof(p->fdsets) / sizeof(p->fdsets[0]); ++i)
-	rb_fd_term(&p->fdsets[i]);
-    return Qnil;
-}
-#endif
-
 /*
  *  call-seq:
  *     IO.select(read_array
@@ -5833,136 +2178,11 @@
  */
 
 static VALUE
-rb_f_select(int argc, VALUE *argv, VALUE obj)
+rb_f_select(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    VALUE timeout;
-    struct select_args args;
-    struct timeval timerec;
-    int i;
-
-    rb_scan_args(argc, argv, "13", &args.read, &args.write, &args.except, &timeout);
-    if (NIL_P(timeout)) {
-	args.timeout = 0;
-    }
-    else {
-	timerec = rb_time_interval(timeout);
-	args.timeout = &timerec;
-    }
-
-    for (i = 0; i < sizeof(args.fdsets) / sizeof(args.fdsets[0]); ++i)
-	rb_fd_init(&args.fdsets[i]);
-
-#ifdef HAVE_RB_FD_INIT
-    return rb_ensure(select_call, (VALUE)&args, select_end, (VALUE)&args);
-#else
-    return select_internal(args.read, args.write, args.except,
-			   args.timeout, args.fdsets);
-#endif
-
+rb_notimplement();
 }
 
-#if !defined(MSDOS) && !defined(__human68k__)
-static int
-io_cntl(int fd, int cmd, long narg, int io_p)
-{
-    int retval;
-
-#ifdef HAVE_FCNTL
-    TRAP_BEG;
-# if defined(__CYGWIN__)
-    retval = io_p?ioctl(fd, cmd, (void*)narg):fcntl(fd, cmd, narg);
-# else
-    retval = io_p?ioctl(fd, cmd, narg):fcntl(fd, cmd, narg);
-# endif
-    TRAP_END;
-#else
-    if (!io_p) {
-	rb_notimplement();
-    }
-    TRAP_BEG;
-    retval = ioctl(fd, cmd, narg);
-    TRAP_END;
-#endif
-    return retval;
-}
-#endif
-
-static VALUE
-rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
-{
-#if !defined(MSDOS) && !defined(__human68k__)
-    int cmd = NUM2ULONG(req);
-    rb_io_t *fptr;
-    long len = 0;
-    long narg = 0;
-    int retval;
-
-    rb_secure(2);
-
-    if (NIL_P(arg) || arg == Qfalse) {
-	narg = 0;
-    }
-    else if (FIXNUM_P(arg)) {
-	narg = FIX2LONG(arg);
-    }
-    else if (arg == Qtrue) {
-	narg = 1;
-    }
-    else {
-	VALUE tmp = rb_check_string_type(arg);
-
-	if (NIL_P(tmp)) {
-	    narg = NUM2LONG(arg);
-	}
-	else {
-	    arg = tmp;
-#ifdef IOCPARM_MASK
-#ifndef IOCPARM_LEN
-#define IOCPARM_LEN(x)  (((x) >> 16) & IOCPARM_MASK)
-#endif
-#endif
-#ifdef IOCPARM_LEN
-	    len = IOCPARM_LEN(cmd);	/* on BSDish systems we're safe */
-#else
-	    len = 256;		/* otherwise guess at what's safe */
-#endif
-	    rb_str_modify(arg);
-
-	    if (len <= RSTRING_BYTELEN(arg)) {
-		len = RSTRING_BYTELEN(arg);
-	    }
-	    if (RSTRING_BYTELEN(arg) < len) {
-		rb_str_resize(arg, len+1);
-	    }
-	    RSTRING_BYTEPTR(arg)[len] = 17;	/* a little sanity check here */
-	    narg = (long)RSTRING_BYTEPTR(arg);
-	}
-    }
-    GetOpenFile(io, fptr);
-    retval = io_cntl(fptr->fd, cmd, narg, io_p);
-    if (retval < 0) rb_sys_fail(fptr->path);
-    if (TYPE(arg) == T_STRING && RSTRING_BYTEPTR(arg)[len] != 17) {
-	rb_raise(rb_eArgError, "return value overflowed string");
-    }
-
-    if (!io_p && cmd == F_SETFL) {
-      if (narg & O_NONBLOCK) {
-        fptr->mode |= FMODE_WSPLIT_INITIALIZED;
-        fptr->mode &= ~FMODE_WSPLIT;
-      }
-      else {
-        fptr->mode &= ~(FMODE_WSPLIT_INITIALIZED|FMODE_WSPLIT);
-      }
-    }
-
-    return INT2NUM(retval);
-#else
-    rb_notimplement();
-    return Qnil;		/* not reached */
-#endif
-}
-
-
 /*
  *  call-seq:
  *     ios.ioctl(integer_cmd, arg)    => integer
@@ -5976,12 +2196,9 @@
  */
 
 static VALUE
-rb_io_ioctl(int argc, VALUE *argv, VALUE io)
+rb_io_ioctl(VALUE recv, SEL sel, VALUE integer_cmd, VALUE arg)
 {
-    VALUE req, arg;
-
-    rb_scan_args(argc, argv, "11", &req, &arg);
-    return rb_io_ctl(io, req, arg, 1);
+rb_notimplement();
 }
 
 /*
@@ -5998,17 +2215,9 @@
  */
 
 static VALUE
-rb_io_fcntl(int argc, VALUE *argv, VALUE io)
+rb_io_fcntl(VALUE recv, SEL sel, VALUE integer_cmd, VALUE arg)
 {
-#ifdef HAVE_FCNTL
-    VALUE req, arg;
-
-    rb_scan_args(argc, argv, "11", &req, &arg);
-    return rb_io_ctl(io, req, arg, 0);
-#else
-    rb_notimplement();
-    return Qnil;		/* not reached */
-#endif
+rb_notimplement();
 }
 
 /*
@@ -6031,136 +2240,10 @@
  */
 
 static VALUE
-rb_f_syscall(int argc, VALUE *argv)
+rb_f_syscall(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-#if defined(HAVE_SYSCALL) && !defined(__CHECKER__)
-#ifdef atarist
-    unsigned long arg[14]; /* yes, we really need that many ! */
-#else
-    unsigned long arg[8];
-#endif
-    int retval = -1;
-    int i = 1;
-    int items = argc - 1;
-
-    /* This probably won't work on machines where sizeof(long) != sizeof(int)
-     * or where sizeof(long) != sizeof(char*).  But such machines will
-     * not likely have syscall implemented either, so who cares?
-     */
-
-    rb_secure(2);
-    if (argc == 0)
-	rb_raise(rb_eArgError, "too few arguments for syscall");
-    if (argc > sizeof(arg) / sizeof(arg[0]))
-	rb_raise(rb_eArgError, "too many arguments for syscall");
-    arg[0] = NUM2LONG(argv[0]); argv++;
-    while (items--) {
-	VALUE v = rb_check_string_type(*argv);
-
-	if (!NIL_P(v)) {
-	    StringValue(v);
-	    rb_str_modify(v);
-	    arg[i] = (unsigned long)StringValueCStr(v);
-	}
-	else {
-	    arg[i] = (unsigned long)NUM2LONG(*argv);
-	}
-	argv++;
-	i++;
-    }
-    TRAP_BEG;
-    switch (argc) {
-      case 1:
-	retval = syscall(arg[0]);
-	break;
-      case 2:
-	retval = syscall(arg[0],arg[1]);
-	break;
-      case 3:
-	retval = syscall(arg[0],arg[1],arg[2]);
-	break;
-      case 4:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3]);
-	break;
-      case 5:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4]);
-	break;
-      case 6:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
-	break;
-      case 7:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
-	break;
-      case 8:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
-	  arg[7]);
-	break;
-#ifdef atarist
-      case 9:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
-	  arg[7], arg[8]);
-	break;
-      case 10:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
-	  arg[7], arg[8], arg[9]);
-	break;
-      case 11:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
-	  arg[7], arg[8], arg[9], arg[10]);
-	break;
-      case 12:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
-	  arg[7], arg[8], arg[9], arg[10], arg[11]);
-	break;
-      case 13:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
-	  arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
-	break;
-      case 14:
-	retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
-	  arg[7], arg[8], arg[9], arg[10], arg[11], arg[12], arg[13]);
-	break;
-#endif /* atarist */
-    }
-    TRAP_END;
-    if (retval < 0) rb_sys_fail(0);
-    return INT2NUM(retval);
-#else
     rb_notimplement();
-    return Qnil;		/* not reached */
-#endif
 }
-
-static VALUE
-io_new_instance(VALUE args)
-{
-    return rb_class_new_instance(2, (VALUE*)args+1, *(VALUE*)args);
-}
-
-static void
-io_encoding_set(rb_io_t *fptr, int argc, VALUE v1, VALUE v2)
-{
-    if (NIL_P(v2)) argc = 1;
-    if (argc == 2) {
-	fptr->enc2 = rb_to_encoding(v1);
-	fptr->enc = rb_to_encoding(v2);
-    }
-    else if (argc == 1) {
-	if (NIL_P(v1)) {
-	    fptr->enc = 0;
-	}
-	else {
-	    VALUE tmp = rb_check_string_type(v1);
-	    if (!NIL_P(tmp)) {
-		mode_enc(fptr, StringValueCStr(tmp));
-	    }
-	    else {
-		fptr->enc = rb_to_encoding(v1);
-	    }
-	}
-    }
-}
-
 /*
  *  call-seq:
  *     IO.pipe                    -> [read_io, write_io]
@@ -6211,133 +2294,11 @@
  */
 
 static VALUE
-rb_io_s_pipe(int argc, VALUE *argv, VALUE klass)
+rb_io_s_pipe(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-#ifdef __human68k__
-    rb_notimplement();
-    return Qnil;		/* not reached */
-#else
-    int pipes[2], state;
-    VALUE r, w, args[3], v1, v2;
-    rb_io_t *fptr;
-
-    rb_scan_args(argc, argv, "02", &v1, &v2);
-    if (pipe(pipes) == -1)
-	rb_sys_fail(0);
-    UPDATE_MAXFD_PIPE(pipes);
-
-    args[0] = klass;
-    args[1] = INT2NUM(pipes[0]);
-    args[2] = INT2FIX(O_RDONLY);
-    r = rb_protect(io_new_instance, (VALUE)args, &state);
-#if 0
-    if (state) {
-	close(pipes[0]);
-	close(pipes[1]);
-	rb_jump_tag(state);
-    }
-#endif
-    GetOpenFile(r, fptr);
-    io_encoding_set(fptr, argc, v1, v2);
-    args[1] = INT2NUM(pipes[1]);
-    args[2] = INT2FIX(O_WRONLY);
-    w = rb_protect(io_new_instance, (VALUE)args, &state);
-#if 0
-    if (state) {
-	close(pipes[1]);
-	if (!NIL_P(r)) rb_io_close(r);
-	rb_jump_tag(state);
-    }
-#endif
-    rb_io_synchronized(RFILE(w)->fptr);
-
-    return rb_assoc_new(r, w);
-#endif
+rb_notimplement();
 }
 
-struct foreach_arg {
-    int argc;
-    VALUE *argv;
-    VALUE io;
-};
-
-static void
-open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
-{
-    VALUE opt, v;
-    static VALUE encoding, mode, open_args;
-
-    FilePathValue(argv[0]);
-    arg->io = 0;
-    arg->argc = argc > 1 ? 1 : 0;
-    arg->argv = argv + 1;
-    if (argc == 1) {
-      no_key:
-	arg->io = rb_io_open(RSTRING_PTR(argv[0]), "r");
-	return;
-    }
-    opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
-    if (NIL_P(opt)) goto no_key;
-    if (argc > 2) arg->argc = 1;
-    else arg->argc = 0;
-    if (!encoding) {
-	ID id;
-
-	id = rb_intern("encoding");
-	encoding = ID2SYM(id);
-	id = rb_intern("mode");
-	mode = ID2SYM(id);
-	id = rb_intern("open_args");
-	open_args = ID2SYM(id);
-    }
-    v = rb_hash_aref(opt, open_args);
-    if (!NIL_P(v)) {
-	v = rb_convert_type(v, T_ARRAY, "Array", "to_ary");
-#if WITH_OBJC
-	long i, v_len = RARRAY_LEN(v);
-	VALUE *values = (VALUE *)alloca(v_len + 1);
-	values[0] = argv[0];
-	for (i = 0; i < v_len; i++)
-	    values[i + 1] = RARRAY_AT(v, i);
-	arg->io = rb_io_open_with_args(v_len + 1, values);
-#else
-	VALUE args;
-	args = rb_ary_new2(RARRAY_LEN(v)+1);
-	rb_ary_push(args, argv[0]);
-	rb_ary_concat(args, v);
-	MEMCPY(RARRAY_PTR(args)+1, RARRAY_PTR(v), VALUE, RARRAY_LEN(v));
-	arg->io = rb_io_open_with_args(RARRAY_LEN(args), RARRAY_PTR(args));
-#endif
-	return;
-    }
-    v = rb_hash_aref(opt, mode);
-    if (!NIL_P(v)) {
-	arg->io = rb_io_open(RSTRING_PTR(argv[0]), StringValueCStr(v));
-    }
-    else {
-	arg->io = rb_io_open(RSTRING_PTR(argv[0]), "r");
-    }
-
-    v = rb_hash_aref(opt, encoding);
-    if (!NIL_P(v)) {
-	rb_io_t *fptr;
-	GetOpenFile(arg->io, fptr);
-        mode_enc(fptr, StringValueCStr(v));
-    }
-}
-
-static VALUE
-io_s_foreach(struct foreach_arg *arg)
-{
-    VALUE str;
-
-    while (!NIL_P(str = rb_io_gets_m(arg->io, 0, arg->argc, arg->argv))) {
-	rb_yield(str);
-	RETURN_IF_BROKEN();
-    }
-    return Qnil;
-}
-
 /*
  *  call-seq:
  *     IO.foreach(name, sep=$/) {|line| block }     => nil
@@ -6362,23 +2323,11 @@
  */
 
 static VALUE
-rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
+rb_io_s_foreach(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    struct foreach_arg arg;
-
-    rb_scan_args(argc, argv, "13", NULL, NULL, NULL, NULL);
-    RETURN_ENUMERATOR(self, argc, argv);
-    open_key_args(argc, argv, &arg);
-    if (NIL_P(arg.io)) return Qnil;
-    return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
+rb_notimplement();
 }
 
-static VALUE
-io_s_readlines(struct foreach_arg *arg)
-{
-    return rb_io_readlines(arg->io, 0, arg->argc, arg->argv);
-}
-
 /*
  *  call-seq:
  *     IO.readlines(name, sep=$/)     => array
@@ -6398,22 +2347,11 @@
  */
 
 static VALUE
-rb_io_s_readlines(VALUE io, SEL sel, int argc, VALUE *argv)
+rb_io_s_readlines(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    struct foreach_arg arg;
-
-    rb_scan_args(argc, argv, "13", NULL, NULL, NULL, NULL);
-    open_key_args(argc, argv, &arg);
-    if (NIL_P(arg.io)) return Qnil;
-    return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
+rb_notimplement();
 }
 
-static VALUE
-io_s_read(struct foreach_arg *arg)
-{
-    return io_read(arg->argc, arg->argv, arg->io);
-}
-
 /*
  *  call-seq:
  *     IO.read(name, [length [, offset]] )   => string
@@ -6447,492 +2385,11 @@
  */
 
 static VALUE
-rb_io_s_read(int argc, VALUE *argv, VALUE io)
+rb_io_s_read(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-    VALUE offset;
-    struct foreach_arg arg;
-
-    rb_scan_args(argc, argv, "13", NULL, NULL, &offset, NULL);
-    open_key_args(argc, argv, &arg);
-    if (NIL_P(arg.io)) return Qnil;
-    if (!NIL_P(offset)) {
-	rb_io_binmode(arg.io);
-	rb_io_seek(arg.io, offset, SEEK_SET);
-	if (arg.argc == 2) arg.argc = 1;
-    }
-    return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
+rb_notimplement();
 }
 
-struct copy_stream_struct {
-    VALUE src;
-    VALUE dst;
-    off_t copy_length; /* (off_t)-1 if not specified */
-    off_t src_offset; /* (off_t)-1 if not specified */
-
-    int src_fd;
-    int dst_fd;
-    int close_src;
-    int close_dst;
-    off_t total;
-    const char *syserr;
-    int error_no;
-    const char *notimp;
-    rb_fdset_t fds;
-    //rb_thread_t *th;
-};
-
-static int
-copy_stream_wait_read(struct copy_stream_struct *stp)
-{
-    int ret;
-    rb_fd_zero(&stp->fds);
-    rb_fd_set(stp->src_fd, &stp->fds);
-    ret = rb_fd_select(rb_fd_max(&stp->fds), &stp->fds, NULL, NULL, NULL);
-    if (ret == -1) {
-        stp->syserr = "select";
-        stp->error_no = errno;
-        return -1;
-    }
-    return 0;
-}
-
-static int
-copy_stream_wait_write(struct copy_stream_struct *stp)
-{
-    int ret;
-    rb_fd_zero(&stp->fds);
-    rb_fd_set(stp->dst_fd, &stp->fds);
-    ret = rb_fd_select(rb_fd_max(&stp->fds), NULL, &stp->fds, NULL, NULL);
-    if (ret == -1) {
-        stp->syserr = "select";
-        stp->error_no = errno;
-        return -1;
-    }
-    return 0;
-}
-
-#ifdef HAVE_SENDFILE
-
-#ifdef __linux__
-#define USE_SENDFILE
-
-#ifdef HAVE_SYS_SENDFILE_H
-#include <sys/sendfile.h>
-#endif
-
-static ssize_t
-simple_sendfile(int out_fd, int in_fd, off_t *offset, size_t count)
-{
-    return sendfile(out_fd, in_fd, offset, count);
-}
-
-#endif
-
-#endif
-
-#ifdef USE_SENDFILE
-static int
-copy_stream_sendfile(struct copy_stream_struct *stp)
-{
-    struct stat src_stat, dst_stat;
-    ssize_t ss;
-    int ret;
-
-    off_t copy_length;
-    off_t src_offset;
-    int use_pread;
-
-    ret = fstat(stp->src_fd, &src_stat);
-    if (ret == -1) {
-        stp->syserr = "fstat";
-        stp->error_no = errno;
-        return -1;
-    }
-    if (!S_ISREG(src_stat.st_mode))
-        return 0;
-
-    ret = fstat(stp->dst_fd, &dst_stat);
-    if (ret == -1) {
-        stp->syserr = "fstat";
-        stp->error_no = errno;
-        return -1;
-    }
-    if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
-        return 0;
-
-    src_offset = stp->src_offset;
-    use_pread = src_offset != (off_t)-1;
-
-    copy_length = stp->copy_length;
-    if (copy_length == (off_t)-1) {
-        if (use_pread)
-            copy_length = src_stat.st_size - src_offset;
-        else {
-            off_t cur = lseek(stp->src_fd, 0, SEEK_CUR);
-            if (cur == (off_t)-1) {
-                stp->syserr = "lseek";
-                stp->error_no = errno;
-                return -1;
-            }
-            copy_length = src_stat.st_size - cur;
-        }
-    }
-
-retry_sendfile:
-    if (use_pread) {
-        ss = simple_sendfile(stp->dst_fd, stp->src_fd, &src_offset, copy_length);
-    }
-    else {
-        ss = simple_sendfile(stp->dst_fd, stp->src_fd, NULL, copy_length);
-    }
-    if (0 < ss) {
-        stp->total += ss;
-        copy_length -= ss;
-        if (0 < copy_length) {
-            ss = -1;
-            errno = EAGAIN;
-        }
-    }
-    if (ss == -1) {
-        if (errno == EINVAL || errno == ENOSYS)
-            return 0;
-        if (errno == EAGAIN || errno == EWOULDBLOCK) {
-            if (copy_stream_wait_write(stp) == -1)
-                return -1;
-            goto retry_sendfile;
-        }
-        stp->syserr = "sendfile";
-        stp->error_no = errno;
-        return -1;
-    }
-    return 1;
-}
-#endif
-
-static ssize_t
-copy_stream_read(struct copy_stream_struct *stp, char *buf, int len, off_t offset)
-{
-    ssize_t ss;
-retry_read:
-    if (offset == (off_t)-1)
-        ss = read(stp->src_fd, buf, len);
-    else {
-#ifdef HAVE_PREAD
-        ss = pread(stp->src_fd, buf, len, offset);
-#else
-        stp->notimp = "pread";
-        return -1;
-#endif
-    }
-    if (ss == 0) {
-        return 0;
-    }
-    if (ss == -1) {
-        if (errno == EAGAIN || errno == EWOULDBLOCK) {
-            if (copy_stream_wait_read(stp) == -1)
-                return -1;
-            goto retry_read;
-        }
-        if (errno == ENOSYS) {
-            stp->notimp = "pread";
-            return -1;
-        }
-        stp->syserr = offset == (off_t)-1 ?  "read" : "pread";
-        stp->error_no = errno;
-        return -1;
-    }
-    return ss;
-}
-
-static int
-copy_stream_write(struct copy_stream_struct *stp, char *buf, int len)
-{
-    ssize_t ss;
-    int off = 0;
-    while (len) {
-        ss = write(stp->dst_fd, buf+off, len);
-        if (ss == -1) {
-            if (errno == EAGAIN || errno == EWOULDBLOCK) {
-                if (copy_stream_wait_write(stp) == -1)
-                    return -1;
-                continue;
-            }
-            stp->syserr = "write";
-            stp->error_no = errno;
-            return -1;
-        }
-        off += ss;
-        len -= ss;
-        stp->total += ss;
-    }
-    return 0;
-}
-
-static void
-copy_stream_read_write(struct copy_stream_struct *stp)
-{
-    char buf[1024*16];
-    int len;
-    ssize_t ss;
-    int ret;
-    off_t copy_length;
-    int use_eof;
-    off_t src_offset;
-    int use_pread;
-
-    copy_length = stp->copy_length;
-    use_eof = copy_length == (off_t)-1;
-    src_offset = stp->src_offset;
-    use_pread = src_offset != (off_t)-1;
-
-    if (use_pread && stp->close_src) {
-        off_t r;
-        r = lseek(stp->src_fd, src_offset, SEEK_SET);
-        if (r == (off_t)-1) {
-            stp->syserr = "lseek";
-            stp->error_no = errno;
-            return;
-        }
-        src_offset = (off_t)-1;
-        use_pread = 0;
-    }
-
-    while (use_eof || 0 < copy_length) {
-        if (!use_eof && copy_length < sizeof(buf)) {
-            len = copy_length;
-        }
-        else {
-            len = sizeof(buf);
-        }
-        if (use_pread) {
-            ss = copy_stream_read(stp, buf, len, src_offset);
-            if (0 < ss)
-                src_offset += ss;
-        }
-        else {
-            ss = copy_stream_read(stp, buf, len, (off_t)-1);
-        }
-        if (ss <= 0) /* EOF or error */
-            return;
-
-        ret = copy_stream_write(stp, buf, ss);
-        if (ret < 0)
-            return;
-
-        if (!use_eof)
-            copy_length -= ss;
-    }
-}
-
-static VALUE
-copy_stream_func(void *arg)
-{
-    struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
-#ifdef USE_SENDFILE
-    int ret;
-#endif
-
-#ifdef USE_SENDFILE
-    ret = copy_stream_sendfile(stp);
-    if (ret != 0)
-        goto finish; /* error or success */
-#endif
-
-    copy_stream_read_write(stp);
-
-#ifdef USE_SENDFILE
-finish:
-#endif
-    return Qnil;
-}
-
-static VALUE
-copy_stream_fallback_body(VALUE arg)
-{
-    struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
-    const int buflen = 16*1024;
-    VALUE n;
-    VALUE buf = rb_str_buf_new(buflen);
-    long rest = stp->copy_length;
-    off_t off = stp->src_offset;
-
-    while (1) {
-        long numwrote;
-        long l;
-        if (stp->copy_length == (off_t)-1) {
-            l = buflen;
-        }
-        else {
-            if (rest == 0)
-                break;
-            l = buflen < rest ? buflen : rest;
-        }
-        if (stp->src_fd == -1) {
-            rb_funcall(stp->src, id_readpartial, 2, INT2FIX(l), buf);
-        }
-        else {
-            ssize_t ss;
-            rb_thread_wait_fd(stp->src_fd);
-            rb_str_resize(buf, buflen);
-            ss = copy_stream_read(stp, RSTRING_BYTEPTR(buf), l, off);
-            if (ss == -1)
-                return Qnil;
-            if (ss == 0)
-                rb_eof_error();
-            rb_str_resize(buf, ss);
-            if (off != (off_t)-1)
-                off += ss;
-        }
-        n = rb_io_write(stp->dst, buf);
-        numwrote = NUM2LONG(n);
-        stp->total += numwrote;
-        rest -= numwrote;
-    }
-
-    return Qnil;
-}
-
-static VALUE
-copy_stream_fallback(struct copy_stream_struct *stp)
-{
-    if (stp->src_fd == -1 && stp->src_offset != (off_t)-1) {
-	rb_raise(rb_eArgError, "cannot specify src_offset for non-IO");
-    }
-    rb_rescue2(copy_stream_fallback_body, (VALUE)stp,
-               (VALUE (*) (ANYARGS))0, (VALUE)0,
-               rb_eEOFError, (VALUE)0);
-    return Qnil;
-}
-
-static VALUE
-copy_stream_body(VALUE arg)
-{
-    struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
-    VALUE src_io, dst_io;
-    rb_io_t *src_fptr = 0, *dst_fptr = 0;
-    int src_fd, dst_fd;
-
-    stp->total = 0;
-
-    if (stp->src == argf ||
-        !(TYPE(stp->src) == T_FILE ||
-          rb_respond_to(stp->src, rb_intern("to_io")) ||
-          TYPE(stp->src) == T_STRING ||
-          rb_respond_to(stp->src, rb_intern("to_path")))) {
-        src_fd = -1;
-    }
-    else {
-        src_io = rb_check_convert_type(stp->src, T_FILE, "IO", "to_io");
-        if (NIL_P(src_io)) {
-            VALUE args[2];
-            int flags = O_RDONLY;
-#ifdef O_NOCTTY
-            flags |= O_NOCTTY;
-#endif
-            FilePathValue(stp->src);
-            args[0] = stp->src;
-            args[1] = INT2NUM(flags);
-            src_io = rb_class_new_instance(2, args, rb_cFile);
-            stp->src = src_io;
-            stp->close_src = 1;
-        }
-        GetOpenFile(src_io, src_fptr);
-        rb_io_check_readable(src_fptr);
-        src_fd = src_fptr->fd;
-    }
-    stp->src_fd = src_fd;
-
-    if (stp->dst == argf ||
-        !(TYPE(stp->dst) == T_FILE ||
-          rb_respond_to(stp->dst, rb_intern("to_io")) ||
-          TYPE(stp->dst) == T_STRING ||
-          rb_respond_to(stp->dst, rb_intern("to_path")))) {
-        dst_fd = -1;
-    }
-    else {
-        dst_io = rb_check_convert_type(stp->dst, T_FILE, "IO", "to_io");
-        if (NIL_P(dst_io)) {
-            VALUE args[3];
-            int flags = O_WRONLY|O_CREAT|O_TRUNC;
-#ifdef O_NOCTTY
-            flags |= O_NOCTTY;
-#endif
-            FilePathValue(stp->dst);
-            args[0] = stp->dst;
-            args[1] = INT2NUM(flags);
-            args[2] = INT2FIX(0600);
-            dst_io = rb_class_new_instance(3, args, rb_cFile);
-            stp->dst = dst_io;
-            stp->close_dst = 1;
-        }
-        else {
-            dst_io = GetWriteIO(dst_io);
-            stp->dst = dst_io;
-        }
-        GetOpenFile(dst_io, dst_fptr);
-        rb_io_check_writable(dst_fptr);
-        dst_fd = dst_fptr->fd;
-    }
-    stp->dst_fd = dst_fd;
-
-    if (stp->src_offset == (off_t)-1 && src_fptr && src_fptr->rbuf_len) {
-        long len = src_fptr->rbuf_len;
-        VALUE str;
-        if (stp->copy_length != (off_t)-1 && stp->copy_length < len) {
-            len = stp->copy_length;
-        }
-        str = rb_str_buf_new(len);
-        rb_str_resize(str,len);
-        read_buffered_data(RSTRING_BYTEPTR(str), len, src_fptr);
-        if (dst_fptr) /* IO or filename */
-            io_fwrite(str, dst_fptr);
-        else /* others such as StringIO */
-            rb_io_write(stp->dst, str);
-        stp->total += len;
-        if (stp->copy_length != (off_t)-1)
-            stp->copy_length -= len;
-    }
-
-    if (dst_fptr && io_fflush(dst_fptr) < 0) {
-	rb_raise(rb_eIOError, "flush failed");
-    }
-
-    if (stp->copy_length == 0)
-        return Qnil;
-
-    if (src_fd == -1 || dst_fd == -1) {
-        return copy_stream_fallback(stp);
-    }
-
-    rb_fd_init(&stp->fds);
-    rb_fd_set(src_fd, &stp->fds);
-    rb_fd_set(dst_fd, &stp->fds);
-
-    return copy_stream_func((void *)stp);
-    //return rb_thread_blocking_region(copy_stream_func, (void*)stp, RB_UBF_DFL, 0);
-}
-
-static VALUE
-copy_stream_finalize(VALUE arg)
-{
-    struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
-    if (stp->close_src) {
-        rb_io_close_m(stp->src);
-    }
-    if (stp->close_dst) {
-        rb_io_close_m(stp->dst);
-    }
-    rb_fd_term(&stp->fds);
-    if (stp->syserr) {
-        errno = stp->error_no;
-        rb_sys_fail(stp->syserr);
-    }
-    if (stp->notimp) {
-	rb_raise(rb_eNotImpError, "%s() not implemented", stp->notimp);
-    }
-    return Qnil;
-}
-
 /*
  *  call-seq:
  *     IO.copy_stream(src, dst)
@@ -6962,35 +2419,9 @@
  *
  */
 static VALUE
-rb_io_s_copy_stream(int argc, VALUE *argv, VALUE io)
+rb_io_s_copy_stream(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    VALUE src, dst, length, src_offset;
-    struct copy_stream_struct *st;
-
-    st = xmalloc(sizeof(struct copy_stream_struct));
-
-    rb_scan_args(argc, argv, "22", &src, &dst, &length, &src_offset);
-
-    st->src = src;
-    st->dst = dst;
-
-    if (NIL_P(length)) {
-        st->copy_length = (off_t)-1;
-    }
-    else {
-        st->copy_length = NUM2OFFT(length);
-    }
-
-    if (NIL_P(src_offset)) {
-        st->src_offset = (off_t)-1;
-    }
-    else {
-        st->src_offset = NUM2OFFT(src_offset);
-    }
-
-    rb_ensure(copy_stream_body, (VALUE)st, copy_stream_finalize, (VALUE)st);
-
-    return OFFT2NUM(st->total);
+rb_notimplement();
 }
 
 /*
@@ -7002,23 +2433,9 @@
  */
 
 static VALUE
-rb_io_external_encoding(VALUE io)
+rb_io_external_encoding(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    if (fptr->enc2) {
-	return rb_enc_from_encoding(fptr->enc2);
-    }
-    if (!fptr->enc && fptr->fd == 0) {
-	fptr->enc = rb_default_external_encoding();
-    }
-    if (fptr->mode & FMODE_WRITABLE) {
-	if (fptr->enc)
-	    return rb_enc_from_encoding(fptr->enc);
-	return Qnil;
-    }
-    return rb_enc_from_encoding(io_read_encoding(fptr));
+rb_notimplement();
 }
 
 /*
@@ -7030,13 +2447,9 @@
  */
 
 static VALUE
-rb_io_internal_encoding(VALUE io)
+rb_io_internal_encoding(VALUE io, SEL sel)
 {
-    rb_io_t *fptr;
-
-    GetOpenFile(io, fptr);
-    if (!fptr->enc2) return Qnil;
-    return rb_enc_from_encoding(io_read_encoding(fptr));
+rb_notimplement();
 }
 
 /*
@@ -7055,164 +2468,75 @@
  */
 
 static VALUE
-rb_io_set_encoding(int argc, VALUE *argv, VALUE io)
+rb_io_set_encoding(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    rb_io_t *fptr;
-    VALUE v1, v2;
-
-    rb_scan_args(argc, argv, "11", &v1, &v2);
-    GetOpenFile(io, fptr);
-    io_encoding_set(fptr, argc, v1, v2);
-    return io;
+rb_notimplement();
 }
 
 static VALUE
-argf_external_encoding(VALUE argf)
+argf_external_encoding(VALUE argf, SEL sel)
 {
-    if (!RTEST(current_file)) {
-	return rb_enc_from_encoding(rb_default_external_encoding());
-    }
-    return rb_io_external_encoding(rb_io_check_io(current_file));
+rb_notimplement();
 }
 
 static VALUE
-argf_internal_encoding(VALUE argf)
+argf_internal_encoding(VALUE argf, SEL sel)
 {
-    if (!RTEST(current_file)) {
-	return rb_enc_from_encoding(rb_default_external_encoding());
-    }
-    return rb_io_internal_encoding(rb_io_check_io(current_file));
+rb_notimplement();
 }
 
 static VALUE
-argf_set_encoding(int argc, VALUE *argv, VALUE argf)
+argf_set_encoding(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    rb_io_t *fptr;
-
-    if (!next_argv()) {
-	rb_raise(rb_eArgError, "no stream to set encoding");
-    }
-    rb_io_set_encoding(argc, argv, current_file);
-    GetOpenFile(current_file, fptr);
-    argf_enc = fptr->enc;
-    argf_enc2 = fptr->enc2;
-    return argf;
+rb_notimplement();
 }
 
 static VALUE
-argf_tell(VALUE argf)
+argf_tell(VALUE argf, SEL sel)
 {
-    if (!next_argv()) {
-	rb_raise(rb_eArgError, "no stream to tell");
-    }
-    ARGF_FORWARD(0, 0);
-    return rb_io_tell(current_file);
+rb_notimplement();
 }
 
 static VALUE
-argf_seek_m(int argc, VALUE *argv, VALUE argf)
+argf_seek_m(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    if (!next_argv()) {
-	rb_raise(rb_eArgError, "no stream to seek");
-    }
-    ARGF_FORWARD(argc, argv);
-    return rb_io_seek_m(argc, argv, current_file);
+rb_notimplement();
 }
 
 static VALUE
-argf_set_pos(VALUE argf, VALUE offset)
+argf_set_pos(VALUE argf, SEL sel, VALUE offset)
 {
-    if (!next_argv()) {
-	rb_raise(rb_eArgError, "no stream to set position");
-    }
-    ARGF_FORWARD(1, &offset);
-    return rb_io_set_pos(current_file, offset);
+rb_notimplement();
 }
 
 static VALUE
-argf_rewind(VALUE argf)
+argf_rewind(VALUE argf, SEL sel)
 {
-    if (!next_argv()) {
-	rb_raise(rb_eArgError, "no stream to rewind");
-    }
-    ARGF_FORWARD(0, 0);
-    return rb_io_rewind(current_file);
+rb_notimplement();
 }
 
 static VALUE
-argf_fileno(VALUE argf)
+argf_fileno(VALUE argf, SEL sel)
 {
-    if (!next_argv()) {
-	rb_raise(rb_eArgError, "no stream");
-    }
-    ARGF_FORWARD(0, 0);
-    return rb_io_fileno(current_file, 0);
+rb_notimplement();
 }
 
 static VALUE
-argf_to_io(VALUE argf)
+argf_to_io(VALUE argf, SEL sel)
 {
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return current_file;
+rb_notimplement();
 }
 
-static VALUE
-argf_eof(VALUE argf)
+static VALUE 
+argf_eof(VALUE argf, SEL sel)
 {
-    if (current_file) {
-	if (init_p == 0) return Qtrue;
-	ARGF_FORWARD(0, 0);
-	if (rb_io_eof(current_file)) {
-	    return Qtrue;
-	}
-    }
-    return Qfalse;
+rb_notimplement();
 }
 
 static VALUE
-argf_read(int argc, VALUE *argv, VALUE argf)
+argf_read(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    VALUE tmp, str, length;
-    long len = 0;
-
-    rb_scan_args(argc, argv, "02", &length, &str);
-    if (!NIL_P(length)) {
-	len = NUM2LONG(argv[0]);
-    }
-    if (!NIL_P(str)) {
-	StringValue(str);
-	rb_str_resize(str,0);
-	argv[1] = Qnil;
-    }
-
-  retry:
-    if (!next_argv()) {
-	return str;
-    }
-    if (ARGF_GENERIC_INPUT_P()) {
-	tmp = argf_forward(argc, argv, argf);
-    }
-    else {
-	tmp = io_read(argc, argv, current_file);
-    }
-    if (NIL_P(str)) str = tmp;
-    else if (!NIL_P(tmp)) rb_str_append(str, tmp);
-    if (NIL_P(tmp) || NIL_P(length)) {
-	if (next_p != -1) {
-	    argf_close(current_file);
-	    next_p = 1;
-	    goto retry;
-	}
-    }
-    else if (argc >= 1) {
-	if (RSTRING_BYTELEN(str) < len) {
-	    len -= RSTRING_BYTELEN(str);
-	    argv[0] = INT2NUM(len);
-	    goto retry;
-	}
-    }
-    return str;
+rb_notimplement();
 }
 
 struct argf_call_arg {
@@ -7221,299 +2545,160 @@
     VALUE argf;
 };
 
-static VALUE
-argf_forward_call(VALUE arg)
-{
-    struct argf_call_arg *p = (struct argf_call_arg *)arg;
-    argf_forward(p->argc, p->argv, p->argf);
-    return Qnil;
-}
+// static VALUE
+// argf_forward_call(VALUE arg, SEL sel)
+// {
+// rb_notimplement();
+// }
 
 static VALUE
-argf_readpartial(int argc, VALUE *argv, VALUE argf)
+argf_readpartial(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    VALUE tmp, str, length;
-
-    rb_scan_args(argc, argv, "11", &length, &str);
-    if (!NIL_P(str)) {
-        StringValue(str);
-        argv[1] = str;
-    }
-
-    if (!next_argv()) {
-        rb_str_resize(str, 0);
-        rb_eof_error();
-    }
-    if (ARGF_GENERIC_INPUT_P()) {
-	struct argf_call_arg arg;
-	arg.argc = argc;
-	arg.argv = argv;
-	arg.argf = argf;
-	tmp = rb_rescue2(argf_forward_call, (VALUE)&arg,
-			 RUBY_METHOD_FUNC(0), Qnil, rb_eEOFError, (VALUE)0);
-    }
-    else {
-        tmp = io_getpartial(argc, argv, current_file, 0);
-    }
-    if (NIL_P(tmp)) {
-        if (next_p == -1) {
-            rb_eof_error();
-        }
-        argf_close(current_file);
-        next_p = 1;
-        if (RARRAY_LEN(rb_argv) == 0)
-            rb_eof_error();
-        if (NIL_P(str))
-            str = rb_str_new(NULL, 0);
-        return str;
-    }
-    return tmp;
+rb_notimplement();
 }
 
 static VALUE
-argf_getc(VALUE argf)
+argf_getc(VALUE argf, SEL sel)
 {
-    VALUE ch;
-
-  retry:
-    if (!next_argv()) return Qnil;
-    if (ARGF_GENERIC_INPUT_P()) {
-	ch = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
-    }
-    else {
-	ch = rb_io_getc(current_file);
-    }
-    if (NIL_P(ch) && next_p != -1) {
-	argf_close(current_file);
-	next_p = 1;
-	goto retry;
-    }
-
-    return ch;
+rb_notimplement();
 }
 
 static VALUE
-argf_getbyte(VALUE argf)
+argf_getbyte(VALUE argf, SEL sel)
 {
-    VALUE ch;
-
-  retry:
-    if (!next_argv()) return Qnil;
-    if (TYPE(current_file) != T_FILE) {
-	ch = rb_funcall3(current_file, rb_intern("getbyte"), 0, 0);
-    }
-    else {
-	ch = rb_io_getbyte(current_file);
-    }
-    if (NIL_P(ch) && next_p != -1) {
-	argf_close(current_file);
-	next_p = 1;
-	goto retry;
-    }
-
-    return ch;
+rb_notimplement();
 }
 
 static VALUE
-argf_readchar(VALUE argf)
+argf_readchar(VALUE argf, SEL sel)
 {
-    VALUE ch;
-
-  retry:
-    if (!next_argv()) rb_eof_error();
-    if (TYPE(current_file) != T_FILE) {
-	ch = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
-    }
-    else {
-	ch = rb_io_getc(current_file);
-    }
-    if (NIL_P(ch) && next_p != -1) {
-	argf_close(current_file);
-	next_p = 1;
-	goto retry;
-    }
-
-    return ch;
+rb_notimplement();
 }
 
 static VALUE
 argf_readbyte(VALUE argf)
 {
-    VALUE c;
-
-    NEXT_ARGF_FORWARD(0, 0);
-    c = argf_getbyte(argf);
-    if (NIL_P(c)) {
-	rb_eof_error();
-    }
-    return c;
+rb_notimplement();
 }
 
 static VALUE
-argf_each_line(int argc, VALUE *argv, VALUE argf)
+argf_each_line(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    RETURN_ENUMERATOR(argf, argc, argv);
-    for (;;) {
-	if (!next_argv()) return Qnil;
-	rb_block_call(current_file, rb_intern("each_line"), 0, 0, rb_yield, 0);
-	next_p = 1;
-    }
-    return argf;
+rb_notimplement();
 }
 
 static VALUE
-argf_each_byte(VALUE argf)
+argf_each_byte(VALUE argf, SEL sel)
 {
-    RETURN_ENUMERATOR(argf, 0, 0);
-    for (;;) {
-	if (!next_argv()) return Qnil;
-	rb_block_call(current_file, rb_intern("each_byte"), 0, 0, rb_yield, 0);
-	next_p = 1;
-    }
+rb_notimplement();
 }
 
 static VALUE
-argf_each_char(VALUE argf)
+argf_each_char(VALUE argf, SEL sel)
 {
-    RETURN_ENUMERATOR(argf, 0, 0);
-    for (;;) {
-	if (!next_argv()) return Qnil;
-	rb_block_call(current_file, rb_intern("each_char"), 0, 0, rb_yield, 0);
-	next_p = 1;
-    }
+rb_notimplement();
 }
 
 static VALUE
-argf_filename(VALUE argf)
+argf_filename(VALUE argf, SEL sel)
 {
-    next_argv();
-    return filename;
+rb_notimplement();
 }
 
 static VALUE
 argf_filename_getter(ID id, VALUE *var)
 {
-    return argf_filename(*var);
+rb_notimplement();
 }
 
 static VALUE
-argf_file(VALUE argf)
+argf_file(VALUE argf, SEL sel)
 {
-    next_argv();
-    return current_file;
+rb_notimplement();
 }
 
 static VALUE
-argf_binmode_m(VALUE argf)
+argf_binmode_m(VALUE argf, SEL sel)
 {
-    argf_binmode = 1;
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    rb_io_binmode(current_file);
-    return argf;
+rb_notimplement();
 }
 
 static VALUE
-argf_skip(VALUE argf)
+argf_skip(VALUE argf, SEL sel)
 {
-    if (next_p != -1) {
-	argf_close(current_file);
-	next_p = 1;
-    }
-    return argf;
+rb_notimplement();
 }
 
 static VALUE
-argf_close_m(VALUE argf)
+argf_close_m(VALUE argf, SEL sel)
 {
-    next_argv();
-    argf_close(current_file);
-    if (next_p != -1) {
-	next_p = 1;
-    }
-    gets_lineno = 0;
-    return argf;
+rb_notimplement();
 }
 
 static VALUE
-argf_closed(VALUE argf)
+argf_closed(VALUE argf, SEL sel)
 {
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return rb_io_closed(current_file);
+rb_notimplement();
 }
 
 static VALUE
-argf_to_s(VALUE argf)
+argf_to_s(VALUE argf, SEL sel)
 {
-    return rb_str_new2("ARGF");
+rb_notimplement();
 }
 
 static VALUE
 argf_inplace_mode_get(VALUE argf)
 {
-    if (!ruby_inplace_mode) return Qnil;
-    return rb_str_new2(ruby_inplace_mode);
+rb_notimplement();
 }
 
 static VALUE
 opt_i_get(ID id, VALUE *var)
 {
-    return argf_inplace_mode_get(*var);
+rb_notimplement();
 }
 
 static VALUE
 argf_inplace_mode_set(VALUE argf, VALUE val)
 {
-    if (!RTEST(val)) {
-	if (ruby_inplace_mode) free(ruby_inplace_mode);
-	ruby_inplace_mode = 0;
-    }
-    else {
-	StringValue(val);
-	if (ruby_inplace_mode) free(ruby_inplace_mode);
-	ruby_inplace_mode = 0;
-	ruby_inplace_mode = strdup(RSTRING_BYTEPTR(val));
-    }
-    return argf;
+rb_notimplement();
 }
 
 static void
 opt_i_set(VALUE val, ID id, VALUE *var)
 {
-    argf_inplace_mode_set(*var, val);
+rb_notimplement();
 }
 
 const char *
 ruby_get_inplace_mode(void)
 {
-    return ruby_inplace_mode;
+rb_notimplement();
 }
 
 void
 ruby_set_inplace_mode(const char *suffix)
 {
-    if (ruby_inplace_mode) free(ruby_inplace_mode);
-    ruby_inplace_mode = 0;
-    if (suffix) ruby_inplace_mode = strdup(suffix);
+rb_notimplement();
 }
 
 static VALUE
 argf_argv(VALUE argf)
 {
-    return rb_argv;
+rb_notimplement();
 }
 
 static VALUE
 argf_argv_getter(ID id, VALUE *var)
 {
-    return argf_argv(*var);
+rb_notimplement();
 }
 
 VALUE
 rb_get_argv(void)
 {
-    return rb_argv;
+rb_notimplement();
 }
 
 /*
@@ -7591,23 +2776,42 @@
  *  the methods <code>#path</code> and <code>#filename</code> to access
  *  the name of the file currently being read.
  */
+ 
+ 
+void
+rb_write_error2(const char *mesg, long len)
+{
+    rb_notimplement();
+}
 
 void
+rb_write_error(const char *mesg)
+{
+    rb_notimplement();
+}
+
+static void
+must_respond_to(ID mid, VALUE val, ID id)
+{
+    if (!rb_respond_to(val, mid)) {
+	rb_raise(rb_eTypeError, "%s must have %s method, %s given",
+		 rb_id2name(id), rb_id2name(mid),
+		 rb_obj_classname(val));
+    }
+}
+
+
+static void
+stdout_setter(VALUE val, ID id, VALUE *variable)
+{
+    must_respond_to(id_write, val, id);
+    *variable = val;
+}
+
+void
 Init_IO(void)
 {
     VALUE rb_cARGF;
-#ifdef __CYGWIN__
-#include <sys/cygwin.h>
-    static struct __cygwin_perfile pf[] =
-    {
-	{"", O_RDONLY | O_BINARY},
-	{"", O_WRONLY | O_BINARY},
-	{"", O_RDWR | O_BINARY},
-	{"", O_APPEND | O_BINARY},
-	{NULL, 0}
-    };
-    cygwin_internal(CW_PERFILE, pf);
-#endif
 
     rb_eIOError = rb_define_class("IOError", rb_eStandardError);
     rb_eEOFError = rb_define_class("EOFError", rb_eIOError);
@@ -7619,40 +2823,40 @@
     id_encode = rb_intern("encode");
     id_readpartial = rb_intern("readpartial");
 
-    rb_define_global_function("syscall", rb_f_syscall, -1);
+    rb_objc_define_method(rb_mKernel, "syscall", rb_f_syscall, -1);
 
-    rb_define_global_function("open", rb_f_open, -1);
+    rb_objc_define_method(rb_mKernel, "open", rb_f_open, -1);
     rb_objc_define_method(rb_mKernel, "printf", rb_f_printf, -1);
     rb_objc_define_method(rb_mKernel, "print", rb_f_print, -1);
-    rb_define_global_function("putc", rb_f_putc, 1);
+    rb_objc_define_method(rb_mKernel, "putc", rb_f_putc, 1);
     rb_objc_define_method(rb_mKernel, "puts", rb_f_puts, -1);
-    rb_define_global_function("gets", rb_f_gets, -1);
-    rb_define_global_function("readline", rb_f_readline, -1);
-    rb_define_global_function("select", rb_f_select, -1);
+    rb_objc_define_method(rb_mKernel, "gets", rb_f_gets, -1);
+    rb_objc_define_method(rb_mKernel, "readline", rb_f_readline, -1);
+    rb_objc_define_method(rb_mKernel, "select", rb_f_select, -1);
 
-    rb_define_global_function("readlines", rb_f_readlines, -1);
+    rb_objc_define_method(rb_mKernel, "readlines", rb_f_readlines, -1);
 
     rb_objc_define_method(rb_mKernel, "`", rb_f_backquote, 1);
 
     rb_objc_define_method(rb_mKernel, "p", rb_f_p, -1);
-    rb_define_method(rb_mKernel, "display", rb_obj_display, -1);
+    rb_objc_define_method(rb_mKernel, "display", rb_obj_display, -1);
 
     rb_cIO = rb_define_class("IO", rb_cObject);
     rb_include_module(rb_cIO, rb_mEnumerable);
 
     rb_objc_define_method(*(VALUE *)rb_cIO, "alloc", io_alloc, 0);
-    rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
-    rb_define_singleton_method(rb_cIO, "open",  rb_io_s_open, -1);
-    rb_define_singleton_method(rb_cIO, "sysopen",  rb_io_s_sysopen, -1);
-    rb_define_singleton_method(rb_cIO, "for_fd", rb_io_s_for_fd, -1);
-    rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
-    rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "new", rb_io_s_new, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "open",  rb_io_s_open, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "sysopen",  rb_io_s_sysopen, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "for_fd", rb_io_s_new, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "popen", rb_io_s_popen, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "foreach", rb_io_s_foreach, -1);
     rb_objc_define_method(*(VALUE *)rb_cIO, "readlines", rb_io_s_readlines, -1);
-    rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
-    rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1);
-    rb_define_singleton_method(rb_cIO, "pipe", rb_io_s_pipe, -1);
-    rb_define_singleton_method(rb_cIO, "try_convert", rb_io_s_try_convert, 1);
-    rb_define_singleton_method(rb_cIO, "copy_stream", rb_io_s_copy_stream, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "read", rb_io_s_read, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "select", rb_f_select, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "pipe", rb_io_s_pipe, -1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "try_convert", rb_io_s_try_convert, 1);
+    rb_objc_define_method(*(VALUE *)rb_cIO, "copy_stream", rb_io_s_copy_stream, -1);
 
     rb_objc_define_method(rb_cIO, "initialize", rb_io_initialize, -1);
 
@@ -7669,99 +2873,104 @@
 
     rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
 
-    rb_define_method(rb_cIO, "initialize_copy", rb_io_init_copy, 1);
-    rb_define_method(rb_cIO, "reopen", rb_io_reopen, -1);
+    rb_objc_define_method(rb_cIO, "initialize_copy", rb_io_init_copy, 1);
+    rb_objc_define_method(rb_cIO, "reopen", rb_io_reopen, -1);
 
-    rb_define_method(rb_cIO, "print", rb_io_print, -1);
-    rb_define_method(rb_cIO, "putc", rb_io_putc, 1);
+    rb_objc_define_method(rb_cIO, "print", rb_io_print, -1);
+    rb_objc_define_method(rb_cIO, "putc", rb_io_putc, 1);
     rb_objc_define_method(rb_cIO, "puts", rb_io_puts, -1);
-    rb_define_method(rb_cIO, "printf", rb_io_printf, -1);
+    rb_objc_define_method(rb_cIO, "printf", rb_io_printf, -1);
 
-    rb_define_method(rb_cIO, "each",  rb_io_each_line, -1);
-    rb_define_method(rb_cIO, "each_line",  rb_io_each_line, -1);
-    rb_define_method(rb_cIO, "each_byte",  rb_io_each_byte, 0);
-    rb_define_method(rb_cIO, "each_char",  rb_io_each_char, 0);
-    rb_define_method(rb_cIO, "lines",  rb_io_lines, -1);
-    rb_define_method(rb_cIO, "bytes",  rb_io_bytes, 0);
-    rb_define_method(rb_cIO, "chars",  rb_io_chars, 0);
+    rb_objc_define_method(rb_cIO, "each",  rb_io_each_line, -1);
+    rb_objc_define_method(rb_cIO, "each_line",  rb_io_each_line, -1);
+    rb_objc_define_method(rb_cIO, "each_byte",  rb_io_each_byte, 0);
+    rb_objc_define_method(rb_cIO, "each_char",  rb_io_each_char, 0);
+    rb_objc_define_method(rb_cIO, "lines",  rb_io_lines, -1);
+    rb_objc_define_method(rb_cIO, "bytes",  rb_io_bytes, 0);
+    rb_objc_define_method(rb_cIO, "chars",  rb_io_chars, 0);
 
-    rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
-    rb_define_method(rb_cIO, "sysread",  rb_io_sysread, -1);
+    rb_objc_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
+    rb_objc_define_method(rb_cIO, "sysread",  rb_io_sysread, -1);
 
     rb_objc_define_method(rb_cIO, "fileno", rb_io_fileno, 0);
     rb_define_alias(rb_cIO, "to_i", "fileno");
-    rb_define_method(rb_cIO, "to_io", rb_io_to_io, 0);
+    rb_objc_define_method(rb_cIO, "to_io", rb_io_to_io, 0);
 
-    rb_define_method(rb_cIO, "fsync",   rb_io_fsync, 0);
-    rb_define_method(rb_cIO, "sync",   rb_io_sync, 0);
-    rb_define_method(rb_cIO, "sync=",  rb_io_set_sync, 1);
+    rb_objc_define_method(rb_cIO, "fsync",   rb_io_fsync, 0);
+    rb_objc_define_method(rb_cIO, "sync",   rb_io_sync, 0);
+    rb_objc_define_method(rb_cIO, "sync=",  rb_io_set_sync, 1);
 
-    rb_define_method(rb_cIO, "lineno",   rb_io_lineno, 0);
-    rb_define_method(rb_cIO, "lineno=",  rb_io_set_lineno, 1);
+    rb_objc_define_method(rb_cIO, "lineno",   rb_io_lineno, 0);
+    rb_objc_define_method(rb_cIO, "lineno=",  rb_io_set_lineno, 1);
 
     rb_objc_define_method(rb_cIO, "readlines",  rb_io_readlines, -1);
 
-    rb_define_method(rb_cIO, "read_nonblock",  io_read_nonblock, -1);
-    rb_define_method(rb_cIO, "write_nonblock", rb_io_write_nonblock, 1);
-    rb_define_method(rb_cIO, "readpartial",  io_readpartial, -1);
-    rb_define_method(rb_cIO, "read",  io_read, -1);
+    rb_objc_define_method(rb_cIO, "read_nonblock",  io_read_nonblock, -1);
+    rb_objc_define_method(rb_cIO, "write_nonblock", rb_io_write_nonblock, 1);
+    rb_objc_define_method(rb_cIO, "readpartial",  io_readpartial, -1);
+    rb_objc_define_method(rb_cIO, "read",  io_read, -1);
     rb_objc_define_method(rb_cIO, "write", io_write, 1);
     rb_objc_define_method(rb_cIO, "gets",  rb_io_gets_m, -1);
-    rb_define_method(rb_cIO, "readline",  rb_io_readline, -1);
-    rb_define_method(rb_cIO, "getc",  rb_io_getc, 0);
-    rb_define_method(rb_cIO, "getbyte",  rb_io_getbyte, 0);
-    rb_define_method(rb_cIO, "readchar",  rb_io_readchar, 0);
-    rb_define_method(rb_cIO, "readbyte",  rb_io_readbyte, 0);
-    rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
-    rb_define_method(rb_cIO, "<<",    rb_io_addstr, 1);
-    rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
-    rb_define_method(rb_cIO, "tell", rb_io_tell, 0);
-    rb_define_method(rb_cIO, "seek", rb_io_seek_m, -1);
+    rb_objc_define_method(rb_cIO, "readline",  rb_io_readline, -1);
+    rb_objc_define_method(rb_cIO, "getc",  rb_io_getc, 0);
+    rb_objc_define_method(rb_cIO, "getbyte",  rb_io_getbyte, 0);
+    rb_objc_define_method(rb_cIO, "readchar",  rb_io_readchar, 0);
+    rb_objc_define_method(rb_cIO, "readbyte",  rb_io_readbyte, 0);
+    rb_objc_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
+    rb_objc_define_method(rb_cIO, "<<",    rb_io_addstr, 1);
+    rb_objc_define_method(rb_cIO, "flush", rb_io_flush, 0);
+    rb_objc_define_method(rb_cIO, "tell", rb_io_tell, 0);
+    rb_objc_define_method(rb_cIO, "seek", rb_io_seek_m, -1);
     rb_define_const(rb_cIO, "SEEK_SET", INT2FIX(SEEK_SET));
     rb_define_const(rb_cIO, "SEEK_CUR", INT2FIX(SEEK_CUR));
     rb_define_const(rb_cIO, "SEEK_END", INT2FIX(SEEK_END));
-    rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0);
-    rb_define_method(rb_cIO, "pos", rb_io_tell, 0);
-    rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);
-    rb_define_method(rb_cIO, "eof", rb_io_eof, 0);
-    rb_define_method(rb_cIO, "eof?", rb_io_eof, 0);
+    rb_objc_define_method(rb_cIO, "rewind", rb_io_rewind, 0);
+    rb_objc_define_method(rb_cIO, "pos", rb_io_tell, 0);
+    rb_objc_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);
+    rb_objc_define_method(rb_cIO, "eof", rb_io_eof, 0);
+    rb_objc_define_method(rb_cIO, "eof?", rb_io_eof, 0);
 
-    rb_define_method(rb_cIO, "close_on_exec?", rb_io_close_on_exec_p, 0);
-    rb_define_method(rb_cIO, "close_on_exec=", rb_io_set_close_on_exec, 1);
+    rb_objc_define_method(rb_cIO, "close_on_exec?", rb_io_close_on_exec_p, 0);
+    rb_objc_define_method(rb_cIO, "close_on_exec=", rb_io_set_close_on_exec, 1);
 
-    rb_define_method(rb_cIO, "close", rb_io_close_m, 0);
-    rb_define_method(rb_cIO, "closed?", rb_io_closed, 0);
-    rb_define_method(rb_cIO, "close_read", rb_io_close_read, 0);
-    rb_define_method(rb_cIO, "close_write", rb_io_close_write, 0);
+    rb_objc_define_method(rb_cIO, "close", rb_io_close_m, 0);
+    rb_objc_define_method(rb_cIO, "closed?", rb_io_closed, 0);
+    rb_objc_define_method(rb_cIO, "close_read", rb_io_close_read, 0);
+    rb_objc_define_method(rb_cIO, "close_write", rb_io_close_write, 0);
 
-    rb_define_method(rb_cIO, "isatty", rb_io_isatty, 0);
-    rb_define_method(rb_cIO, "tty?", rb_io_isatty, 0);
-    rb_define_method(rb_cIO, "binmode",  rb_io_binmode_m, 0);
-    rb_define_method(rb_cIO, "sysseek", rb_io_sysseek, -1);
+    rb_objc_define_method(rb_cIO, "isatty", rb_io_isatty, 0);
+    rb_objc_define_method(rb_cIO, "tty?", rb_io_isatty, 0);
+    rb_objc_define_method(rb_cIO, "binmode",  rb_io_binmode_m, 0);
+    rb_objc_define_method(rb_cIO, "sysseek", rb_io_sysseek, -1);
 
-    rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
-    rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
-    rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
-    rb_define_method(rb_cIO, "inspect",  rb_io_inspect, 0);
+    rb_objc_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
+    rb_objc_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
+    rb_objc_define_method(rb_cIO, "pid", rb_io_pid, 0);
+    rb_objc_define_method(rb_cIO, "inspect",  rb_io_inspect, 0);
 
-    rb_define_method(rb_cIO, "external_encoding", rb_io_external_encoding, 0);
-    rb_define_method(rb_cIO, "internal_encoding", rb_io_internal_encoding, 0);
-    rb_define_method(rb_cIO, "set_encoding", rb_io_set_encoding, -1);
+    rb_objc_define_method(rb_cIO, "external_encoding", rb_io_external_encoding, 0);
+    rb_objc_define_method(rb_cIO, "internal_encoding", rb_io_internal_encoding, 0);
+    rb_objc_define_method(rb_cIO, "set_encoding", rb_io_set_encoding, -1);
 
-    rb_define_variable("$stdin", &rb_stdin);
+
+    // TODO: Replace these with their real equivalents - they're nil now.
     rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
-    rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);
+    rb_define_variable("$stdin", &rb_stdin);
+    rb_define_global_const("STDIN", rb_stdin);
+    
     rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO, "<STDOUT>");
-    rb_define_hooked_variable("$stderr", &rb_stderr, 0, stdout_setter);
-    rb_stderr = prep_stdio(stderr, FMODE_WRITABLE|FMODE_SYNC, rb_cIO, "<STDERR>");
+    rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);
     rb_define_hooked_variable("$>", &rb_stdout, 0, stdout_setter);
+    rb_define_global_const("STDOUT", rb_stdout);
+    
+    rb_stderr = prep_stdio(stderr, FMODE_WRITABLE|FMODE_SYNC, rb_cIO, "<STDERR>");
+    rb_define_hooked_variable("$stderr", &rb_stderr, 0, stdout_setter);
+    rb_define_global_const("STDERR", rb_stderr);
+    
+
     orig_stdout = rb_stdout;
     rb_deferr = orig_stderr = rb_stderr;
 
-    /* constants to hold original stdin/stdout/stderr */
-    rb_define_global_const("STDIN", rb_stdin);
-    rb_define_global_const("STDOUT", rb_stdout);
-    rb_define_global_const("STDERR", rb_stderr);
 
     rb_cARGF = rb_class_new(rb_cObject);
     rb_set_class_path(rb_cARGF, rb_cObject, "ARGF.class");
@@ -7770,100 +2979,96 @@
     rb_include_module(rb_cARGF, rb_mEnumerable);
 
     rb_objc_define_method(rb_cARGF, "initialize", argf_initialize, -2);
-    rb_define_method(rb_cARGF, "initialize_copy", argf_initialize_copy, 1);
-    rb_define_method(rb_cARGF, "to_s", argf_to_s, 0);
-    rb_define_method(rb_cARGF, "argv", argf_argv, 0);
+    rb_objc_define_method(rb_cARGF, "initialize_copy", argf_initialize_copy, 1);
+    rb_objc_define_method(rb_cARGF, "to_s", argf_to_s, 0);
+    rb_objc_define_method(rb_cARGF, "argv", argf_argv, 0);
 
-    rb_define_method(rb_cARGF, "fileno", argf_fileno, 0);
-    rb_define_method(rb_cARGF, "to_i", argf_fileno, 0);
-    rb_define_method(rb_cARGF, "to_io", argf_to_io, 0);
-    rb_define_method(rb_cARGF, "each",  argf_each_line, -1);
-    rb_define_method(rb_cARGF, "each_line",  argf_each_line, -1);
-    rb_define_method(rb_cARGF, "each_byte",  argf_each_byte, 0);
-    rb_define_method(rb_cARGF, "each_char",  argf_each_char, 0);
-    rb_define_method(rb_cARGF, "lines", argf_each_line, -1);
-    rb_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
-    rb_define_method(rb_cARGF, "chars", argf_each_char, 0);
+    rb_objc_define_method(rb_cARGF, "fileno", argf_fileno, 0);
+    rb_objc_define_method(rb_cARGF, "to_i", argf_fileno, 0);
+    rb_objc_define_method(rb_cARGF, "to_io", argf_to_io, 0);
+    rb_objc_define_method(rb_cARGF, "each",  argf_each_line, -1);
+    rb_objc_define_method(rb_cARGF, "each_line",  argf_each_line, -1);
+    rb_objc_define_method(rb_cARGF, "each_byte",  argf_each_byte, 0);
+    rb_objc_define_method(rb_cARGF, "each_char",  argf_each_char, 0);
+    rb_objc_define_method(rb_cARGF, "lines", argf_each_line, -1);
+    rb_objc_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
+    rb_objc_define_method(rb_cARGF, "chars", argf_each_char, 0);
 
-    rb_define_method(rb_cARGF, "read",  argf_read, -1);
-    rb_define_method(rb_cARGF, "readpartial",  argf_readpartial, -1);
-    rb_define_method(rb_cARGF, "readlines", argf_readlines, -1);
-    rb_define_method(rb_cARGF, "to_a", argf_readlines, -1);
-    rb_define_method(rb_cARGF, "gets", argf_gets, -1);
-    rb_define_method(rb_cARGF, "readline", argf_readline, -1);
-    rb_define_method(rb_cARGF, "getc", argf_getc, 0);
-    rb_define_method(rb_cARGF, "getbyte", argf_getbyte, 0);
-    rb_define_method(rb_cARGF, "readchar", argf_readchar, 0);
-    rb_define_method(rb_cARGF, "readbyte", argf_readbyte, 0);
-    rb_define_method(rb_cARGF, "tell", argf_tell, 0);
-    rb_define_method(rb_cARGF, "seek", argf_seek_m, -1);
-    rb_define_method(rb_cARGF, "rewind", argf_rewind, 0);
-    rb_define_method(rb_cARGF, "pos", argf_tell, 0);
-    rb_define_method(rb_cARGF, "pos=", argf_set_pos, 1);
-    rb_define_method(rb_cARGF, "eof", argf_eof, 0);
-    rb_define_method(rb_cARGF, "eof?", argf_eof, 0);
-    rb_define_method(rb_cARGF, "binmode", argf_binmode_m, 0);
+    rb_objc_define_method(rb_cARGF, "read",  argf_read, -1);
+    rb_objc_define_method(rb_cARGF, "readpartial",  argf_readpartial, -1);
+    rb_objc_define_method(rb_cARGF, "readlines", argf_readlines, -1);
+    rb_objc_define_method(rb_cARGF, "to_a", argf_readlines, -1);
+    rb_objc_define_method(rb_cARGF, "gets", argf_gets, -1);
+    rb_objc_define_method(rb_cARGF, "readline", argf_readline, -1);
+    rb_objc_define_method(rb_cARGF, "getc", argf_getc, 0);
+    rb_objc_define_method(rb_cARGF, "getbyte", argf_getbyte, 0);
+    rb_objc_define_method(rb_cARGF, "readchar", argf_readchar, 0);
+    rb_objc_define_method(rb_cARGF, "readbyte", argf_readbyte, 0);
+    rb_objc_define_method(rb_cARGF, "tell", argf_tell, 0);
+    rb_objc_define_method(rb_cARGF, "seek", argf_seek_m, -1);
+    rb_objc_define_method(rb_cARGF, "rewind", argf_rewind, 0);
+    rb_objc_define_method(rb_cARGF, "pos", argf_tell, 0);
+    rb_objc_define_method(rb_cARGF, "pos=", argf_set_pos, 1);
+    rb_objc_define_method(rb_cARGF, "eof", argf_eof, 0);
+    rb_objc_define_method(rb_cARGF, "eof?", argf_eof, 0);
+    rb_objc_define_method(rb_cARGF, "binmode", argf_binmode_m, 0);
 
-    rb_define_method(rb_cARGF, "filename", argf_filename, 0);
-    rb_define_method(rb_cARGF, "path", argf_filename, 0);
-    rb_define_method(rb_cARGF, "file", argf_file, 0);
-    rb_define_method(rb_cARGF, "skip", argf_skip, 0);
-    rb_define_method(rb_cARGF, "close", argf_close_m, 0);
-    rb_define_method(rb_cARGF, "closed?", argf_closed, 0);
+    rb_objc_define_method(rb_cARGF, "filename", argf_filename, 0);
+    rb_objc_define_method(rb_cARGF, "path", argf_filename, 0);
+    rb_objc_define_method(rb_cARGF, "file", argf_file, 0);
+    rb_objc_define_method(rb_cARGF, "skip", argf_skip, 0);
+    rb_objc_define_method(rb_cARGF, "close", argf_close_m, 0);
+    rb_objc_define_method(rb_cARGF, "closed?", argf_closed, 0);
 
-    rb_define_method(rb_cARGF, "lineno",   argf_lineno, 0);
-    rb_define_method(rb_cARGF, "lineno=",  argf_set_lineno, 1);
+    rb_objc_define_method(rb_cARGF, "lineno",   argf_lineno, 0);
+    rb_objc_define_method(rb_cARGF, "lineno=",  argf_set_lineno, 1);
 
-    rb_define_method(rb_cARGF, "inplace_mode", argf_inplace_mode_get, 0);
-    rb_define_method(rb_cARGF, "inplace_mode=", argf_inplace_mode_set, 1);
+    rb_objc_define_method(rb_cARGF, "inplace_mode", argf_inplace_mode_get, 0);
+    rb_objc_define_method(rb_cARGF, "inplace_mode=", argf_inplace_mode_set, 1);
 
-    rb_define_method(rb_cARGF, "external_encoding", argf_external_encoding, 0);
-    rb_define_method(rb_cARGF, "internal_encoding", argf_internal_encoding, 0);
-    rb_define_method(rb_cARGF, "set_encoding", argf_set_encoding, -1);
+    rb_objc_define_method(rb_cARGF, "external_encoding", argf_external_encoding, 0);
+    rb_objc_define_method(rb_cARGF, "internal_encoding", argf_internal_encoding, 0);
+    rb_objc_define_method(rb_cARGF, "set_encoding", argf_set_encoding, -1);
 
-    argf = rb_class_new_instance(0, 0, rb_cARGF);
+    argf = Qnil;
 
     rb_define_readonly_variable("$<", &argf);
     rb_define_global_const("ARGF", argf);
 
     rb_define_hooked_variable("$.", &argf, argf_lineno_getter, argf_lineno_setter);
     rb_define_hooked_variable("$FILENAME", &argf, argf_filename_getter, 0);
-    GC_WB(&filename, rb_str_new2("-"));
+    //GC_WB(&filename, rb_str_new2("-"));
 
     rb_define_hooked_variable("$-i", &argf, opt_i_get, opt_i_set);
     rb_define_hooked_variable("$*", &argf, argf_argv_getter, 0);
+    
+    //Init_File();
 
-#if defined (_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__)
-    atexit(pipe_atexit);
-#endif
-
-    Init_File();
-
-    rb_define_method(rb_cFile, "initialize",  rb_file_initialize, -1);
-
-    rb_file_const("RDONLY", INT2FIX(O_RDONLY));
-    rb_file_const("WRONLY", INT2FIX(O_WRONLY));
-    rb_file_const("RDWR", INT2FIX(O_RDWR));
-    rb_file_const("APPEND", INT2FIX(O_APPEND));
-    rb_file_const("CREAT", INT2FIX(O_CREAT));
-    rb_file_const("EXCL", INT2FIX(O_EXCL));
-#if defined(O_NDELAY) || defined(O_NONBLOCK)
-#   ifdef O_NONBLOCK
-    rb_file_const("NONBLOCK", INT2FIX(O_NONBLOCK));
-#   else
-    rb_file_const("NONBLOCK", INT2FIX(O_NDELAY));
-#   endif
-#endif
-    rb_file_const("TRUNC", INT2FIX(O_TRUNC));
-#ifdef O_NOCTTY
-    rb_file_const("NOCTTY", INT2FIX(O_NOCTTY));
-#endif
-#ifdef O_BINARY
-    rb_file_const("BINARY", INT2FIX(O_BINARY));
-#else
-    rb_file_const("BINARY", INT2FIX(0));
-#endif
-#ifdef O_SYNC
-    rb_file_const("SYNC", INT2FIX(O_SYNC));
-#endif
+    //rb_objc_define_method(rb_cFile, "initialize",  rb_file_initialize, -1);
+// 
+//     rb_file_const("RDONLY", INT2FIX(O_RDONLY));
+//     rb_file_const("WRONLY", INT2FIX(O_WRONLY));
+//     rb_file_const("RDWR", INT2FIX(O_RDWR));
+//     rb_file_const("APPEND", INT2FIX(O_APPEND));
+//     rb_file_const("CREAT", INT2FIX(O_CREAT));
+//     rb_file_const("EXCL", INT2FIX(O_EXCL));
+// #if defined(O_NDELAY) || defined(O_NONBLOCK)
+// #   ifdef O_NONBLOCK
+//     rb_file_const("NONBLOCK", INT2FIX(O_NONBLOCK));
+// #   else
+//     rb_file_const("NONBLOCK", INT2FIX(O_NDELAY));
+// #   endif
+// #endif
+//     rb_file_const("TRUNC", INT2FIX(O_TRUNC));
+// #ifdef O_NOCTTY
+//     rb_file_const("NOCTTY", INT2FIX(O_NOCTTY));
+// #endif
+// #ifdef O_BINARY
+//     rb_file_const("BINARY", INT2FIX(O_BINARY));
+// #else
+//     rb_file_const("BINARY", INT2FIX(0));
+// #endif
+// #ifdef O_SYNC
+//     rb_file_const("SYNC", INT2FIX(O_SYNC));
+// #endif
 }

Modified: MacRuby/branches/experimental/marshal.c
===================================================================
--- MacRuby/branches/experimental/marshal.c	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/marshal.c	2009-03-12 01:47:48 UTC (rev 884)
@@ -196,7 +196,7 @@
     rb_str_buf_cat(buf, s, n);
     if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) {
 	if (arg->taint) OBJ_TAINT(buf);
-	rb_io_write(arg->dest, buf);
+	rb_io_write(arg->dest, (SEL)"write:", buf);
 	rb_str_resize(buf, 0);
     }
 }
@@ -859,7 +859,7 @@
 {
     w_object(arg->obj, arg->arg, arg->limit);
     if (arg->arg->dest) {
-	rb_io_write(arg->arg->dest, arg->arg->str);
+	    rb_io_write(arg->arg->dest, (SEL)"write:", arg->arg->str);
 	rb_str_resize(arg->arg->str, 0);
     }
     return 0;

Modified: MacRuby/branches/experimental/parse.y
===================================================================
--- MacRuby/branches/experimental/parse.y	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/parse.y	2009-03-12 01:47:48 UTC (rev 884)
@@ -5032,7 +5032,7 @@
 static VALUE
 lex_io_gets(struct parser_params *parser, VALUE io)
 {
-    return rb_io_gets(io);
+    return rb_io_gets(io, (SEL)0);
 }
 
 NODE*

Modified: MacRuby/branches/experimental/ruby.c
===================================================================
--- MacRuby/branches/experimental/ruby.c	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/ruby.c	2009-03-12 01:47:48 UTC (rev 884)
@@ -629,6 +629,22 @@
     rb_warn("don't know how to dump `%.*s', (insns)", len, str);
 }
 
+void
+rb_exit(int status)
+{
+#if 0 // XXX should we call pthread_exit()
+    if (GET_THREAD()->tag) {
+	VALUE args[2];
+
+	args[0] = INT2NUM(status);
+	args[1] = rb_str_new2("exit");
+	rb_exc_raise(rb_class_new_instance(2, args, rb_eSystemExit));
+    }
+#endif
+    ruby_finalize();
+    exit(status);
+}
+
 static int
 proc_options(int argc, char **argv, struct cmdline_options *opt)
 {
@@ -1114,7 +1130,7 @@
 #endif
     GC_WB(&opt->script_name, rb_str_new4(rb_progname));
     opt->script = RSTRING_PTR(opt->script_name);
-    ruby_set_argv(argc, argv);
+    //ruby_set_argv(argc, argv);
     process_sflag(opt);
 
     ruby_init_loadpath();
@@ -1277,7 +1293,7 @@
 	if (opt->xflag) {
 	    forbid_setid("-x");
 	    opt->xflag = Qfalse;
-	    while (!NIL_P(line = rb_io_gets(f))) {
+	    while (!NIL_P(line = rb_io_gets(f, (SEL)"gets"))) {
 		line_start++;
 		const char *lineptr = RSTRING_PTR(line);
 		if (RSTRING_LEN(line) > 2
@@ -1291,11 +1307,11 @@
 	    rb_raise(rb_eLoadError, "no Ruby script found in input");
 	}
 
-	c = rb_io_getbyte(f);
+	c = rb_io_getbyte(f, (SEL)"getbyte");
 	if (c == INT2FIX('#')) {
-	    c = rb_io_getbyte(f);
+	    c = rb_io_getbyte(f, (SEL)"getbyte");
 	    if (c == INT2FIX('!')) {
-		line = rb_io_gets(f);
+		line = rb_io_gets(f, (SEL)"gets");
 		if (NIL_P(line))
 		    return 0;
 
@@ -1344,12 +1360,12 @@
 		}
 
 		/* push back shebang for pragma may exist in next line */
-		rb_io_ungetc(f, rb_str_new2("!\n"));
+		rb_io_ungetc(f, (SEL)"ungetc:", rb_str_new2("!\n"));
 	    }
 	    else if (!NIL_P(c)) {
-		rb_io_ungetc(f, c);
+		rb_io_ungetc(f, (SEL)"ungetc:", c);
 	    }
-	    rb_io_ungetc(f, INT2FIX('#'));
+	    rb_io_ungetc(f, (SEL)"ungetc:", INT2FIX('#'));
 	    if (no_src_enc && opt->src.enc.name) {
 #if WITH_OBJC
 		opt->src.enc.enc = opt_enc_find(opt->src.enc.name);
@@ -1368,7 +1384,7 @@
 	    }
 	}
 	else if (!NIL_P(c)) {
-	    rb_io_ungetc(f, c);
+	    rb_io_ungetc(f, (SEL)"ungetc", c);
 	}
 	require_libraries();	/* Why here? unnatural */
     }
@@ -1401,7 +1417,7 @@
 	rb_define_global_const("DATA", f);
     }
     else if (f != rb_stdin) {
-	rb_io_close(f);
+	rb_io_close(f, (SEL)"close");
     }
     return tree;
 }
@@ -1583,8 +1599,8 @@
     rb_define_hooked_variable("$PROGRAM_NAME", &rb_progname, 0, set_arg0);
     GC_ROOT(&rb_progname);
 
-    rb_define_global_const("ARGV", rb_argv);
-    rb_global_variable(&rb_argv0);
+    //rb_define_global_const("ARGV", rb_argv);
+    //rb_global_variable(&rb_argv0);
 
 #ifdef MSDOS
     /*

Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/string.c	2009-03-12 01:47:48 UTC (rev 884)
@@ -32,7 +32,10 @@
 VALUE rb_cNSString;
 VALUE rb_cNSMutableString;
 VALUE rb_cSymbol;
+VALUE rb_cByteString;
 
+static ptrdiff_t wrappedDataOffset;
+
 static void *rb_str_cfdata_key;
 
 static inline void
@@ -5374,6 +5377,96 @@
 
 #undef INSTALL_METHOD
 
+CFMutableDataRef 
+rb_bytestring_wrapped_data(VALUE bstr)
+{
+    void **data = (void **)((char *)bstr + wrappedDataOffset);
+    return (CFMutableDataRef)(*data); 
+}
+
+inline
+UInt8 *rb_bytestring_byte_pointer(VALUE bstr)
+{
+    return CFDataGetMutableBytePtr(rb_bytestring_wrapped_data(bstr));
+}
+
+
+static VALUE
+rb_bytestring_alloc(VALUE klass, SEL sel)
+{
+    VALUE bstr = (VALUE)class_createInstance((Class)rb_cByteString, 0);
+    CFMutableDataRef data = CFDataCreateMutable(NULL, 0);
+    CFDataIncreaseLength(data, 1);
+    // TODO: Maybe we should access this with wrappedDataOffset...
+    object_setInstanceVariable((id)bstr, "wrappedData", (void*)CFMakeCollectable(data));
+    return bstr;
+}
+
+
+VALUE 
+rb_bytestring_new() 
+{
+    VALUE bs = rb_bytestring_alloc(0, (SEL)"");
+    bs = (VALUE)objc_msgSend((id)bs, selInit); // [recv init];
+    return bs;
+}
+
+static VALUE
+rb_bytestring_initialize(VALUE recv, SEL sel, int argc, VALUE *argv)
+{
+    VALUE orig;
+    recv = (VALUE)objc_msgSend((id)recv, selInit); // [recv init];
+    if(argc == 1) {
+        rb_scan_args(argc, argv, "01", &orig);
+        const UniChar *toCopy = (const UniChar*)CFStringGetCStringPtr((CFStringRef)orig, kCFStringEncodingUTF8);
+        CFDataAppendBytes(rb_bytestring_wrapped_data(recv), (UInt8*)toCopy, CFStringGetLength((CFStringRef)orig));
+    }
+    return orig;
+}
+
+VALUE
+rb_coerce_to_bytestring(VALUE str)
+{
+    VALUE new = rb_bytestring_alloc(0, 0);
+    const UniChar *toCopy = (const UniChar*)CFStringGetCStringPtr((CFStringRef)str, kCFStringEncodingUTF8);
+    CFDataAppendBytes(rb_bytestring_wrapped_data(new), (UInt8*)toCopy, CFStringGetLength((CFStringRef)str));
+    return new;
+}
+
+long 
+rb_bytestring_length(VALUE str)
+{
+    return CFDataGetLength(rb_bytestring_wrapped_data(str))-1;
+}
+
+static CFIndex
+imp_rb_bytestring_length(void *rcv, SEL sel) 
+{
+    return CFDataGetLength(rb_bytestring_wrapped_data((VALUE)rcv))-1;
+}
+
+// There has GOT to be some character encoding issues with this.
+static UniChar
+imp_rb_bytestring_characterAtIndex(void *rcv, SEL sel, CFIndex idx)
+{
+    return rb_bytestring_byte_pointer((VALUE)rcv)[idx];
+}
+
+static void
+imp_rb_bytestring_replaceCharactersInRange_withString(void *rcv, SEL sel, CFRange range, void *str)
+{
+    const UniChar *toCopy = (const UniChar*)CFStringGetCStringPtr((CFStringRef)str, kCFStringEncodingUTF8);
+    // TODO: Add a call to CFStringGetCString to catch if this fails.
+    assert(toCopy != NULL);
+    size_t length = strlen((const char*)toCopy);
+    CFMutableDataRef data = rb_bytestring_wrapped_data((VALUE)rcv);
+    // TODO: Have a more robust check than merely an assert(),
+    // and find out whether CFDataReplaceBytes complains if you give it
+    // a range outside the length of the wrapped data..
+    assert((length + range.location) < CFDataGetLength(data));
+    CFDataReplaceBytes(data, range, (const UInt8*)toCopy, length);
+}
+
 /*
  *  A <code>String</code> object holds and manipulates an arbitrary sequence of
  *  bytes, typically representing characters. String objects may be created
@@ -5544,12 +5637,25 @@
     rb_objc_define_method(rb_cSymbol, "<=>", sym_cmp, 1);
     rb_objc_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
     rb_objc_define_method(rb_cSymbol, "description", sym_inspect, 0);
-    rb_objc_define_method(rb_cSymbol, "dup", rb_obj_dup, 0);
-    rb_objc_define_method(rb_cSymbol, "to_proc", sym_to_proc, 0);
-    rb_objc_define_method(rb_cSymbol, "to_s", rb_sym_to_s, 0);
-    rb_objc_define_method(rb_cSymbol, "id2name", rb_sym_to_s, 0);
-    rb_objc_define_method(rb_cSymbol, "intern", sym_to_sym, 0);
-    rb_objc_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
+    rb_define_method(rb_cSymbol, "dup", rb_obj_dup, 0);
+    rb_define_method(rb_cSymbol, "to_proc", sym_to_proc, 0);
+    rb_define_method(rb_cSymbol, "to_s", rb_sym_to_s, 0);
+    rb_define_method(rb_cSymbol, "id2name", rb_sym_to_s, 0);
+    rb_define_method(rb_cSymbol, "intern", sym_to_sym, 0);
+    rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
+    
+        
+    rb_cByteString = (VALUE)objc_allocateClassPair((Class)objc_getClass("NSMutableString"), "ByteString", 0);
+    class_addIvar((Class)rb_cByteString, "wrappedData", sizeof(id), 0, "@");
+    rb_objc_install_method2((Class)rb_cByteString, "length", (IMP)imp_rb_bytestring_length);
+    rb_objc_install_method2((Class)rb_cByteString, "characterAtIndex:", (IMP)imp_rb_bytestring_characterAtIndex);
+    rb_objc_install_method2((Class)rb_cByteString, "replaceCharactersInRange:withString:", (IMP)imp_rb_bytestring_replaceCharactersInRange_withString);
+    objc_registerClassPair((Class)rb_cByteString);
+    rb_objc_define_method(rb_cByteString, "initialize", rb_bytestring_initialize, -1);
+    rb_objc_define_method(*(VALUE *)rb_cByteString, "alloc", rb_bytestring_alloc, 0);
 
+    
+    wrappedDataOffset = ivar_getOffset(class_getInstanceVariable((Class)rb_cByteString, "wrappedData"));
+
     install_symbol_primitives();
 }

Modified: MacRuby/branches/experimental/test_roxor.rb
===================================================================
--- MacRuby/branches/experimental/test_roxor.rb	2009-03-12 01:07:53 UTC (rev 883)
+++ MacRuby/branches/experimental/test_roxor.rb	2009-03-12 01:47:48 UTC (rev 884)
@@ -5,7 +5,7 @@
 # use the rubyspec directory instead.
 
 $test_ruby = File.join(Dir.pwd, 'miniruby')
-$test_ruby_archs = ['i386', 'x86_64']
+$test_ruby_archs = ['i386']
 $test_only = ARGV
 $problems = []
 $assertions_count = 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090311/2f1ce8f9/attachment-0001.html>


More information about the macruby-changes mailing list