New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor bug fix and enhancement to to pp.c:pp_pack() #1886
Comments
From johnno@ms.comCreated by root@pland.cwpThis message contains a small set of patches to pp.c:pp_pack/unpack(). Included is a bug fix to the decode of unpack 'N/Z*' which There is also option to use 'N/a*4' to round the length of encoded More contentiously perhaps the code also supports a new length my @arr = (1,2,3,4); Using these basic changes it is possible to decode/encode SUN RPC calls, Included are patches to t/op/pack.t and pod/perlfunc.pod regression I hope you find this interesting. I've tried to keep the changes Regards, John Holdsworth Patch file to perl-5.6.0 follows... *** t/op/pack.t Mon Mar 13 21:25:37 2000 Perl Info
|
From [Unknown Contact. See original ticket]John Holdsworth writes:
Not clear. unpack 'N/Z*' with N unpacking to 14 should be the same as
I think a more general command is needed. Say, 'x!8' which would add
Again, something more general is needed. Something like my $packed = pack "(N//N)(N//N)", scalar @arr, @arr, scalar @arr, @arr; or similar. Ilya |
From [Unknown Contact. See original ticket]Ilya Zakharevich wrote:
Hello IIlya, thanks for your comments.
It seems not. There is some rather strange code in pp_pack()
I would agree with this. I was trying to make the absolute
I'm not so sure this would be more intuitive. '?' is in effect a new way to specify
Cheers, john. |
From [Unknown Contact. See original ticket]On Wed, Apr 26, 2000 at 12:25:08PM +0100, John Holdsworth wrote:
Hmm, I was asking about unpack(), not about pack().
???? This chunk calculates the *required* length basing on the length What is the problem you want to address?
Thanks, but for user-visible changes this is not the best criterion.
Currently this can be done with interpolation into the pattern: my $len = @arr; I can easily believe that the feature you wanted to add is desirable, Ilya |
From [Unknown Contact. See original ticket]Created by root@pland.cwpThis message contains a small set of patches to pp.c:pp_pack/unpack(). Included is a bug fix to the decode of unpack 'N/Z*' which There is also option to use 'N/a*4' to round the length of encoded More contentiously perhaps the code also supports a new length my @arr = (1,2,3,4); Using these basic changes it is possible to decode/encode SUN RPC calls, Included are patches to t/op/pack.t and pod/perlfunc.pod regression I hope you find this interesting. I've tried to keep the changes Regards, John Holdsworth Patch file to perl-5.6.0 follows... *** t/op/pack.t Mon Mar 13 21:25:37 2000 ! print "1..156\n"; $format = "c2 x5 C C x s d i l a6"; ! print "1..160\n"; $format = "c2 x5 C C x s d i l a6"; + The characterC<?> for the repeat count means the next argument will The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a - The I<string-item> must, at present, be C<"A*">, C<"a*"> or C<"Z*">. unpack 'C/a', "\04Gurusamy"; gives 'Guru' The I<length-item> is not returned explicitly from C<unpack>. --- 3097,3112 ---- For C<unpack> the length of the string is obtained from the I<length-item>, unpack 'C/a', "\04Gurusamy"; gives 'Guru' The I<length-item> is not returned explicitly from C<unpack>. *** pp.c Mon Mar 20 15:35:44 2000 + #define NEXTPAT( _chr ) (pat < patend && *pat == (_chr) && pat++) Perl Info
|
From [Unknown Contact. See original ticket]On Wed, Apr 26, 2000 at 08:55:42PM +0100, John Holdsworth wrote:
DB<1> x pack "N/Z* a4", "hi there ", "1234"; This is clearly a bug. Either \0 should not have been inserted, or But this is a bug in pack(). I do not see why any change should be
I do not care which letter represents "it" in the template. I care Ilya |
From [Unknown Contact. See original ticket]Ilya Zakharevich <ilya@math.ohio-state.edu> wrote
Since Z is defined to *always* insert a \0, the length should be 10.
Agreed. Patch attached. Mike Guy Inline Patch--- ./pp.c.orig Thu Apr 27 18:11:50 2000
+++ ./pp.c Thu Apr 27 18:04:17 2000
@@ -4445,7 +4445,8 @@
if ((*pat != 'a' && *pat != 'A' && *pat != 'Z') || pat[1] != '*')
DIE(aTHX_ "/ must be followed by a*, A* or Z*");
lengthcode = sv_2mortal(newSViv(sv_len(items > 0
- ? *MARK : &PL_sv_no)));
+ ? *MARK : &PL_sv_no)
+ + (*pat == 'Z' ? 1 : 0)));
}
switch(datumtype) {
default:
--- ./t/op/pack.t.orig Thu Apr 27 18:11:50 2000
+++ ./t/op/pack.t Thu Apr 27 18:12:05 2000
@@ -372,8 +372,9 @@
eval { ($x) = pack '/a*','hello' };
print 'not ' unless $@; print "ok $test\n"; $test++;
-$z = pack 'n/a* w/A*','string','etc';
-print 'not ' unless $z eq "\000\006string\003etc"; print "ok $test\n"; $test++;
+$z = pack 'n/a* N/Z* w/A*','string','hi there ','etc';
+print 'not ' unless $z eq "\000\006string\0\0\0\012hi there \000\003etc";
+print "ok $test\n"; $test++;
eval { ($x) = unpack 'a/a*/a*', '212ab345678901234567' };
print $@ eq '' && $x eq 'ab3456789012' ? "ok $test\n" : "#$x,$@\nnot ok $test\n";
End of patch |
From @iabynThe patch appears to have been applied. |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#3154 (status was 'resolved')
Searchable as RT3154$
The text was updated successfully, but these errors were encountered: