[svn:parrot] r43957 - in branches/tt362: . src src/pmc t/pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Sun Feb 14 22:54:06 UTC 2010


Author: plobsing
Date: Sun Feb 14 22:54:05 2010
New Revision: 43957
URL: https://trac.parrot.org/parrot/changeset/43957

Log:
eliminate thaw_ptr from ImageIO API. This makes ImageIO easier to use from PIR.

Add basic tests for ImageIO PMC.

Added:
   branches/tt362/t/pmc/imageio.t
Modified:
   branches/tt362/MANIFEST
   branches/tt362/src/pmc/imageio.pmc
   branches/tt362/src/pmc_freeze.c

Modified: branches/tt362/MANIFEST
==============================================================================
--- branches/tt362/MANIFEST	Sun Feb 14 22:01:02 2010	(r43956)
+++ branches/tt362/MANIFEST	Sun Feb 14 22:54:05 2010	(r43957)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Sun Feb  7 21:29:31 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sun Feb 14 22:53:39 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1896,6 +1896,7 @@
 t/pmc/hash.t                                                [test]
 t/pmc/hashiterator.t                                        [test]
 t/pmc/hashiteratorkey.t                                     [test]
+t/pmc/imageio.t                                             [test]
 t/pmc/integer.t                                             [test]
 t/pmc/io.t                                                  [test]
 t/pmc/io_iterator.t                                         [test]

Modified: branches/tt362/src/pmc/imageio.pmc
==============================================================================
--- branches/tt362/src/pmc/imageio.pmc	Sun Feb 14 22:01:02 2010	(r43956)
+++ branches/tt362/src/pmc/imageio.pmc	Sun Feb 14 22:54:05 2010	(r43957)
@@ -165,7 +165,7 @@
         break;
     }
 
-    *(PARROT_IMAGEIO(info)->thaw_ptr) = pmc;
+    PARROT_IMAGEIO(info)->pmc_result = pmc;
 }
 
 static void
@@ -260,7 +260,7 @@
     ATTR size_t           pos;            /* current read/write position in buffer */
     ATTR size_t           input_length;
     ATTR INTVAL           what;
-    ATTR PMC            **thaw_ptr;       /* where to thaw a new PMC */
+    ATTR PMC             *pmc_result;     /* where to thaw a new PMC */
     ATTR PMC             *seen;           /* seen hash */
     ATTR PMC             *todo;           /* todo list */
     ATTR PMC             *id_list;        /* seen list used by thaw */
@@ -288,7 +288,7 @@
 
 */
     VTABLE void init() {
-        PARROT_IMAGEIO(SELF)->thaw_ptr    = NULL;
+        PARROT_IMAGEIO(SELF)->pmc_result  = PMCNULL;
         PARROT_IMAGEIO(SELF)->buffer      = NULL;
         PARROT_IMAGEIO(SELF)->todo        = pmc_new(INTERP, enum_class_ResizablePMCArray);
         PARROT_IMAGEIO(SELF)->seen        = PMCNULL;
@@ -347,20 +347,19 @@
                                           PARROT_IMAGEIO(SELF)->buffer,
                                           PARROT_IMAGEIO(SELF)->pos);
     }
-/*
 
 /*
 
-=item C<VTABLE void set_pointer()>
+=item C<VTABLE PMC *get_pmc()>
 
-Sets the location where to thaw a new PMC.
+Gets the result PMC after a thaw.
 
 =cut
 
 */
 
-    VTABLE void set_pointer(void* value) {
-        PARROT_IMAGEIO(SELF)->thaw_ptr = (PMC**)value;
+    VTABLE PMC *get_pmc() {
+        return VTABLE_get_pmc_keyed_int(INTERP, (PARROT_IMAGEIO(SELF))->id_list, 1);
     }
 
 /*
@@ -441,7 +440,6 @@
 */
 
     VTABLE void push_pmc(PMC *v) {
-        VTABLE_set_pointer(interp, SELF, &v);
         (PARROT_IMAGEIO(SELF)->visit_pmc_now)(INTERP, v, SELF);
     }
 
@@ -516,8 +514,8 @@
 
     VTABLE PMC *shift_pmc() {
         PMC *result;
-        VTABLE_set_pointer(interp, SELF, &result);
         (PARROT_IMAGEIO(SELF)->visit_pmc_now)(interp, NULL, SELF);
+        result = PARROT_IMAGEIO(SELF)->pmc_result;
         return result;
     }
 

Modified: branches/tt362/src/pmc_freeze.c
==============================================================================
--- branches/tt362/src/pmc_freeze.c	Sun Feb 14 22:01:02 2010	(r43956)
+++ branches/tt362/src/pmc_freeze.c	Sun Feb 14 22:54:05 2010	(r43957)
@@ -103,8 +103,8 @@
         gc_block = 1;
     }
 
-    VTABLE_set_pointer(interp, info, &result);
     VTABLE_set_string_native(interp, info, image);
+    result = VTABLE_get_pmc(interp, info);
 
     if (gc_block) {
         Parrot_unblock_GC_mark(interp);

Added: branches/tt362/t/pmc/imageio.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/tt362/t/pmc/imageio.t	Sun Feb 14 22:54:05 2010	(r43957)
@@ -0,0 +1,77 @@
+#! parrot
+# Copyright (C) 2010, Parrot Foundation.
+# $Id: $
+
+=head1 NAME
+
+t/pmc/imageio.t - test ImageIO PMC
+
+=head1 SYNOPSIS
+
+    % prove t/pmc/imagio.t
+
+=head1 DESCRIPTION
+
+Tests the ImageIO PMC.
+
+=cut
+
+.sub main :main
+    .include 'test_more.pir'
+
+    plan(11)
+
+    .local pmc imageio
+    imageio = new ['ImageIO']
+    ok(1, 'instantiated ImageIO')
+
+    .local pmc test_pmc
+    test_pmc = 'get_test_simple'()
+    setref imageio, test_pmc
+    $S0 = imageio
+    ok($S0, 'frozen PMC is true (simple)')
+    $S1 = freeze test_pmc
+    is($S0, $S1, 'freeze gives same image as ImageIO (simple)')
+
+    imageio = $S0
+    $P0 = deref imageio
+    ok($P0, 'thawed PMC is true (simple)')
+    $P1 = thaw $S1
+    is($P0, $P1, 'thaw gives same PMC as ImageIO (simple)')
+    is($P0, test_pmc, 'round trip gives same PMC (simple)')
+
+    imageio = new ['ImageIO']
+    test_pmc = 'get_test_aggregate'()
+    setref imageio, test_pmc
+    $S0 = imageio
+    ok($S0, 'frozen PMC is true (aggregate)')
+    $S1 = freeze test_pmc
+    is($S0, $S1, 'freeze gives same image as ImageIO (aggregate)')
+
+    imageio = $S0
+    $P0 = deref imageio
+    ok($P0, 'thawed PMC is true (aggregate)')
+    $P1 = thaw $S1
+    is_deeply($P0, $P1, 'thaw gives same PMC as ImageIO (aggregate)')
+    is_deeply($P0, test_pmc, 'round trip gives same PMC (aggregate)')
+.end
+
+.sub get_test_simple
+    $P0 = new ['Integer']
+    $P0 = -99
+    .return ($P0)
+.end
+
+.sub get_test_aggregate
+    $P0 = new ['ResizableStringArray']
+    $P0[0] = 'parrot'
+    $P0[1] = '???'
+    $P0[2] = 'profit'
+    .return ($P0)
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir


More information about the parrot-commits mailing list