[svn:parrot] r38077 - in branches/packfile_revamp: src/pmc t/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sun Apr 12 08:02:42 UTC 2009


Author: bacek
Date: Sun Apr 12 08:02:41 2009
New Revision: 38077
URL: https://trac.parrot.org/parrot/changeset/38077

Log:
Add PackfileSegment.(set|get)_directory.

This is required for proper handling of Annotations because
AnnotationKeys holds index in ConstantTable.

Modified:
   branches/packfile_revamp/src/pmc/packfiledirectory.pmc
   branches/packfile_revamp/src/pmc/packfilesegment.pmc
   branches/packfile_revamp/t/pmc/packfiledirectory.t

Modified: branches/packfile_revamp/src/pmc/packfiledirectory.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfiledirectory.pmc	Sun Apr 12 08:02:21 2009	(r38076)
+++ branches/packfile_revamp/src/pmc/packfiledirectory.pmc	Sun Apr 12 08:02:41 2009	(r38077)
@@ -133,11 +133,12 @@
             }
 
             segment = pmc_new(interp, pmc_type);
+            name    = Parrot_str_new(interp, pfseg->name, strlen(pfseg->name));
+            VTABLE_set_pmc_keyed_str(interp, SELF, name, segment);
+
             /* Initialize internal PMC structure */
             VTABLE_set_pointer(interp, segment, pfseg);
 
-            name    = Parrot_str_new(interp, pfseg->name, strlen(pfseg->name));
-            VTABLE_set_pmc_keyed_str(interp, hash, name, segment);
         }
     }
 
@@ -249,6 +250,9 @@
 
 */
     VTABLE void set_pmc_keyed_str(STRING *name, PMC *segment)  {
+        Parrot_PCCINVOKE(interp, segment,
+            Parrot_str_new_constant(interp, "set_directory"),
+            "P->", SELF);
         VTABLE_set_pmc_keyed_str(interp,
             PARROT_PACKFILEDIRECTORY(SELF)->hash, name, segment);
     }

Modified: branches/packfile_revamp/src/pmc/packfilesegment.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfilesegment.pmc	Sun Apr 12 08:02:21 2009	(r38076)
+++ branches/packfile_revamp/src/pmc/packfilesegment.pmc	Sun Apr 12 08:02:41 2009	(r38077)
@@ -26,6 +26,69 @@
 #include "parrot/parrot.h"
 
 pmclass PackfileSegment {
+    /*
+    Directory which owns this segment. Required for correct pack/unpack
+    Annotations.
+    */
+    ATTR PMC *directory;
+
+
+/*
+
+=item C<void init()>
+
+Initialize PackfileSegment.
+
+=cut
+
+*/
+    VTABLE void init() {
+        Parrot_PackfileSegment_attributes * attrs =
+                mem_allocate_zeroed_typed(Parrot_PackfileSegment_attributes);
+
+        attrs->directory = NULL;
+
+        PObj_custom_mark_destroy_SETALL(SELF);
+        PMC_data(SELF) = attrs;
+    }
+
+/*
+
+=item C<void mark()>
+
+Marks the object as live.
+
+=cut
+
+*/
+
+    VTABLE void mark() {
+        Parrot_PackfileSegment_attributes * attrs =
+                PARROT_PACKFILESEGMENT(SELF);
+
+        if (attrs->directory)
+            pobject_lives(interp, (PObj *)attrs->directory);
+    }
+
+/*
+
+=item C<void destroy()>
+
+Destroys the PMC and frees all allocated memory.
+
+=cut
+
+*/
+
+    VTABLE void destroy() {
+        Parrot_PackfileSegment_attributes * attrs =
+                PARROT_PACKFILESEGMENT(SELF);
+
+        if (attrs) {
+            mem_sys_free(attrs);
+            PMC_data(SELF) = NULL;
+        }
+    }
 
 /*
 
@@ -81,6 +144,35 @@
                                     "PackfileSegment.unpack() not implemented yet.");
     }
 
+/*
+
+=item C<void set_directory(PMC *directory)>
+
+Set owning directory.
+
+=cut
+
+*/
+    METHOD set_directory(PMC *directory) {
+        PARROT_PACKFILESEGMENT(SELF)->directory = directory;
+    }
+
+/*
+
+=item C<void get_directory(PMC *directory)>
+
+Get owning directory.
+
+=cut
+
+*/
+    METHOD get_directory() {
+        PMC * directory = PARROT_PACKFILESEGMENT(SELF)->directory;
+        if (!directory)
+            directory = PMCNULL;
+        RETURN(PMC* directory);
+    }
+
 }
 /*
 

Modified: branches/packfile_revamp/t/pmc/packfiledirectory.t
==============================================================================
--- branches/packfile_revamp/t/pmc/packfiledirectory.t	Sun Apr 12 08:02:21 2009	(r38076)
+++ branches/packfile_revamp/t/pmc/packfiledirectory.t	Sun Apr 12 08:02:41 2009	(r38077)
@@ -21,14 +21,36 @@
 
 .sub 'main' :main
 .include 'test_more.pir'
-    plan(13)
+    plan(21)
 
+    'test_create'()
     'test_typeof'()
     'test_elements'()
     'test_get_iter'()
     'test_set_pmc_keyed_str'()
 .end
 
+# Test creation of fresh directory
+.sub 'test_create'
+    .local pmc dir, seg
+    dir = new 'PackfileDirectory'
+    isa_ok(dir, 'PackfileDirectory')
+
+    seg = new 'PackfileRawSegment'
+    # We should set owner
+    $P0 = seg.'get_directory'()
+    $I0 = defined $P0
+    $I0 = not $I0
+    ok($I0, "Owner of fresh segment unknown")
+
+    dir['RAWSEGMENT'] = seg
+
+    # We should set owner
+    $P0 = seg.'get_directory'()
+    $I0 = defined $P0
+    ok($I0, "Owner of segment set correctly")
+.end
+
 # PackfileDirectory.typeof
 .sub 'test_typeof'
     .local pmc pf
@@ -37,7 +59,6 @@
     isa_ok($P1, 'PackfileDirectory', 'PackfileDirectory.get_directory')
 .end
 
-
 # PackfileDirectory.elements
 .sub 'test_elements'
     .local pmc pf, pfdir
@@ -79,6 +100,9 @@
 
     $P1 = pfdir[name]
     isa_ok($P1, 'PackfileSegment')
+    $P2 = $P1.'get_directory'()
+    $I0 = defined $P2
+    ok($I0, "Loaded Segment has proper directory")
     goto loop
   done:
     .return ()


More information about the parrot-commits mailing list