problem with 0.6

9 views
Skip to first unread message

Seth Daniel

unread,
Jan 21, 2009, 9:47:14 PM1/21/09
to protobu...@googlegroups.com
All,

Given a proto file:

package Foo.Common;

message NameValue {
optional string name = 1;
optional string value = 2;
}


Build the message and execute the following code:

#!/usr/bin/perl

use strict;
use warnings;

use Foo::Common::NameValue;

my $c;
foreach (1..3) {
foreach ('A'..'Z') {
my $m = Foo::Common::NameValue->new;
$c .= $_;
$m->set_name($c);
$m->set_value($c);
my $payload = $m->pack;
print "(" . length($c) . ") p: " . length($payload) . "\n";
}
}


I get the following (edited) result:

(1) p: 6
(2) p: 8
(3) p: 10
(4) p: 12
(5) p: 14
(6) p: 0 <-------------------
(7) p: 18
(8) p: 20
(9) p: 22
(10) p: 24
(11) p: 26
(12) p: 28
(13) p: 30
(14) p: 0 <-------------------
(15) p: 34
(16) p: 36
(17) p: 38
[...]
(26) p: 56
(27) p: 58
(28) p: 60
(29) p: 62
(30) p: 0 <-------------------
(31) p: 66
(32) p: 68
[...]
(60) p: 124
(61) p: 126
(62) p: 0 <-------------------
(63) p: 130
(64) p: 132
(65) p: 134
[...]


For whatever reason when the length of the pack would be a multiple of 8
the pack will return a zero length string...unless the length is exactly 8.

I have yet to look at the code, but it is interesting. :o)

--
seth /\ sethdaniel.org

Dave Bailey

unread,
Jan 21, 2009, 10:05:10 PM1/21/09
to protobu...@googlegroups.com
Hi Seth,

I think this is a bug in the generated ZeroCopyStream implementation (foo_OutputStream in NameValue.xs in this case, near the top of the file).  I'll look at this tonight, along with issue #4, and see if I can get a new release out shortly.  In the meantime, the workaround is to uncomment line 12 of perlxs_generator.cc:

//#define NO_ZERO_COPY 1

Uncommenting this line will revert the pack() method to the pre-0.6 behavior, which is slower (for large messages), but doesn't have any known bugs.

-dave

Seth Daniel

unread,
Jan 21, 2009, 10:08:00 PM1/21/09
to protobu...@googlegroups.com
On Wed, Jan 21, 2009 at 07:05:10PM -0800, Dave Bailey wrote:
> Hi Seth,
>
> I think this is a bug in the generated ZeroCopyStream implementation
> (foo_OutputStream in NameValue.xs in this case, near the top of the file).
> I'll look at this tonight, along with issue #4,

Thanks Dave.

You know I never noticed the Issues tab before.

--
seth /\ sethdaniel.org

Dave Bailey

unread,
Jan 21, 2009, 11:02:41 PM1/21/09
to protobu...@googlegroups.com
Hi Seth,

I just committed a fix for this in SVN (rev 18).  The diff can be viewed here:

http://code.google.com/p/protobuf-perlxs/source/diff?spec=svn18&old=16&r=18&format=unidiff&path=%2Ftrunk%2Fsrc%2Fgoogle%2Fprotobuf%2Fcompiler%2Fperlxs%2Fperlxs_generator.cc

The problem was that in cases where the packed message is a multiple of 8 bytes in size, protobuf doesn't call BackUp() to adjust the length of the string when it's finished packing, so SvCUR_set never gets called, and Perl ends up thinking that the string is empty.

-dave

Seth Daniel

unread,
Jan 21, 2009, 11:17:14 PM1/21/09
to protobu...@googlegroups.com

Just tested and it works. Thanks again!

--
seth /\ sethdaniel.org

Reply all
Reply to author
Forward
0 new messages