[macruby-changes] [891] MacRuby/branches/experimental/io.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 11 21:00:17 PDT 2009


Revision: 891
          http://trac.macosforge.org/projects/ruby/changeset/891
Author:   lsansonetti at apple.com
Date:     2009-03-11 21:00:16 -0700 (Wed, 11 Mar 2009)
Log Message:
-----------
re-implemented rb_io_fdopen() + do not leak the CF streams

Modified Paths:
--------------
    MacRuby/branches/experimental/io.c

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-03-12 02:32:40 UTC (rev 890)
+++ MacRuby/branches/experimental/io.c	2009-03-12 04:00:16 UTC (rev 891)
@@ -172,7 +172,38 @@
 #define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
 #define PREP_STDIO_NAME(f) ((f)->path)
 
+static inline 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;
+}
+
 /*
  *  call-seq:
  *     IO.try_convert(obj) -> io or nil
@@ -218,11 +249,11 @@
     CFStreamCreatePairWithSocket(NULL, fd, &r, &w);
     CFReadStreamOpen(r);
     CFWriteStreamOpen(w);
-    // Do I need to use GC_WB?
     GC_WB(&RFILE(io)->fptr->readStream, r);
     GC_WB(&RFILE(io)->fptr->writeStream, w);
+    CFMakeCollectable(r);
+    CFMakeCollectable(w);
     rb_objc_keep_for_exit_finalize((VALUE)io);
-    
     return io;
 }
 
@@ -1282,12 +1313,19 @@
     rb_notimplement();
 }
 
-VALUE rb_io_fdopen(int a, int b, const char* c)
+VALUE
+rb_io_fdopen(int fd, int mode, const char *path)
 {
-    rb_notimplement();
+    VALUE klass = rb_cIO;
+
+    if (path != NULL && strcmp(path, "-")) {
+	klass = rb_cFile;
+    }
+    return prep_io(fd, rb_io_modenum_flags(mode), klass, path);
 }
 
-VALUE rb_io_gets(VALUE v, SEL s)
+VALUE
+rb_io_gets(VALUE v, SEL s)
 {
     rb_notimplement();
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090311/ae8152d5/attachment.html>


More information about the macruby-changes mailing list