Loading ...
Sorry, an error occurred while loading the content.

Re: [BUG] Inconsistent $r->print() behavior with references

Expand Messages
  • Geoffrey Young
    ... interesting. I think the issue is that after your manipulations $dataref is no longer a plain PV. I used Devel::Peek to look at $dataref before and after
    Message 1 of 35 , Dec 2, 2003
    • 0 Attachment
      Jonathan Field wrote:
      > Hi all,
      >
      > This is my first mod_perl bug report, so I'd like to start by thanking you
      > all for your great work over the years.
      >
      > The problem I am experiencing involves passing a scalar reference (instead
      > of a scalar) to $r->print(). It usually works as documented. However I
      > have come across a situation where instead of printing the contents, it
      > prints the string version of the ref itself: "SCALAR(0x8ca70e4)".
      >
      > After some research, it seems that I can trigger this behavior by doing a
      > certain type of regex on the scalar reference, specifically: a successful
      > regex that includes a backreference.

      > my $data = "hello\n";
      > my $dataref = \$data;

      > $$dataref =~ s/(h)/$1/;

      interesting.

      I think the issue is that after your manipulations $dataref is no longer a
      plain PV. I used Devel::Peek to look at $dataref before and after and it
      changes from a PV to PVMG. where this trips up mod_perl is in
      Apache::write_client:

      SV *sv = SvROK(ST(i)) && (SvTYPE(SvRV(ST(i))) == SVt_PV) ?
      (SV*)SvRV(ST(i)) : ST(i);

      so, if the scalar reference to be printed isn't of type SVt_PV it does not
      get dereferenced.

      I suppose we could change that to a SvPOK check instead, but I'm really not
      inclined to change anything here - doug has said several times that the
      magical dereferencing in $r->print() was a bad idea and should be considered
      deprecated. it's not in 2.0 either, so you'll need to dereference yourself
      in order to port your code (someday :)

      but thanks for the report - it's fun to track this kind of stuff down, even
      if we end up not changing anything :)

      --Geoff


      --
      Reporting bugs: http://perl.apache.org/bugs/
      Mail list info: http://perl.apache.org/maillist/modperl.html
    • Jonathan Field
      Thanks, all, for the prompt attention. I will update my coding habits accordingly :) Cheers ... -- Reporting bugs: http://perl.apache.org/bugs/ Mail list
      Message 35 of 35 , Dec 10, 2003
      • 0 Attachment
        Thanks, all, for the prompt attention. I will update my coding habits
        accordingly :)

        Cheers

        On Wed, 10 Dec 2003, Stas Bekman wrote:

        > I've pinged Doug and the final verdict is this:
        >
        > The print-a-scalar-reference feature is now deprecated. There are
        > known bugs when using it and it's not supported by mod_perl 2.0. If
        > you have a scalar reference containing a string to be printed,
        > dereference it before sending it to print.
        >
        > It's now documented as such.
        >
        > Jonathan, please adjust your code to dereference the scalar references before
        > sending them to print.
        >
        > __________________________________________________________________
        > Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
        > http://stason.org/ mod_perl Guide ---> http://perl.apache.org
        > mailto:stas@... http://use.perl.org http://apacheweek.com
        > http://modperlbook.org http://apache.org http://ticketmaster.com
        >


        --
        Reporting bugs: http://perl.apache.org/bugs/
        Mail list info: http://perl.apache.org/maillist/modperl.html
      Your message has been successfully submitted and would be delivered to recipients shortly.