Author: particle
Date: Mon Apr  9 16:03:11 2007
New Revision: 18092

Modified:
   trunk/src/pmc/namespace.pmc
   trunk/t/pmc/namespace.t

Log:
[pmc]: added null guard to NameSpace PMC 'export_to' method
~ also added tests

Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Mon Apr  9 16:03:11 2007
@@ -596,9 +596,18 @@
     METHOD void export_to(PMC* dest, PMC* what) {
         INTVAL i, n;
 
-        n = VTABLE_elements(INTERP, what);
-        if (!n)
+        if (PMC_IS_NULL(dest)) {
+            real_exception(interp, NULL, 0,
+                    "destination namespace not specified");
+            return;
+        }
+        if (PMC_IS_NULL(what) || !VTABLE_elements(interp, what)) {
+            real_exception(interp, NULL, 0,
+                    "exporting default object set not yet specified");
             return;
+        }
+
+        n = VTABLE_elements(INTERP, what);
         for (i = 0; i < n; ++i) {
             STRING *name;
             PMC *el;

Modified: trunk/t/pmc/namespace.t
==============================================================================
--- trunk/t/pmc/namespace.t     (original)
+++ trunk/t/pmc/namespace.t     Mon Apr  9 16:03:11 2007
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 52;
+use Parrot::Test tests => 55;
 use Parrot::Config;
 
 =head1 NAME
@@ -657,6 +657,7 @@
 OUTPUT
 }
 
+
 open $S, '>', "$temp_b.pir" or die "Can't write $temp_b.pir";
 print $S <<'EOF';
 .HLL 'B', ''
@@ -666,7 +667,63 @@
 EOF
 close $S;
 
-pir_output_is( <<"CODE", <<'OUTPUT', "export_to" );
+
+pir_output_like(<<'CODE', <<'OUTPUT', 'export_to() with null destination 
throws exception');
+.sub 'test' :main
+    .local pmc nsa, nsb, ar
+
+    ar = new .ResizableStringArray
+    push ar, 'foo'
+    nsa = new .Null
+    nsb = get_namespace ['B']
+    nsb.'export_to'(nsa, ar)
+.end
+
+.namespace ['B']
+.sub 'foo' :anon
+.end
+CODE
+/^destination namespace not specified\n/
+OUTPUT
+
+
+pir_output_like(<<'CODE', <<'OUTPUT', 'export_to() with null array exports 
default boject set !!!UNSPECIFIED!!!');
+.sub 'test' :main
+    .local pmc nsa, nsb, ar
+
+    ar = new .Null
+    nsa = get_namespace
+    nsb = get_namespace ['B']
+    nsb.'export_to'(nsa, ar)
+.end
+
+.namespace ['B']
+.sub 'foo'
+.end
+CODE
+/^exporting default object set not yet specified\n/
+OUTPUT
+
+
+pir_output_like(<<'CODE', <<'OUTPUT', 'export_to() with empty array exports 
default boject set !!!UNSPECIFIED!!!');
+.sub 'test' :main
+    .local pmc nsa, nsb, ar
+
+    ar = new .ResizableStringArray
+    nsa = get_namespace
+    nsb = get_namespace ['B']
+    nsb.'export_to'(nsa, ar)
+.end
+
+.namespace ['B']
+.sub 'foo'
+.end
+CODE
+/^exporting default object set not yet specified\n/
+OUTPUT
+
+
+pir_output_is( <<"CODE", <<'OUTPUT', "export_to -- success" );
 .HLL 'A', ''
 .sub main :main
     a_foo()

Reply via email to