On Thu, 23 May 2002, Daniel Grunblatt wrote: > > On Wed, 22 May 2002, Sean O'Rourke wrote: > > > that pack() can't handle null bytes makes it a bit more complicated (and > Exactly how do you want it to handle null bytes?
Nevermind -- sorry 'bout that. There's a little wierdness in there, but it isn't because of nulls -- I just spaced out reading the pack docs. The strangeness is with the 4-argument version of pack(), which doesn't extend its first argument if the pack destination goes past the end of the string. So you get this: set S0, "" set I0, 42 pack S0, 4, I0, 0 length I1, S0 # is 0 pack S0, 4, I0 length I1, S0 # is 4 pack S0, 4, I0, 10000 # is segv which is completely unrelated to nulls, but still strange. I was thrown off by this result when trying to use the offset version of pack. I attached a patch that (I think) does something with less startle value. /s
RCS file: /cvs/public/parrot/core.ops,v retrieving revision 1.143 diff -u -p -r1.143 core.ops --- core.ops 20 May 2002 17:52:28 -0000 1.143 +++ core.ops 23 May 2002 15:03:31 -0000 @@ -1957,11 +1957,17 @@ inline op pack(inout STR, in INT, in STR inline op pack(inout STR, in INT, in INT, in INT) { char *c = (char *)&$3, *n; STRING *s; + INTVAL ln; const char *t; int i; s = string_make(interpreter, c, (UINTVAL)$2, NULL, 0, NULL); s->flags |= BUFFER_neonate_FLAG; + ln = string_length($1); + assert($4 <= ln); + if (ln < $4 + $2) + string_grow(interpreter, $1, $4 + $2 - ln) + /* XXX this is EVIL, use string_replace */ n = $1->bufstart; t = string_to_cstring(interpreter, (s));