Skip to content

Commit

Permalink
stringnull preserved accross freeze/thaw
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/branches/stringnull@45572 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
plobsing committed Apr 11, 2010
1 parent 8241251 commit f03cee0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/packfile/pf_items.c
Expand Up @@ -1309,19 +1309,28 @@ PF_fetch_string(PARROT_INTERP, ARGIN_NULLOK(PackFile *pf), ARGIN(const opcode_t
{
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 */
Expand Down Expand Up @@ -1369,6 +1378,17 @@ PF_store_string(ARGOUT(opcode_t *cursor), ARGIN(const STRING *s))
}

*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
Expand Down
10 changes: 10 additions & 0 deletions t/pmc/freeze.t
Expand Up @@ -52,9 +52,19 @@ pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a String" );
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" );
Expand Down

0 comments on commit f03cee0

Please sign in to comment.