[svn:parrot] r39210 - in branches/io_rewiring/src: io pmc

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Thu May 28 00:59:53 UTC 2009


Author: whiteknight
Date: Thu May 28 00:59:52 2009
New Revision: 39210
URL: https://trac.parrot.org/parrot/changeset/39210

Log:
[io_rewiring] convert a few more things, add support in some functions for StringHandle

Modified:
   branches/io_rewiring/src/io/api.c
   branches/io_rewiring/src/pmc/stringhandle.pmc

Modified: branches/io_rewiring/src/io/api.c
==============================================================================
--- branches/io_rewiring/src/io/api.c	Thu May 28 00:48:49 2009	(r39209)
+++ branches/io_rewiring/src/io/api.c	Thu May 28 00:59:52 2009	(r39210)
@@ -27,6 +27,7 @@
 #include "io_private.h"
 #include "api.str"
 #include "../pmc/pmc_filehandle.h"
+#include "../pmc/pmc_stringhandle.h"
 
 #include <stdarg.h>
 
@@ -204,7 +205,7 @@
 Parrot_io_close(PARROT_INTERP, ARGMOD(PMC *pmc))
 {
     ASSERT_ARGS(Parrot_io_close)
-    INTVAL result;
+    INTVAL result = 1;
 
     if (PMC_IS_NULL(pmc))
         return -1;
@@ -213,6 +214,9 @@
         result = Parrot_io_close_filehandle(interp, pmc);
         SETATTR_FileHandle_flags(interp, pmc, 0);
     }
+    else if (VTABLE_does(interp, pmc, CONST_STRING(interp, "string"))) {
+        SETATTR_StringHandle_read_offset(interp, pmc, 0);
+    }
 
     return result;
 }
@@ -240,6 +244,11 @@
         return 1;
     if (VTABLE_does(interp, pmc, CONST_STRING(interp, "file")))
         result = Parrot_io_is_closed_filehandle(interp, pmc);
+    else if (VTABLE_does(interp, pmc, CONST_STRING(interp, "string"))) {
+        STRING *stringhandle;
+        GETATTR_StringHandle_stringhandle(interp, pmc, stringhandle);
+        result = STRING_IS_NULL(stringhandle);
+    }
 
     return result;
 }

Modified: branches/io_rewiring/src/pmc/stringhandle.pmc
==============================================================================
--- branches/io_rewiring/src/pmc/stringhandle.pmc	Thu May 28 00:48:49 2009	(r39209)
+++ branches/io_rewiring/src/pmc/stringhandle.pmc	Thu May 28 00:59:52 2009	(r39210)
@@ -21,7 +21,7 @@
 
 #include "../src/io/io_private.h"
 
-pmclass StringHandle need_ext {
+pmclass StringHandle extends Handle need_ext {
     ATTR INTVAL  flags;               /* Filehandle flags             */
     ATTR STRING *stringhandle;        /* The string data              */
     ATTR STRING *mode;                /* The mode string used in open */
@@ -83,6 +83,20 @@
 
 /*
 
+=item <INTVAL does(STRING * role)>
+
+=cut
+
+*/
+
+    VTABLE INTVAL does(STRING * role) {
+        if (Parrot_str_equal(INTERP, SELF, CONST_STRING(INTERP, "string")))
+            return 1;
+        return SUPER(role);
+    }
+
+/*
+
 =item C<void mark()>
 
 Mark active stringhandle data as live.
@@ -238,13 +252,9 @@
 */
 
     METHOD is_closed() {
-        STRING *stringhandle;
-        GET_ATTR_stringhandle(INTERP, SELF, stringhandle);
-
-        if (STRING_IS_NULL(stringhandle))
-            RETURN(INTVAL 1);
-
-        RETURN(INTVAL 0);
+        INTVAL status;
+        status = Parrot_io_is_closed(INTERP, SELF);
+        RETURN(INTVAL status);
     }
 
 /*


More information about the parrot-commits mailing list