develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34442 - in branches/pdd22io_part3: include/parrot src/io src/pmc

From:
allison
Date:
December 27, 2008 12:20
Subject:
[svn:parrot] r34442 - in branches/pdd22io_part3: include/parrot src/io src/pmc
Message ID:
20081227202022.DD33CCBA12@x12.develooper.com
Author: allison
Date: Sat Dec 27 12:20:21 2008
New Revision: 34442

Modified:
   branches/pdd22io_part3/include/parrot/io.h
   branches/pdd22io_part3/src/io/api.c
   branches/pdd22io_part3/src/pmc/filehandle.pmc

Log:
[pdd22io] Invert 'read' so public interface calls the method, allowing cleaner
polymorphism.


Modified: branches/pdd22io_part3/include/parrot/io.h
==============================================================================
--- branches/pdd22io_part3/include/parrot/io.h	(original)
+++ branches/pdd22io_part3/include/parrot/io.h	Sat Dec 27 12:20:21 2008
@@ -253,17 +253,6 @@
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
-INTVAL Parrot_io_read(PARROT_INTERP,
-    ARGMOD(PMC *pmc),
-    ARGIN(char *buffer),
-    size_t len)
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(3)
-        FUNC_MODIFIES(*pmc);
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 STRING * Parrot_io_reads(PARROT_INTERP, ARGMOD(PMC *pmc), size_t len)
         __attribute__nonnull__(1)

Modified: branches/pdd22io_part3/src/io/api.c
==============================================================================
--- branches/pdd22io_part3/src/io/api.c	(original)
+++ branches/pdd22io_part3/src/io/api.c	Sat Dec 27 12:20:21 2008
@@ -218,63 +218,12 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 STRING *
-Parrot_io_reads(PARROT_INTERP, ARGMOD(PMC *pmc), size_t len)
+Parrot_io_reads(PARROT_INTERP, ARGMOD(PMC *pmc), size_t length)
 {
-    STRING               *res;
-    INTVAL                ignored;
-
-    if (Parrot_io_is_closed(interp, pmc))
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
-            "Cannot read from a closed filehandle");
-
-    if (Parrot_io_get_buffer_flags(interp, pmc) & PIO_BF_MMAP) {
-        res           = new_string_header(interp, 0);
-        res->charset  = Parrot_iso_8859_1_charset_ptr;   /* XXX binary */
-        res->encoding = Parrot_fixed_8_encoding_ptr;
-    }
-    else {
-        res = NULL;
-        res = Parrot_io_make_string(interp, &res, len);
-    }
-
-    res->bufused = len;
-
-    if (Parrot_io_is_encoding(interp, pmc, CONST_STRING(interp, "utf8")))
-        ignored = Parrot_io_read_utf8(interp, pmc, &res);
-    else
-        ignored = Parrot_io_read_buffer(interp, pmc, &res);
-    UNUSED(ignored);
-
-    return res;
-}
-
-/*
-
-=item C<INTVAL Parrot_io_read>
-
-Reads up to C<len> bytes from C<*pmc> and copies them into C<*buffer>.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-INTVAL
-Parrot_io_read(PARROT_INTERP, ARGMOD(PMC *pmc), ARGIN(char *buffer), size_t len)
-{
-    STRING *res = new_string_header(interp, 0);
-
-    if (Parrot_io_is_closed(interp, pmc))
-        return -1;
-
-    res->strstart = buffer;
-    res->bufused = len;
-
-    if (Parrot_io_is_encoding(interp, pmc, CONST_STRING(interp, "utf8")))
-        return Parrot_io_read_utf8(interp, pmc, &res);
-
-    return Parrot_io_read_buffer(interp, pmc, &res);
+    STRING *result;
+    Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "read"), "I->S",
+            length, &result);
+    return result;
 }
 
 /*

Modified: branches/pdd22io_part3/src/pmc/filehandle.pmc
==============================================================================
--- branches/pdd22io_part3/src/pmc/filehandle.pmc	(original)
+++ branches/pdd22io_part3/src/pmc/filehandle.pmc	Sat Dec 27 12:20:21 2008
@@ -290,8 +290,22 @@
 
 */
 
-    METHOD read(INTVAL bytes) {
-        STRING *string_result = Parrot_io_reads(INTERP, SELF, bytes);
+    METHOD read(INTVAL length) {
+        STRING *string_result = NULL;
+        INTVAL  ignored;
+
+        if (Parrot_io_is_closed_filehandle(interp, pmc))
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+                "Cannot read from a closed filehandle");
+
+        string_result = Parrot_io_make_string(interp, &string_result, length);
+        string_result->bufused = length;
+
+        if (Parrot_io_is_encoding(interp, pmc, CONST_STRING(interp, "utf8")))
+            ignored = Parrot_io_read_utf8(interp, pmc, &string_result);
+        else
+            ignored = Parrot_io_read_buffer(interp, pmc, &string_result);
+
         RETURN(STRING *string_result);
     }
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About