[svn:parrot] r39255 - in branches/io_rewiring/src: io pmc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Sat May 30 01:39:50 UTC 2009
Author: whiteknight
Date: Sat May 30 01:39:49 2009
New Revision: 39255
URL: https://trac.parrot.org/parrot/changeset/39255
Log:
[io_rewiring] convert the Parrot_io_reads function
Modified:
branches/io_rewiring/src/io/api.c
branches/io_rewiring/src/pmc/filehandle.pmc
branches/io_rewiring/src/pmc/stringhandle.pmc
Modified: branches/io_rewiring/src/io/api.c
==============================================================================
--- branches/io_rewiring/src/io/api.c Sat May 30 01:16:48 2009 (r39254)
+++ branches/io_rewiring/src/io/api.c Sat May 30 01:39:49 2009 (r39255)
@@ -297,9 +297,49 @@
Parrot_io_reads(PARROT_INTERP, ARGMOD(PMC *pmc), size_t length)
{
ASSERT_ARGS(Parrot_io_reads)
- STRING *result;
- Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "read"), "I->S",
- length, &result);
+ STRING *result = NULL;
+ if (VTABLE_does(interp, pmc, CONST_STRING(interp, "file"))) {
+ 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");
+
+ result = Parrot_io_make_string(interp, &result, length);
+ result->bufused = length;
+
+ if (Parrot_io_is_encoding(interp, pmc, CONST_STRING(interp, "utf8")))
+ ignored = Parrot_io_read_utf8(interp, pmc, &result);
+ else
+ ignored = Parrot_io_read_buffer(interp, pmc, &result);
+ }
+ else if (VTABLE_does(interp, pmc, CONST_STRING(interp, "string"))) {
+ STRING *string_orig;
+ INTVAL offset;
+
+ GETATTR_StringHandle_stringhandle(interp, pmc, string_orig);
+ if (STRING_IS_NULL(string_orig))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+ "Cannot read from a closed filehandle");
+
+ if (length == 0)
+ result = Parrot_str_copy(interp, string_orig);
+ else {
+ INTVAL orig_length, read_length;
+ read_length = length;
+ orig_length = Parrot_str_byte_length(interp, string_orig);
+
+ GETATTR_StringHandle_read_offset(interp, pmc, offset);
+
+ /* Only read to the end of the string data. */
+ if (offset + read_length > orig_length)
+ read_length = orig_length - offset;
+
+ result = Parrot_str_substr(interp, string_orig, offset,
+ read_length, NULL, 0);
+ SETATTR_StringHandle_read_offset(interp, pmc, offset + read_length);
+ }
+ }
return result;
}
Modified: branches/io_rewiring/src/pmc/filehandle.pmc
==============================================================================
--- branches/io_rewiring/src/pmc/filehandle.pmc Sat May 30 01:16:48 2009 (r39254)
+++ branches/io_rewiring/src/pmc/filehandle.pmc Sat May 30 01:39:49 2009 (r39255)
@@ -362,19 +362,7 @@
METHOD read(INTVAL length) {
STRING *string_result = NULL;
- INTVAL ignored;
-
- if (Parrot_io_is_closed_filehandle(interp, SELF))
- 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, SELF, CONST_STRING(interp, "utf8")))
- ignored = Parrot_io_read_utf8(interp, SELF, &string_result);
- else
- ignored = Parrot_io_read_buffer(interp, SELF, &string_result);
+ string_result = Parrot_io_reads(INTERP, SELF, length);
RETURN(STRING *string_result);
}
Modified: branches/io_rewiring/src/pmc/stringhandle.pmc
==============================================================================
--- branches/io_rewiring/src/pmc/stringhandle.pmc Sat May 30 01:16:48 2009 (r39254)
+++ branches/io_rewiring/src/pmc/stringhandle.pmc Sat May 30 01:39:49 2009 (r39255)
@@ -269,32 +269,7 @@
*/
METHOD read(INTVAL length) {
- STRING *string_result, *string_orig;
- INTVAL offset;
-
- GET_ATTR_stringhandle(INTERP, SELF, string_orig);
- if (STRING_IS_NULL(string_orig))
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
- "Cannot read from a closed filehandle");
-
- if (length == 0)
- string_result = Parrot_str_copy(INTERP, string_orig);
- else {
- INTVAL orig_length, read_length;
- read_length = length;
- orig_length = Parrot_str_byte_length(INTERP, string_orig);
-
- GET_ATTR_read_offset(INTERP, SELF, offset);
-
- /* Only read to the end of the string data. */
- if (offset + read_length > orig_length)
- read_length = orig_length - offset;
-
- string_result = Parrot_str_substr(INTERP, string_orig, offset,
- read_length, NULL, 0);
- SET_ATTR_read_offset(INTERP, SELF, offset + read_length);
- }
-
+ STRING *string_result;
RETURN(STRING *string_result);
}
More information about the parrot-commits
mailing list