[svn:parrot] r45572 - in branches/stringnull: src/packfile t/pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Sun Apr 11 17:23:45 UTC 2010


Author: plobsing
Date: Sun Apr 11 17:23:45 2010
New Revision: 45572
URL: https://trac.parrot.org/parrot/changeset/45572

Log:
stringnull preserved accross freeze/thaw

Modified:
   branches/stringnull/src/packfile/pf_items.c
   branches/stringnull/t/pmc/freeze.t

Modified: branches/stringnull/src/packfile/pf_items.c
==============================================================================
--- branches/stringnull/src/packfile/pf_items.c	Sun Apr 11 17:10:30 2010	(r45571)
+++ branches/stringnull/src/packfile/pf_items.c	Sun Apr 11 17:23:45 2010	(r45572)
@@ -1309,19 +1309,28 @@
 {
     ASSERT_ARGS(PF_fetch_string)
     STRING   *s;
-    UINTVAL   flags      = PF_fetch_opcode(pf, cursor);
-    opcode_t  charset_nr = PF_fetch_opcode(pf, cursor);
-    size_t    size       = (size_t)PF_fetch_opcode(pf, cursor);
-    const int wordsize   = pf ? pf->header->wordsize : sizeof (opcode_t);
+    UINTVAL   flags;
+    opcode_t  charset_nr;
+    size_t    size;
+    const int wordsize = pf ? pf->header->wordsize : sizeof (opcode_t);
+
+    flags      = PF_fetch_opcode(pf, cursor);
+    charset_nr = PF_fetch_opcode(pf, cursor);
+
+    if (charset_nr < 0) {
+        return STRINGNULL;
+    }
+
+    size = (size_t)PF_fetch_opcode(pf, cursor);
 
     /* don't let PBC mess our internals - only constant or not */
-    flags      &= (PObj_constant_FLAG | PObj_private7_FLAG);
+    flags &= (PObj_constant_FLAG | PObj_private7_FLAG);
 
     TRACE_PRINTF(("PF_fetch_string(): flags=0x%04x, ", flags));
     TRACE_PRINTF(("charset_nr=%ld, ", charset_nr));
     TRACE_PRINTF(("size=%ld.\n", size));
 
-    s            = string_make_from_charset(interp, (const char *)*cursor,
+    s = string_make_from_charset(interp, (const char *)*cursor,
                         size, charset_nr, flags);
 
     /* print only printable characters */
@@ -1369,6 +1378,17 @@
     }
 
     *cursor++ = PObj_get_FLAGS(s); /* only constant_FLAG and private7 */
+
+    if (STRING_IS_NULL(s)) {
+        /* preserve NULL-ness of strings
+         * ideally we'd null strings would take only a single opcode_t,
+         * but PObj flags uses a whole word
+         * charset number, OTOH, can't be negative
+         */
+        *cursor++ = -1;
+        return cursor;
+    }
+
     /*
      * TODO as soon as we have dynamically loadable charsets
      *      we have to store the charset name, not the number

Modified: branches/stringnull/t/pmc/freeze.t
==============================================================================
--- branches/stringnull/t/pmc/freeze.t	Sun Apr 11 17:10:30 2010	(r45571)
+++ branches/stringnull/t/pmc/freeze.t	Sun Apr 11 17:23:45 2010	(r45572)
@@ -52,9 +52,19 @@
     print " "
     print P10
     print "\n"
+
+    null S1
+    new P1, ['String']
+    set P1, S1
+    freeze S0, P1
+    thaw P10, S0
+    set S10, P10
+    isnull I0, S10
+    say I0
     end
 CODE
 String foo
+1
 OUTPUT
 
 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Float" );


More information about the parrot-commits mailing list