[svn:parrot] r45961 - in trunk: src/io t/op

dukeleto at svn.parrot.org dukeleto at svn.parrot.org
Sat Apr 24 03:04:53 UTC 2010


Author: dukeleto
Date: Sat Apr 24 03:04:52 2010
New Revision: 45961
URL: https://trac.parrot.org/parrot/changeset/45961

Log:
[io] Make Parrot_io_open delegate to the FileHandle PMC and allow HLL mapping

Modified:
   trunk/src/io/api.c
   trunk/t/op/io.t

Modified: trunk/src/io/api.c
==============================================================================
--- trunk/src/io/api.c	Sat Apr 24 02:57:27 2010	(r45960)
+++ trunk/src/io/api.c	Sat Apr 24 03:04:52 2010	(r45961)
@@ -122,25 +122,24 @@
     ASSERT_ARGS(Parrot_io_open)
     PMC *new_filehandle, *filehandle;
     INTVAL flags;
+    const INTVAL typenum = Parrot_get_ctx_HLL_type(interp, Parrot_PMC_typenum(interp, "FileHandle"));
     if (PMC_IS_NULL(pmc)) {
-        /* TODO: We should look up the HLL mapped type, instead of always
-           using FileHandle here */
-        new_filehandle = Parrot_pmc_new(interp, enum_class_FileHandle);
-        PARROT_ASSERT(new_filehandle->vtable->base_type == enum_class_FileHandle);
+        new_filehandle = Parrot_pmc_new(interp, typenum);
+        PARROT_ASSERT(new_filehandle->vtable->base_type == typenum);
     }
     else
         new_filehandle = pmc;
 
     flags = Parrot_io_parse_open_flags(interp, mode);
-    if (new_filehandle->vtable->base_type == enum_class_FileHandle) {
+    if (new_filehandle->vtable->base_type == typenum) {
         /* TODO: StringHandle may have a null path, but a filehandle really
            shouldn't allow that. */
-        PARROT_ASSERT(new_filehandle->vtable->base_type == enum_class_FileHandle);
+        PARROT_ASSERT(new_filehandle->vtable->base_type == typenum);
         filehandle = PIO_OPEN(interp, new_filehandle, path, flags);
         if (PMC_IS_NULL(filehandle))
             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
                 "Unable to open filehandle from path '%S'", path);
-        PARROT_ASSERT(filehandle->vtable->base_type == enum_class_FileHandle);
+        PARROT_ASSERT(filehandle->vtable->base_type == typenum);
         SETATTR_FileHandle_flags(interp, new_filehandle, flags);
         SETATTR_FileHandle_filename(interp, new_filehandle, path);
         SETATTR_FileHandle_mode(interp, new_filehandle, mode);

Modified: trunk/t/op/io.t
==============================================================================
--- trunk/t/op/io.t	Sat Apr 24 02:57:27 2010	(r45960)
+++ trunk/t/op/io.t	Sat Apr 24 03:04:52 2010	(r45961)
@@ -16,19 +16,40 @@
 
 =cut
 
-.const int TESTS = 4
+.const int TESTS = 5
 
 .sub 'main' :main
     .include 'test_more.pir'
 
     plan(TESTS)
 
+    open_delegates_to_filehandle_pmc()
     open_null_filename()
     open_null_mode()
     open_pipe_for_reading()
     open_pipe_for_writing()
 .end
 
+.sub open_delegates_to_filehandle_pmc
+    load_bytecode 'P6object.pbc'
+
+    .local pmc p6meta, interp, classes, classid
+    p6meta = get_root_global ["parrot"], "P6metaclass"
+    p6meta.'new_class'('Testing')
+
+    interp = getinterp
+    classes = interp[0]
+    classid = classes['Testing']
+    $I0 = classes['FileHandle']
+    set classes['FileHandle'], classid
+
+    $P1 = open '/foo'
+
+    # replace the original, so we don't break other tests
+    set classes['FileHandle'], $I0
+
+.end
+
 .sub 'open_null_filename'
     push_eh open_null_filename_failed
     null $S0
@@ -127,7 +148,8 @@
     .local pmc pipe
     pipe = open command, 'wp'
     unless pipe goto open_pipe_for_writing_failed
-    pipe.'puts'("ok - open pipe for writing\n")
+
+    pipe.'puts'("ok 5 - open pipe for writing\n")
     close pipe
     .return ()
 
@@ -140,6 +162,14 @@
 
 .end
 
+.namespace ["Testing"]
+
+.sub open :method
+    .param pmc args :slurpy
+    ok(1,'open opcode delegates to the FileHandle PMC')
+.end
+
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100


More information about the parrot-commits mailing list