Author: infinoid
Date: Mon Jul 21 05:35:36 2008
New Revision: 29650

Modified:
   branches/pdd13pbc/src/pmc/packfilesegment.pmc
   branches/pdd13pbc/t/pmc/packfile.t

Log:
[PDD13]
* Fix inheritance, so that subclasses of PackfileSegment can use the
  .pack() method.
* Fix .pack, it seems sometimes Packfile_Segment_pack() doesn't return
  the same number of bytes PackFile_Segment_packed_size() said it would.
* Consolidate some PIR test code into a common string.
* Fix the get_directory() test to use the "typeof" op.


Modified: branches/pdd13pbc/src/pmc/packfilesegment.pmc
==============================================================================
--- branches/pdd13pbc/src/pmc/packfilesegment.pmc       (original)
+++ branches/pdd13pbc/src/pmc/packfilesegment.pmc       Mon Jul 21 05:35:36 2008
@@ -25,7 +25,21 @@
 
 #include "parrot/parrot.h"
 
-pmclass PackfileSegment abstract no_init {
+pmclass PackfileSegment {
+
+
+/*
+
+=item C<void init()>
+
+Initialize the structure.  (Create a blank PackFile_Segment object.)
+
+=cut
+
+*/
+    VTABLE void init() {
+        PMC_data(SELF) = PackFile_Segment_new(interp, NULL, "", 0);
+    }
 
 
 /*
@@ -40,14 +54,15 @@
     METHOD pack() {
         PackFile_Segment *pfseg = PMC_data_typed(SELF, PackFile_Segment *);
         opcode_t length = PackFile_Segment_packed_size(interp, pfseg) * 
sizeof(opcode_t);
-        opcode_t *ptr = (opcode_t*)mem_sys_allocate(length);
+        opcode_t *newptr, *ptr = (opcode_t*)mem_sys_allocate(length);
         STRING *str;
-        PackFile_Segment_pack(interp, pfseg, ptr);
+        newptr = PackFile_Segment_pack(interp, pfseg, ptr);
         /* FIXME: PARROT_BINARY_CHARSET seems like a better choice, but the
          * comparison function for the binary charset plugin always returns
          * "equal", which means tests fail.
          */
-        str = string_make_direct(interp, (const char*)ptr, length,
+        str = string_make_direct(interp, (const char*)ptr,
+                (newptr - ptr) * sizeof(opcode_t),
                 PARROT_FIXED_8_ENCODING, PARROT_DEFAULT_CHARSET, 0);
         mem_sys_free(ptr);
         RETURN(STRING *str);

Modified: branches/pdd13pbc/t/pmc/packfile.t
==============================================================================
--- branches/pdd13pbc/t/pmc/packfile.t  (original)
+++ branches/pdd13pbc/t/pmc/packfile.t  Mon Jul 21 05:35:36 2008
@@ -61,22 +61,21 @@
     .local pmc pf
     pf = new 'Packfile'
     $P1 = pf.'get_directory'()
-    $I0 = defined $P1
-    say $I0
+    $S0 = typeof $P1
+    say $S0
 .end
 CODE
-1
+PackfileDirectory
 OUT
 
 
-# Packfile.set_string_native, Packfile.get_integer_keyed_str
-pir_output_is( <<'CODE', $PConfig{VERSION}, 'set_string_native' );
-.sub 'test' :main
+my $get_uuid_pbc = <<'EOF';
+
+.sub _pbc
     .include "stat.pasm"
     .include "interpinfo.pasm"
-    .local pmc pf, conf, pio
+    .local pmc pf, pio
     pf   = new 'Packfile'
-    conf = _config()
     $S0  = interpinfo .INTERPINFO_RUNTIME_PREFIX
     $S0 .= "/runtime/parrot/library/uuid.pbc"
     $I0  = stat $S0, .STAT_FILESIZE
@@ -84,6 +83,16 @@
     $S0  = read pio, $I0
     close pio
     pf   = $S0
+    .return(pf)
+.end
+EOF
+
+
+# Packfile.set_string_native, Packfile.get_integer_keyed_str
+pir_output_is( <<'CODE' . $get_uuid_pbc, $PConfig{VERSION}, 
'set_string_native' );
+.sub 'test' :main
+    .local pmc pf
+    pf   = _pbc()
     $S0  = "version_major"
     $I0  = pf[$S0]
     $S0  = "version_minor"
@@ -96,26 +105,15 @@
     print "."
     print $I2
 .end
-
-.include "library/config.pir"
 CODE
 
 
 # Packfile.set_integer_keyed_str
 
-pir_output_is( <<'CODE', <<'OUT', 'set_integer_keyed_str' );
+pir_output_is( <<'CODE' . $get_uuid_pbc, <<'OUT', 'set_integer_keyed_str' );
 .sub 'test' :main
-    .include "stat.pasm"
-    .include "interpinfo.pasm"
-    .local pmc pf, pio
-    $S0 = interpinfo .INTERPINFO_RUNTIME_PREFIX
-    $S0 .= "/runtime/parrot/library/uuid.pbc"
-    $I0 = stat $S0, .STAT_FILESIZE
-    pio = open $S0, "<"
-    $S0 = read pio, $I0
-    close pio
-    pf  = new 'Packfile'
-    pf  = $S0
+    .local pmc pf
+    pf  = _pbc()
     $S1 = 'version_major'
     $I0 = pf[$S1]
     $I1 = $I0
@@ -137,24 +135,15 @@
 OUT
 
 
-# PackfileSegment.pack
+# PackfileSegment.pack (via subclass PackfileDirectory)
 
-pir_output_is( <<'CODE', <<'OUT', 'set_integer_keyed_str' );
+pir_output_is( <<'CODE' . $get_uuid_pbc, <<'OUT', 'set_integer_keyed_str' );
 .sub 'test' :main
-    .include "stat.pasm"
-    .include "interpinfo.pasm"
-    .local pmc pf, pio, pfdir
-    $S0 = interpinfo .INTERPINFO_RUNTIME_PREFIX
-    $S0 .= "/runtime/parrot/library/uuid.pbc"
-    $I0 = stat $S0, .STAT_FILESIZE
-    pio = open $S0, "<"
-    $S0 = read pio, $I0
-    close pio
-    pf  = new 'Packfile'
-    pf  = $S0
+    .local pmc pf, pfdir
+    pf    = _pbc()
     pfdir = pf.'get_directory'()
-    $S0 = pfdir.'pack'()
-    $I0 = length $S0
+    $S0   = pfdir.'pack'()
+    $I0   = length $S0
     eq $I0, 0, OUT1
     print "not "
     OUT1:

Reply via email to