[svn:parrot] r40950 - in trunk: src/pmc t/op

chromatic at svn.parrot.org chromatic at svn.parrot.org
Thu Sep 3 07:29:58 UTC 2009


Author: chromatic
Date: Thu Sep  3 07:29:57 2009
New Revision: 40950
URL: https://trac.parrot.org/parrot/changeset/40950

Log:
[PMC] Made String PMC's set_string_native() promote NULL STRINGs to empty
STRINGs.  We need STRINGNULL.  See TT #964, which includes a test case for
boxed NULL STRINGs.

Modified:
   trunk/src/pmc/string.pmc
   trunk/t/op/box.t

Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc	Thu Sep  3 07:29:53 2009	(r40949)
+++ trunk/src/pmc/string.pmc	Thu Sep  3 07:29:57 2009	(r40950)
@@ -220,11 +220,16 @@
 */
 
     VTABLE void set_string_native(STRING *value) {
+        /* in lieu of a STRINGNULL, promote any NULL STRINGs to empty ones */
+        if (!value)
+            value = Parrot_str_new(INTERP, NULL, 0);
+
         /* Only allow constant PMCs to embed constant strings */
         if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) {
             char *copy = Parrot_str_to_cstring(INTERP, value);
             value      = Parrot_str_new_init(INTERP, copy, strlen(copy),
-                    PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, PObj_constant_FLAG);
+                PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
+                PObj_constant_FLAG);
             Parrot_str_free_cstring(copy);
         }
 

Modified: trunk/t/op/box.t
==============================================================================
--- trunk/t/op/box.t	Thu Sep  3 07:29:53 2009	(r40949)
+++ trunk/t/op/box.t	Thu Sep  3 07:29:57 2009	(r40950)
@@ -1,5 +1,5 @@
 #!parrot
-# Copyright (C) 2008, Parrot Foundation.
+# Copyright (C) 2008-2009, Parrot Foundation.
 # $Id$
 
 =head1 NAME
@@ -16,7 +16,7 @@
 
 =cut
 
-.const int TESTS = 24
+.const int TESTS = 26
 
 # must set these up before the hll_map calls later
 .sub '__setup' :immediate
@@ -33,6 +33,7 @@
     'box_int'()
     'box_num'()
     'box_string'()
+    'box_null_string'()
 
     .local pmc box_int_hll
     box_int_hll = get_root_global [ 'for_test' ], 'box_int'
@@ -93,7 +94,20 @@
     isa_ok( $P0, 'String', 'string boxed to appropriate base type from reg' )
 .end
 
+.sub 'box_null_string'
+    null $S0
+    $P0 = box $S0
+    $S1 = $P0
+    is( $S1, '', 'NULL STRING boxed to empty String PMC' )
+
+    $P1 = clone $P0
+    $S1 = $P0
+    is( $S1, '', '... and survives clone of boxed PMC (TT #964)' )
+
+.end
+
 .HLL 'for_test'
+
 .sub anon :anon :init
   .local pmc interp
   .local pmc cint, myint


More information about the parrot-commits mailing list