satyenr / protobuf-perlxs

Automatically exported from code.google.com/p/protobuf-perlxs
Apache License 2.0
0 stars 0 forks source link

to_hashref() and repeated messages #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add next strings to examples/types/test.pl:
$msg1->add_rep_message(new Protobuf::Types::Message({ t_string => "message 1" 
}));
$msg1->add_rep_message(new Protobuf::Types::Message({ t_string => "message 2" 
}));
$msg1->add_rep_message(new Protobuf::Types::Message({ t_string => "message 3" 
}));
$msg1->add_rep_message(new Protobuf::Types::Message({ t_string => "message 4" 
}));
$msg1->add_rep_message(new Protobuf::Types::Message({ t_string => "message 5" 
}));

2. Add more 'print'-s:
print Dumper $msg1->rep_message(0)->to_hashref();
print Dumper $msg1->rep_message(1)->to_hashref();
print Dumper $msg1->rep_message(2)->to_hashref();
print Dumper $msg1->rep_message(3)->to_hashref();
print Dumper $msg1->rep_message(4)->to_hashref();

3. Run 'make test'

What is the expected output? What do you see instead?

I see this:

          'rep_message' => [
                             {
                               't_string' => 'message 5'
                             },
                             {
                               't_string' => 'message 5'
                             },
                             {
                               't_string' => 'message 5'
                             },
                             {
                               't_string' => 'message 5'
                             },
                             {
                               't_string' => 'message 5'
                             }
                           ],

All messages are the same due to bug in to_hashref() Types.xs:
...
      if ( msg0->rep_message_size() > 0 ) {
        AV * av0 = newAV();
        SV * sv0 = newRV_noinc((SV *)av0);

        for ( int i0 = 0; i0 < msg0->rep_message_size(); i0++ ) {
          ::Protobuf::Types_Message * msg2 = msg0->mutable_rep_message(i0);
          SV * svv1 = sv_2mortal( __Protobuf__Types_call_Method( svTHIS, "rep_message" ) );
          SV * sv1 = __Protobuf__Types_call_Method( svv1, "to_hashref" );

          av_push(av0, sv1);
        }
        hv_store(hv0, "rep_message", sizeof("rep_message") - 1, sv0, 0);
      }
...

What version of the product are you using? On what operating system?

Last version and last Ubuntu.

Please provide any additional information below.

Original issue reported on code.google.com by s2...@land.ru on 13 Sep 2013 at 11:38

GoogleCodeExporter commented 9 years ago
Sorry, version from https://github.com/sombr/protobuf-perlxs

Original comment by s2...@land.ru on 13 Sep 2013 at 11:49