perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoffrey Young <ge...@modperlcookbook.org>
Subject [Fwd: [rt.cpan.org #30061] $r->pnotes stores aliases not copies so is subject to action at a distance]
Date Wed, 17 Oct 2007 15:30:58 GMT
heh, didn't this just come up?

:)

gozer: I did find the documentation, and I posted it to the rt ticket.

I guess we don't have a historical way of managing rt tickets, but I'm
tempted to resolve this one as "rejected" (though the thought of
rejecting tim isn't a pleasant one ;)

--Geoff

-------- Original Message --------
Subject: [rt.cpan.org #30061] $r->pnotes stores aliases not copies so is
subject to action at a distance
Date: Wed, 17 Oct 2007 10:58:22 -0400
From: Tim_Bunce via RT <bug-mod_perl@rt.cpan.org>
Reply-To: bug-mod_perl@rt.cpan.org
To: undisclosed-recipients:;
References: <RT-Ticket-30061@rt.cpan.org>


Wed Oct 17 10:57:58 2007: Request 30061 was acted upon.
Transaction: Ticket created by TIMB
       Queue: mod_perl
     Subject: $r->pnotes stores aliases not copies so is subject to
action at a
 distance
   Broken in: (no value)
    Severity: Important
       Owner: Nobody
  Requestors: TIMB@cpan.org
      Status: new
 Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=30061 >


This code:

  $x = 42;
  $r->pnotes( 'foo', $x );
  ++$x;
  warn $r->pnotes( 'foo', $x );

should print the value that was stored, 42, but it actually prints 43!

The value stored has been modified by action at a distance. *Not good*

This can cause some very hard to debug problems, where values stored in
pnotes change for
no readily apparent reason. I know, I've spent way too long doing just
that before I identified
this as the cause.

A workaround for affected code is to assign to a temporary variable so
the alias taken by
pnotes isn't an alias for the orginal value:

    $r->pnotes( 'foo', my $tmp = $x )

The minimal fix is to change:

    hv_store(cfg->pnotes, key, len, SvREFCNT_inc(val), FALSE);

in pnotes in src/modules/perl/Apache.xs to something more like

   SV **svp = hv_fetch(cfg->pnotes, key, len, TRUE);
   sv_setsv(*svp, val);

with a little more work you could eliminate the earlier hv_exists and
hv_fetch by doing

  SV **svp = hv_fetch(cfg->pnotes, key, len, (val) ? TRUE : FALSE);

and working with svp.

Tim Bunce.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message