Skip to content
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

Does not work in perl 5.20.1 #13

Open
GoogleCodeExporter opened this issue Oct 30, 2015 · 0 comments
Open

Does not work in perl 5.20.1 #13

GoogleCodeExporter opened this issue Oct 30, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

1. Patch protobuf-perlxs-1.1/examples/embedded with the following:
Index: examples/embedded/test.pl
===================================================================
--- examples/embedded/test.pl   (revision 191663)
+++ examples/embedded/test.pl   (working copy)
@@ -84,6 +84,8 @@
     my $packed  = $error->pack;
     my $length  = length($packed);
     my $elapsed = tv_interval($now);
+    $error->clear();
+    $error->unpack($packed);

     print "Built/packed error of $length bytes in $elapsed seconds\n";

@@ -116,6 +118,8 @@
     my $packed  = $error->pack;
     my $length  = length($packed);
     my $elapsed = tv_interval($now);
+    $error->clear();
+    $error->unpack($packed);

     print "Built/packed error of $length bytes in $elapsed seconds\n";

2. perl Makefile.PL && make && make test

What is the expected output? What do you see instead?
I see output like this:

        Built/packed error of 141 bytes in 6.8e-05 seconds
        $VAR1 = {
                  'datetime' => 1415276412,
                  'severity' => 3,
                  'message' => 'Here iing"

        test'
                };
        Built/packed error of 141 bytes in 6.2e-05 seconds
        $VAR1 = {
                  'message' => 'Here iing"

        test',
                  'datetime' => 1415276412,
                  'severity' => 3
                };

instead of

        Built/packed error of 173 bytes in 7.7e-05 seconds
        $VAR1 = {
                  'pid' => 29231,
                  'message' => 'Here is a warning',
                  'trace' => [
                               {
                                 'file' => 'test.pl',
                                 'line' => 51
                               },
                               {
                                 'line' => 43,
                                 'file' => 'test.pl'
                               },
                               {
                                 'line' => 39,
                                 'file' => 'test.pl'
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 35
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 31
                               },
                               {
                                 'line' => 27,
                                 'file' => 'test.pl'
                               },
                               {
                                 'line' => 23,
                                 'file' => 'test.pl'
                               },
                               {
                                 'line' => 19,
                                 'file' => 'test.pl'
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 15
                               },
                               {
                                 'line' => 11,
                                 'file' => 'test.pl'
                               }
                             ],
                  'hostname' => 'spider-man',
                  'severity' => 3,
                  'datetime' => 1415276538
                };
        Built/packed error of 173 bytes in 6.1e-05 seconds
        $VAR1 = {
                  'pid' => 29231,
                  'message' => 'Here is a warning',
                  'trace' => [
                               {
                                 'file' => 'test.pl',
                                 'line' => 51
                               },
                               {
                                 'line' => 43,
                                 'file' => 'test.pl'
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 39
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 35
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 31
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 27
                               },
                               {
                                 'line' => 23,
                                 'file' => 'test.pl'
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 19
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 15
                               },
                               {
                                 'file' => 'test.pl',
                                 'line' => 12
                               }
                             ],
                  'datetime' => 1415276538,
                  'severity' => 3,
                  'hostname' => 'spider-man'
                };

What version of the product are you using? On what operating system?
- protobuf-perlxs-1.1
- Ubuntu 14.10
- $ perl -v

        This is perl 5, version 20, subversion 1 (v5.20.1) built for x86_64-linux-gnu-thread-multi
        (with 37 registered patches, see perl -V for more detail)

Please provide any additional information below.
I fixed this by that patch:
Index: src/google/protobuf/compiler/perlxs/perlxs_generator.cc
===================================================================
--- src/google/protobuf/compiler/perlxs/perlxs_generator.cc (revision 191667)
+++ src/google/protobuf/compiler/perlxs/perlxs_generator.cc (working copy)
@@ -123,21 +123,19 @@
   printer.Print("class $base$_OutputStream :\n"
        "  public google::protobuf::io::ZeroCopyOutputStream {\n"
        "public:\n"
+       "  explicit $base$_OutputStream(SV * sv) : sv_(sv) {}\n"
-       "  explicit $base$_OutputStream(SV * sv) :\n"
-       "  sv_(sv), len_(0) {}\n"
        "  ~$base$_OutputStream() {}\n"
        "\n"
        "  bool Next(void** data, int* size)\n"
        "  {\n"
+       "    STRLEN byteCount = SvCUR(sv_);\n"
+       "    STRLEN available = SvLEN(sv_) - byteCount;\n"
+       "    if (available <= 16)\n"
+       "    {\n"
+       "      SvGROW(sv_, 2 * byteCount);\n"
+       "      available = SvLEN(sv_) - byteCount;\n"
+       "    }\n"
+       "    SvCUR_set(sv_, byteCount + available);\n"
+       "    *data = SvPVX(sv_) + byteCount;\n"
+       "    *size = available;\n"
-       "    STRLEN nlen = len_ << 1;\n"
-       "\n"
-       "    if ( nlen < 16 ) nlen = 16;\n"
-       "    SvGROW(sv_, nlen);\n"
-       "    *data = SvEND(sv_) + len_;\n"
-       "    *size = SvLEN(sv_) - len_;\n"
-       "    len_ = nlen;\n"
        "\n"
        "    return true;\n"
        "  }\n"
@@ -147,7 +145,11 @@
        "    SvCUR_set(sv_, SvLEN(sv_) - count);\n"
        "  }\n"
        "\n"
+       "  void Sync() {}\n"
-       "  void Sync() {\n"
-       "    if ( SvCUR(sv_) == 0 ) {\n"
-       "      SvCUR_set(sv_, len_);\n"
-       "    }\n"
-       "  }\n"
        "\n"
        "  int64_t ByteCount() const\n"
        "  {\n"
@@ -156,6 +158,7 @@
        "\n"
        "private:\n"
        "  SV * sv_;\n"
-       "  STRLEN len_;\n"
        "\n"
        "  GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($base$_OutputStream);\n"
        "};\n"

Original issue reported on code.google.com by [email protected] on 6 Nov 2014 at 12:32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant