develooper Front page | perl.perl5.porters | Postings from April 2000

Re: [ID 20000425.002] Minor bug fix and enhancement to to pp.c:pp_pack()

Thread Previous | Thread Next
John Holdsworth
April 26, 2000 04:25
Re: [ID 20000425.002] Minor bug fix and enhancement to to pp.c:pp_pack()
Message ID:

Ilya Zakharevich wrote:

> John Holdsworth writes:
> > Included is a bug fix to the decode of unpack 'N/Z*' which
> > was not adding a byte to the encoded length as pack does.

Hello IIlya, thanks for your comments.

> Not clear.  unpack 'N/Z*' with N unpacking to 14 should be the same as
> Z14.  Is it?

It seems not. There is some rather strange code in pp_pack()
 case 'A':
 case 'Z':
 case 'a':
     fromstr = NEXTFROM;
     aptr = SvPV(fromstr, fromlen);
     if (pat[-1] == '*') {
  len = fromlen;
  if (datumtype == 'Z')
which bumps the length. I copied this into unpack so unpack(pack("N/Z*")) worked.

> > There is also option to use 'N/a*4' to round the length of encoded
> > strings to four bytes as required by SUN XDR RFC 1832.
> I think a more general command is needed.  Say, 'x!8' which would add
> 0-bytes until the next position which is multiple of 8.  Then you
> would write 'N/a*x!4'.

I would agree with this. I was trying to make the absolute
minum change possible to what is very much core code.

> > More contentiously perhaps the code also supports a new length
> > character '?' which steals the length from the next argument.
> > This allows multiple arrays to be encoded and decoded viz.:
> >
> > my @arr = (1,2,3,4);
> > my $packed = pack "N/N?N/N?", scalar @arr, @arr, scalar @arr, @arr;
> Again, something more general is needed.  Something like
>   my $packed = pack "(N//N)(N//N)", scalar @arr, @arr, scalar @arr, @arr;

I'm not so sure this would be more intuitive. '?' is in effect a new way to specify
the length of operands after '123' and '*'. It steals an argument for a length in
pack and leaves it on the stack on unpack. This is very useful for processing
SUN/RPC calls along with "@?" which pushes the current position in the string
onto the stack so you know how much of the string has been processed.

> or similar.
> Ilya



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About