Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4365

Perl generated code uses indirect object syntax, which occasionally causes compilation errors.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.11.0
    • Component/s: Perl - Compiler
    • Labels:

      Description

      When running the Thrift compiler for Perl the automatically generated code uses "Indirect Object Syntax". So the generated code looks like this:

      $self->{success} = new contact_types::Response();
      

      It should look like this:

      $self->{success} = contact_types::Response->new();
      

      I found in some cases the indirect object syntax can actually cause failures because Perl gets confused and thinks Response is a subroutine, with an error like this:

      Undefined subroutine &user_types::Response called at gen-perl/user/Service.pm line 131.
      

      If you look in https://perldoc.perl.org/perlobj.html under the "Indirect Object Syntax" heading, you see it says:
      "Outside of the file handle case, use of this syntax is discouraged as it can confuse the Perl interpreter. See below for more details.".
      Fixing this problem should be straight forward. In the https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_perl_generator.cc it should instead of doing this:

      out << indent() << "$" << prefix << " = new " << perl_namespace(tstruct->get_program())
            << tstruct->get_name() << "();" << endl << indent() << "$xfer += $" << prefix
            << "->read($input);" << endl;
      

      Do this:

      out << indent() << "$" << prefix << " = " << perl_namespace(tstruct->get_program())
            << tstruct->get_name() << "->new();" << endl << indent() << "$xfer += $" << prefix
            << "->read($input);" << endl;
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jking3 James E. King III
                Reporter:
                thefunster Finn Isaac Norris Colman
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: