You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philippe M. Chiasson" <go...@ectoplasm.org> on 2006/03/13 23:55:32 UTC
Re: [MP2] possible pnotes bug?
Torsten Foertsch wrote:
> Geoff,
>
> On Tuesday 10 January 2006 19:21, Geoffrey Young wrote:
>
>>>Nevertheless, I really think it is a bug, since it provokes action at a
>>>distance.
>>
>>I think it's best filed under "feature" - the mp1 behavior is not going
>>to change and has been more than ok for years and years now, and it's
>>priobably better to have mp1 and mp2 be in sync here in the
>>principle-of-least-surprise-while-migrating kind of way than to go
>>messing around with the API now
Reviving a somewhat old thread here, so for context, here it is, archived:
http://www.gossamer-threads.com/lists/modperl/modperl/86483
Basically, I think documenting this as a feature was not such a good idea. Who
can expect that this is correct/expected behaviour
my $foo = 123;
$r->pnotes('foo' => $foo);
$foo = 456;
$r->pnotes('foo') # <== now 456
I understand _why_ this hapenning, but I think that if it's not a bug, it's certainly
a very strange behaviour, compared to, say $note{foo} = $foo; I would think that
the casual user would be bitten by something like this, even though it's documented.
Is there any good reason _not_ to make this pnotes code behave just like a hash,
and store a copy of the scalar ?
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Tuesday 14 March 2006 03:01, Philippe M. Chiasson wrote:
> >>I'm fine with fixing things in 2.0 if that's the majority consensus.
>
> I'd certainly put my vote in that direction.
So do I. Don't forget connection pnotes.
Torsten
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 15 March 2006 18:23, Geoffrey Young wrote:
> > + my $foo = 123;
> > + $r->pnotes('foo' => $foo);
> > + $foo = 456;
> > + $r->pnotes('foo') # <== now 456 (in 2.0.2)
> > + $r->pnotes('foo') # <== left at 123 (in 2.0.3)
>
> actually, I'm re-thinking my stance on this. a common use of pnotes is to
> pass objects around. if I understand things correctly, the current
> situation is this
>
> -- some handler
> my $o = Foo->new;
> $r->pnotes(foo => $o);
>
> -- next handler
> my $o = $r->pnotes('foo');
> $o->set(bar => 1); # sets $o->{_bar} = 1
>
> -- another handler
> my $o = $r->pnotes('foo');
> my $bar = $o->bar; # 1
>
> I actually thing that would be somewhat common. and as I understand
> things, the fix would require the middle step to be
>
> -- next handler
> my $o = $r->pnotes('foo');
> $o->set(bar => 1); # sets $o->{_bar} = 1
> $r->pnotes(foo => $o);
>
> in order for $o to maintain it's internal state. is that right?
I don't think so. An object is a blessed reference. Hence, pnotes store only
the reference. Your set operation in next handler modifies the object itself
not the reference. Hence, there is no need to store it again. With normal
hashes this can also be done:
$h{foo}=$o;
$o->set(bar=>1);
# no need to update $h{foo} here
$h{foo}->bar; # 1
Torsten
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 15 March 2006 18:23, Geoffrey Young wrote:
> > + my $foo = 123;
> > + $r->pnotes('foo' => $foo);
> > + $foo = 456;
> > + $r->pnotes('foo') # <== now 456 (in 2.0.2)
> > + $r->pnotes('foo') # <== left at 123 (in 2.0.3)
>
> actually, I'm re-thinking my stance on this. a common use of pnotes is to
> pass objects around. if I understand things correctly, the current
> situation is this
>
> -- some handler
> my $o = Foo->new;
> $r->pnotes(foo => $o);
>
> -- next handler
> my $o = $r->pnotes('foo');
> $o->set(bar => 1); # sets $o->{_bar} = 1
>
> -- another handler
> my $o = $r->pnotes('foo');
> my $bar = $o->bar; # 1
>
> I actually thing that would be somewhat common. and as I understand
> things, the fix would require the middle step to be
>
> -- next handler
> my $o = $r->pnotes('foo');
> $o->set(bar => 1); # sets $o->{_bar} = 1
> $r->pnotes(foo => $o);
>
> in order for $o to maintain it's internal state. is that right?
I don't think so. An object is a blessed reference. Hence, pnotes store only
the reference. Your set operation in next handler modifies the object itself
not the reference. Hence, there is no need to store it again. With normal
hashes this can also be done:
$h{foo}=$o;
$o->set(bar=>1);
# no need to update $h{foo} here
$h{foo}->bar; # 1
Torsten
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 15 March 2006 18:55, Perrin Harkins wrote:
> On Wed, 2006-03-15 at 12:23 -0500, Geoffrey Young wrote:
> > I actually thing that would be somewhat common. and as I understand
> > things, the fix would require the middle step to be
> >
> > -- next handler
> > my $o = $r->pnotes('foo');
> > $o->set(bar => 1); # sets $o->{_bar} = 1
> > $r->pnotes(foo => $o);
> >
> > in order for $o to maintain it's internal state. is that right? if so,
> > I don't like that very much.
>
> I agree, cloning is not the answer. What you want really want here is
> for it to behave like a normal perl variable assignment, i.e. if you
> assign a reference, it stays a reference, and if you assign a value,
> it's just a value, not a double-secret-probation reference. I don't
> think it's a good idea to change this unless it can be done that way.
The current implementation of
$r->pnotes(foo=>$x)
is halfway similar to
$r->pnotes->{foo}=\$x.
Only halfway because fetching the value works as expected: $r->pnotes('foo').
In pure Perl the exact behavior cannot be expressed.
Internally pnotes are stored in a HV. $r->pnotes without arguments returns a
reference to that HV. Hence, $r->pnotes->{foo}=$o works as a normal
assignment of a hash element:
$ perl -MDevel::Peek -e '$x=1; Dump($x); $h{x}=$x; Dump(\%h);'
SV = IV(0x816e598) at 0x816c6fc
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
SV = RV(0x8178d48) at 0x8151d40
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x816c744
SV = PVHV(0x81699c8) at 0x816c744
...
Elt "x" HASH = 0x9303a5e5
SV = IV(0x816e59c) at 0x8151c20
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
Note that the refcounts of both IVs the first after $x=1 and the second in %h
are 1. Also the IVs themself are different objects one at 0x816e598 the
second at 0x816e59c.
With $r->pnotes->{x}=$x the output is similar.
But with $r->pnotes(x=>$x) it changes:
SV = IV(0x84c0664) at 0x866099c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,IOK,pIOK)
IV = 1
SV = RV(0x8640b68) at 0x8651a7c
REFCNT = 2
FLAGS = (TEMP,ROK)
RV = 0x86397ec
SV = PVHV(0x86453a0) at 0x86397ec
...
Elt "x" HASH = 0x9303a5e5
SV = IV(0x84c0664) at 0x866099c
REFCNT = 2
FLAGS = (PADBUSY,PADMY,IOK,pIOK)
IV = 1
Now the both IVs are the same (0x84c0664) and the refcount after storing as a
pnote is 2. And here is the problem. $r->pnotes->{x}=$x and $r->pnotes(x=>$x)
are different operations. The first stores a copy of the IV represented by
$x. The second stores the IV $x itself. This is somehow similar to *y=\$x:
$ perl -e '$x=1; *y=\$x; $x++; print "$y\n";'
2
$ perl -MDevel::Peek -e '$x=1; Dump($x); *y=\$x; Dump($y);'
SV = IV(0x816e590) at 0x816c6f4
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
SV = IV(0x816e590) at 0x816c6f4
REFCNT = 2
FLAGS = (IOK,pIOK)
IV = 1
I think it is a bug even in MP1.
Here the code that produces the output in error_log:
package pn;
use strict;
use Apache2::RequestRec;
use Apache2::RequestIO;
use Apache2::RequestUtil;
use Apache2::Const -compile=>'OK';
use Devel::Peek;
sub handler {
my $r=shift;
my $x=1;
Dump($x);
$r->pnotes(x=>$x);
Dump($r->pnotes);
$r->print("ok\n");
return Apache2::Const::OK;
}
1;
Devel::Peek uses buffered output at C-level. Hence, you probably have to
restart the server to see the actual output.
Torsten
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 15 March 2006 18:55, Perrin Harkins wrote:
> On Wed, 2006-03-15 at 12:23 -0500, Geoffrey Young wrote:
> > I actually thing that would be somewhat common. and as I understand
> > things, the fix would require the middle step to be
> >
> > -- next handler
> > my $o = $r->pnotes('foo');
> > $o->set(bar => 1); # sets $o->{_bar} = 1
> > $r->pnotes(foo => $o);
> >
> > in order for $o to maintain it's internal state. is that right? if so,
> > I don't like that very much.
>
> I agree, cloning is not the answer. What you want really want here is
> for it to behave like a normal perl variable assignment, i.e. if you
> assign a reference, it stays a reference, and if you assign a value,
> it's just a value, not a double-secret-probation reference. I don't
> think it's a good idea to change this unless it can be done that way.
The current implementation of
$r->pnotes(foo=>$x)
is halfway similar to
$r->pnotes->{foo}=\$x.
Only halfway because fetching the value works as expected: $r->pnotes('foo').
In pure Perl the exact behavior cannot be expressed.
Internally pnotes are stored in a HV. $r->pnotes without arguments returns a
reference to that HV. Hence, $r->pnotes->{foo}=$o works as a normal
assignment of a hash element:
$ perl -MDevel::Peek -e '$x=1; Dump($x); $h{x}=$x; Dump(\%h);'
SV = IV(0x816e598) at 0x816c6fc
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
SV = RV(0x8178d48) at 0x8151d40
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x816c744
SV = PVHV(0x81699c8) at 0x816c744
...
Elt "x" HASH = 0x9303a5e5
SV = IV(0x816e59c) at 0x8151c20
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
Note that the refcounts of both IVs the first after $x=1 and the second in %h
are 1. Also the IVs themself are different objects one at 0x816e598 the
second at 0x816e59c.
With $r->pnotes->{x}=$x the output is similar.
But with $r->pnotes(x=>$x) it changes:
SV = IV(0x84c0664) at 0x866099c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,IOK,pIOK)
IV = 1
SV = RV(0x8640b68) at 0x8651a7c
REFCNT = 2
FLAGS = (TEMP,ROK)
RV = 0x86397ec
SV = PVHV(0x86453a0) at 0x86397ec
...
Elt "x" HASH = 0x9303a5e5
SV = IV(0x84c0664) at 0x866099c
REFCNT = 2
FLAGS = (PADBUSY,PADMY,IOK,pIOK)
IV = 1
Now the both IVs are the same (0x84c0664) and the refcount after storing as a
pnote is 2. And here is the problem. $r->pnotes->{x}=$x and $r->pnotes(x=>$x)
are different operations. The first stores a copy of the IV represented by
$x. The second stores the IV $x itself. This is somehow similar to *y=\$x:
$ perl -e '$x=1; *y=\$x; $x++; print "$y\n";'
2
$ perl -MDevel::Peek -e '$x=1; Dump($x); *y=\$x; Dump($y);'
SV = IV(0x816e590) at 0x816c6f4
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
SV = IV(0x816e590) at 0x816c6f4
REFCNT = 2
FLAGS = (IOK,pIOK)
IV = 1
I think it is a bug even in MP1.
Here the code that produces the output in error_log:
package pn;
use strict;
use Apache2::RequestRec;
use Apache2::RequestIO;
use Apache2::RequestUtil;
use Apache2::Const -compile=>'OK';
use Devel::Peek;
sub handler {
my $r=shift;
my $x=1;
Dump($x);
$r->pnotes(x=>$x);
Dump($r->pnotes);
$r->print("ok\n");
return Apache2::Const::OK;
}
1;
Devel::Peek uses buffered output at C-level. Hence, you probably have to
restart the server to see the actual output.
Torsten
Re: [MP2] possible pnotes bug?
Posted by Frank Wiles <fr...@wiles.org>.
On Wed, 15 Mar 2006 12:23:38 -0500
Geoffrey Young <ge...@modperlcookbook.org> wrote:
> I actually thing that would be somewhat common. and as I understand
> things, the fix would require the middle step to be
>
> -- next handler
> my $o = $r->pnotes('foo');
> $o->set(bar => 1); # sets $o->{_bar} = 1
> $r->pnotes(foo => $o);
>
> in order for $o to maintain it's internal state. is that right? if
> so, I don't like that very much. in fact, I'll bet that doug
> originally coded pnotes to behave the way it currently does on
> purpose, since the original force behind pnotes was to be able to
> pass objects around.
>
> so, I think I'm leaning more towards "the current behavior is not
> only not broken, it's intentional" camp.
Yes, but I've always seen pnotes as more of a caching/passing
mechanism. Much like Cache::FastMmap or Memcached. Personally,
I would want to middle step to ensure that I really do want that
value to be seen by other handlers.
But maybe I'm the weirdo here and others use pnotes more like
you describe.
---------------------------------
Frank Wiles <fr...@wiles.org>
http://www.wiles.org
---------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Thursday 16 March 2006 00:39, Geoffrey Young wrote:
> >>>in order for $o to maintain it's internal state. is that right? if so,
> >>> I don't like that very much.
> >
> > It's not right. You are confusing scalars with references in that
> > example.
>
> ook, my bad - I thought the proposed "solution" was to always dereference
> pnotes behind the scenes, making the additional storage a requirement.
>
> but, just in case I'm not the only one confused, I'd propose a path like
> this...
>
> o create some (many?) additional pnotes tests that exercise the different
> ways we think people will be using pnotes in almost all normal
> circumstances we can think of. digging through CPAN might be a good idea.
>
> o offer that any fix shouldn't break the tests
Here are some tests that cover your concerns so far:
package TestPn::pn;
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestUtil;
use Apache2::RequestUtil;
use Apache2::Const -compile => 'OK';
{
package _O;
sub new {bless {}=>__PACKAGE__}
sub member {$_[0]->{x}=$_[1] if @_>1; $_[0]->{x}}
}
sub handler {
my $r = shift;
Apache::Test::test_pm_refresh();
plan $r, tests => 20;
my $x;
# pnotes as hash ref
# this 1st set of tests are all ok, because $r->pnotes returns a normal
# hash ref
$x=1;
$r->pnotes->{x}=$x;
$x++;
ok t_cmp $r->pnotes('x'), 1, q{hash ref1};
ok t_cmp $r->pnotes->{x}, 1, q{hash ref2};
delete $r->pnotes->{x};
# pnotes method interface
# these two fail
$x=1;
$r->pnotes(x=>$x);
$x++;
ok t_cmp $r->pnotes('x'), 1, q{method1};
ok t_cmp $r->pnotes->{x}, 1, q{method2};
delete $r->pnotes->{x};
# pnotes as hash: storing and retrieving objects
my $o1=_O->new;
$o1->member(1);
my $o2=_O->new;
$o2->member(2);
# check if the objects work properly
ok t_cmp $o1->member, 1, q{o1 setup};
ok t_cmp $o2->member, 2, q{o2 setup};
# these tests succeed. they show normal object behavior.
$r->pnotes->{o}=$o1;
$o1->member(10);
ok t_cmp $r->pnotes('o')->member, 10, q{hash ref obj 1};
ok t_cmp $r->pnotes->{o}->member, 10, q{hash ref obj 2};
$r->pnotes('o')->member(100);
ok t_cmp $r->pnotes('o')->member, 100, q{hash ref obj 3};
ok t_cmp $r->pnotes->{o}->member, 100, q{hash ref obj 4};
# the following two succeed only because the hash ref interface
# was used to assing $r->pnotes->{o}.
$o1=$o2;
ok t_cmp $r->pnotes('o')->member, 100, q{hash ref obj 5};
ok t_cmp $r->pnotes->{o}->member, 100, q{hash ref obj 6};
delete $r->pnotes->{o};
# pnotes method interface: storing and retrieving objects
$o1=_O->new;
$o1->member(1);
$o2=_O->new;
$o2->member(2);
ok t_cmp $o1->member, 1, q{o1 setup};
ok t_cmp $o2->member, 2, q{o2 setup};
$r->pnotes(o=>$o1);
$o1->member(10);
ok t_cmp $r->pnotes('o')->member, 10, q{method obj 1};
ok t_cmp $r->pnotes->{o}->member, 10, q{method obj 2};
$r->pnotes('o')->member(100);
ok t_cmp $r->pnotes('o')->member, 100, q{method obj 3};
ok t_cmp $r->pnotes->{o}->member, 100, q{method obj 4};
# these two fail, because the assignment $o1=$o2 modifies $r->pnotes->{o}.
$o1=$o2;
ok t_cmp $r->pnotes('o')->member, 100, q{method obj 5};
ok t_cmp $r->pnotes->{o}->member, 100, q{method obj 6};
delete $r->pnotes->{o};
Apache2::Const::OK;
}
1;
The patch is IMO really simple:
In xs/Apache2/ConnectionUtil/Apache2__ConnectionUtil.h and
xs/Apache2/RequestUtil/Apache2__RequestUtil.h
if (val) {
retval = *hv_store(ccfg->pnotes, k, len,
- SvREFCNT_inc(val), 0);
+ newSVsv(val), 0);
}
else if (hv_exists(ccfg->pnotes, k, len)) {
retval = *hv_fetch(ccfg->pnotes, k, len, FALSE);
The attached patch was made a few days ago. It applies to r384596 with the
connection-pnotes patch applied before. All tests succeed.
Torsten
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Thursday 16 March 2006 00:39, Geoffrey Young wrote:
> >>>in order for $o to maintain it's internal state. is that right? if so,
> >>> I don't like that very much.
> >
> > It's not right. You are confusing scalars with references in that
> > example.
>
> ook, my bad - I thought the proposed "solution" was to always dereference
> pnotes behind the scenes, making the additional storage a requirement.
>
> but, just in case I'm not the only one confused, I'd propose a path like
> this...
>
> o create some (many?) additional pnotes tests that exercise the different
> ways we think people will be using pnotes in almost all normal
> circumstances we can think of. digging through CPAN might be a good idea.
>
> o offer that any fix shouldn't break the tests
Here are some tests that cover your concerns so far:
package TestPn::pn;
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestUtil;
use Apache2::RequestUtil;
use Apache2::Const -compile => 'OK';
{
package _O;
sub new {bless {}=>__PACKAGE__}
sub member {$_[0]->{x}=$_[1] if @_>1; $_[0]->{x}}
}
sub handler {
my $r = shift;
Apache::Test::test_pm_refresh();
plan $r, tests => 20;
my $x;
# pnotes as hash ref
# this 1st set of tests are all ok, because $r->pnotes returns a normal
# hash ref
$x=1;
$r->pnotes->{x}=$x;
$x++;
ok t_cmp $r->pnotes('x'), 1, q{hash ref1};
ok t_cmp $r->pnotes->{x}, 1, q{hash ref2};
delete $r->pnotes->{x};
# pnotes method interface
# these two fail
$x=1;
$r->pnotes(x=>$x);
$x++;
ok t_cmp $r->pnotes('x'), 1, q{method1};
ok t_cmp $r->pnotes->{x}, 1, q{method2};
delete $r->pnotes->{x};
# pnotes as hash: storing and retrieving objects
my $o1=_O->new;
$o1->member(1);
my $o2=_O->new;
$o2->member(2);
# check if the objects work properly
ok t_cmp $o1->member, 1, q{o1 setup};
ok t_cmp $o2->member, 2, q{o2 setup};
# these tests succeed. they show normal object behavior.
$r->pnotes->{o}=$o1;
$o1->member(10);
ok t_cmp $r->pnotes('o')->member, 10, q{hash ref obj 1};
ok t_cmp $r->pnotes->{o}->member, 10, q{hash ref obj 2};
$r->pnotes('o')->member(100);
ok t_cmp $r->pnotes('o')->member, 100, q{hash ref obj 3};
ok t_cmp $r->pnotes->{o}->member, 100, q{hash ref obj 4};
# the following two succeed only because the hash ref interface
# was used to assing $r->pnotes->{o}.
$o1=$o2;
ok t_cmp $r->pnotes('o')->member, 100, q{hash ref obj 5};
ok t_cmp $r->pnotes->{o}->member, 100, q{hash ref obj 6};
delete $r->pnotes->{o};
# pnotes method interface: storing and retrieving objects
$o1=_O->new;
$o1->member(1);
$o2=_O->new;
$o2->member(2);
ok t_cmp $o1->member, 1, q{o1 setup};
ok t_cmp $o2->member, 2, q{o2 setup};
$r->pnotes(o=>$o1);
$o1->member(10);
ok t_cmp $r->pnotes('o')->member, 10, q{method obj 1};
ok t_cmp $r->pnotes->{o}->member, 10, q{method obj 2};
$r->pnotes('o')->member(100);
ok t_cmp $r->pnotes('o')->member, 100, q{method obj 3};
ok t_cmp $r->pnotes->{o}->member, 100, q{method obj 4};
# these two fail, because the assignment $o1=$o2 modifies $r->pnotes->{o}.
$o1=$o2;
ok t_cmp $r->pnotes('o')->member, 100, q{method obj 5};
ok t_cmp $r->pnotes->{o}->member, 100, q{method obj 6};
delete $r->pnotes->{o};
Apache2::Const::OK;
}
1;
The patch is IMO really simple:
In xs/Apache2/ConnectionUtil/Apache2__ConnectionUtil.h and
xs/Apache2/RequestUtil/Apache2__RequestUtil.h
if (val) {
retval = *hv_store(ccfg->pnotes, k, len,
- SvREFCNT_inc(val), 0);
+ newSVsv(val), 0);
}
else if (hv_exists(ccfg->pnotes, k, len)) {
retval = *hv_fetch(ccfg->pnotes, k, len, FALSE);
The attached patch was made a few days ago. It applies to r384596 with the
connection-pnotes patch applied before. All tests succeed.
Torsten
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Tuesday 06 June 2006 12:38, Philip M. Gollucci wrote:
> Torsten Foertsch wrote:
> > What is the common understanding on this point by now?
> > - retval = *hv_store(*pnotes, k, len, SvREFCNT_inc(val), 0);
> > + retval = *hv_store(*pnotes, k, len, newSVsv(val), 0);
>
> Pushes the cobwebs aside.....
> I agree that the change you propose will accomplish what you want, but
> at some point later, don't we need to free this new AV()?
The only reference to the new SV is from the pnotes HV. When the HV is
destroyed all contained SVs will be destroyed as well, right? Correct me if I
am wrong here. My XS experience is quite limited.
Torsten
Re: [MP2] possible pnotes bug?
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
> But I understand that such a change cannot be done without due warning. We all
> remember well the complains after 2.0.0-rc5 or so was released.
>
> We could document the current behavior of $r->pnotes(key=>value) and mark it
> as to be changed in a future release. How about that?
I am okay with this.
+1
--
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F
"It takes a minute to have a crush on someone, an hour to like someone,
and a day to love someone, but it takes a lifetime to forget someone..."
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Friday 09 June 2006 19:21, Geoffrey Young wrote:
> > This is said in the description of pnotes:
> >
> > $hash_ref = $r->pnotes();
> > ...
> > if no arguments are passed, a hash reference is returned, which can
> > then be directly accessed without going through the "pnotes()" interface.
> >
> > Since a hash reference is returned it is clear that it is accessed as
> > pnotes->{key}.
>
> I'm not doubting the interface exists. I'm saying that it's not in use
> in the wild nearly as often as the method call.
Yes, I was using it too until it has bitten me, ;-)
> > I think the behavior of $r->pnotes(key=>value) is buggy not because I
> > want something special. I want it to behave simply like an ordinary perl
> > hash.
> >
> > Further I really think it is buggy because it leads to very difficult
> > traceable bugs in applications using it. The docs says:
> >
> > $r->pnotes(foo => [1..5]);
> > $val = $r->pnotes("foo");
> >
> > If this example is changed into:
> >
> > $var=[1..5];
> > $r->pnotes(foo => $var);
> >
> > $var=[’a’..’c’]; # this changes the pnote behind the scene
> >
> > $val = $r->pnotes("foo");
> >
> > What would you expect $val to be? [1..5] or [’a’..’c’]?
> >
> > I think every new programmer and even almost all experienced mod_perl
> > users would say it is [1..5].
>
> but this has nothing to do with it, really - we're talking about
> changing the way $r->pnotes(key => value) has historically behaved for,
> what, 8 years? you can't just do this on users and introduce wickedly
> difficult bugs to track down without some serious consideration. well,
> you can do whatever you want with your own code, but mod_perl as a
> project has an obligation to its established userbase to not introduce
> pain on purpose, or at least without due warning (such as would come
> from a major version bump).
I understand.
You can look at it in two ways.
1) no matter what, it has been this way for 8 years. So don't touch it!
But since the behavior is really weird it must be described and thoroughly
explained (as I have tried to do this morning).
2) it is a long surviving bug.
Again, because the behavior is weird I think there is a certain amount of
applications out there using this feature that work only by accident. There
is certainly a certain amount of applications using this feature
deliberately. But if a program relies on variables changing by itself behind
the scene it is in my opinion not maintainable and belongs rather to the
obfuscated perl contest.
I think, people that got bitten by this bug simply did not complain and
changed their code more or less randomly unless it had worked somehow. Simply
introducing a new variable $var2=[’a’..’c’] would have cured the problem.
But I understand that such a change cannot be done without due warning. We all
remember well the complains after 2.0.0-rc5 or so was released.
We could document the current behavior of $r->pnotes(key=>value) and mark it
as to be changed in a future release. How about that?
Torsten
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> This is said in the description of pnotes:
>
> $hash_ref = $r->pnotes();
> ...
> if no arguments are passed, a hash reference is returned, which can then be
> directly accessed without going through the "pnotes()" interface.
>
> Since a hash reference is returned it is clear that it is accessed as
> pnotes->{key}.
I'm not doubting the interface exists. I'm saying that it's not in use
in the wild nearly as often as the method call.
>
> Btw, this description does not mention a tied hash. Maybe because it is in
> fact not tied. It is a normal perl hash only hidden in the C layer.
yeah, ok, I was wrong. all the APR::Table foo is tied, but pnotes is
not. blasted inconsistent interfaces...
>
> I think the behavior of $r->pnotes(key=>value) is buggy not because I want
> something special. I want it to behave simply like an ordinary perl hash.
>
> Further I really think it is buggy because it leads to very difficult
> traceable bugs in applications using it. The docs says:
>
> $r->pnotes(foo => [1..5]);
> $val = $r->pnotes("foo");
>
> If this example is changed into:
>
> $var=[1..5];
> $r->pnotes(foo => $var);
>
> $var=[’a’..’c’]; # this changes the pnote behind the scene
>
> $val = $r->pnotes("foo");
>
> What would you expect $val to be? [1..5] or [’a’..’c’]?
>
> I think every new programmer and even almost all experienced mod_perl users
> would say it is [1..5].
but this has nothing to do with it, really - we're talking about
changing the way $r->pnotes(key => value) has historically behaved for,
what, 8 years? you can't just do this on users and introduce wickedly
difficult bugs to track down without some serious consideration. well,
you can do whatever you want with your own code, but mod_perl as a
project has an obligation to its established userbase to not introduce
pain on purpose, or at least without due warning (such as would come
from a major version bump).
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Friday 09 June 2006 17:48, Geoffrey Young wrote:
> Geoffrey Young wrote:
> > I didn't realize there was a difference between this (preferred for eons)
> > syntax and the tied (essentially deprecated, never suggested on list)
> > syntax. that there is a difference constitutes a bug in and of itself.
>
> and just to make sure I wasn't making things up
>
> modperl-docs$ grep -r 'pnotes->{' * |grep -v svn|grep -v dst_html|wc -l
> 4
>
> modperl-docs$ grep -r 'pnotes(' * |grep -v svn|grep -v dst_html|wc -l
> 28
>
> that's mp1 and mp2 docs, and all 4 of those tied references are from the
> documentation explaing the thing we're talking about, so they don't count
> :)
This is said in the description of pnotes:
$hash_ref = $r->pnotes();
...
if no arguments are passed, a hash reference is returned, which can then be
directly accessed without going through the "pnotes()" interface.
Since a hash reference is returned it is clear that it is accessed as
pnotes->{key}.
Btw, this description does not mention a tied hash. Maybe because it is in
fact not tied. It is a normal perl hash only hidden in the C layer.
I think the behavior of $r->pnotes(key=>value) is buggy not because I want
something special. I want it to behave simply like an ordinary perl hash.
Further I really think it is buggy because it leads to very difficult
traceable bugs in applications using it. The docs says:
$r->pnotes(foo => [1..5]);
$val = $r->pnotes("foo");
If this example is changed into:
$var=[1..5];
$r->pnotes(foo => $var);
$var=[’a’..’c’]; # this changes the pnote behind the scene
$val = $r->pnotes("foo");
What would you expect $val to be? [1..5] or [’a’..’c’]?
I think every new programmer and even almost all experienced mod_perl users
would say it is [1..5].
And it would be true if the code is changed to:
$var=[1..5];
$r->pnotes->{foo} = $var;
$var=[’a’..’c’];
$val = $r->pnotes("foo");
Torsten
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Geoffrey Young wrote:
> I didn't realize there was a difference between this (preferred for eons)
> syntax and the tied (essentially deprecated, never suggested on list)
> syntax. that there is a difference constitutes a bug in and of itself.
and just to make sure I wasn't making things up
modperl-docs$ grep -r 'pnotes->{' * |grep -v svn|grep -v dst_html|wc -l
4
modperl-docs$ grep -r 'pnotes(' * |grep -v svn|grep -v dst_html|wc -l
28
that's mp1 and mp2 docs, and all 4 of those tied references are from the
documentation explaing the thing we're talking about, so they don't count :)
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Torsten Foertsch wrote:
> On Friday 09 June 2006 15:04, Geoffrey Young wrote:
>
>>>The more I think of it the more I am convinced that this is not good. If
>>>you think $r->pnotes behaves the way it is designed to then let it be so.
>>>There is indeed an interface that already does what the new one is
>>>intended to do, that is $r->pnotes->{key}=value. Hence, no need for an
>>>additional interface.
>>
>>I'm upset that there is a difference in the two interfaces to pnotes() -
>>this just shouldn't be the case at all.
>>
>>care to add a TODO test to pnotes in the mp2 test suite? that pnotes()
>>behaves differently depending on how it's called _needs_ to be fixed imho.
>
>
> Now, I am a bit puzzled. For months you have convinced me that pnotes()
> behaves the way it is designed to.
it does... at least if you use the $r->pnotes(key => value) syntax. I
didn't realize there was a difference between this (preferred for eons)
syntax and the tied (essentially deprecated, never suggested on list)
syntax. that there is a difference constitutes a bug in and of itself.
> Now that I have given up you out of the
> sudden switch hats. Is my English so bad to be not understandable?
>
> Anyway, I'd like to provide these tests if we agree on what the "right"
> interface is. Should
>
> a) $r->pnotes(key=>value) behave like $r->pnotes->{key}=value or
>
> b) $r->pnotes->{key}=value behave like $r->pnotes(key=>value)
>
> I would vote for a). That means $r->pnotes(key=>value) is to be changed to
> behave like an ordinary Perl hash.
I think the solution for the moment is to keep thing the way they are in
1.3, then determine a suitable path for altering the behavior in some
2.X release cycle. however the masses think the pnotes referencing
thing should behave is fine with me, provided both forms behave
identically - there should be absolutely no difference whether you're
using the method or tied interface to any tied object.
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Friday 09 June 2006 15:04, Geoffrey Young wrote:
> > The more I think of it the more I am convinced that this is not good. If
> > you think $r->pnotes behaves the way it is designed to then let it be so.
> > There is indeed an interface that already does what the new one is
> > intended to do, that is $r->pnotes->{key}=value. Hence, no need for an
> > additional interface.
>
> I'm upset that there is a difference in the two interfaces to pnotes() -
> this just shouldn't be the case at all.
>
> care to add a TODO test to pnotes in the mp2 test suite? that pnotes()
> behaves differently depending on how it's called _needs_ to be fixed imho.
Now, I am a bit puzzled. For months you have convinced me that pnotes()
behaves the way it is designed to. Now that I have given up you out of the
sudden switch hats. Is my English so bad to be not understandable?
Anyway, I'd like to provide these tests if we agree on what the "right"
interface is. Should
a) $r->pnotes(key=>value) behave like $r->pnotes->{key}=value or
b) $r->pnotes->{key}=value behave like $r->pnotes(key=>value)
I would vote for a). That means $r->pnotes(key=>value) is to be changed to
behave like an ordinary Perl hash.
Torsten
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Friday 09 June 2006 09:13, Torsten Foertsch wrote:
> The behavior must be well documented and the difference thoroughly
> explained. That's all. I'll see if I can come up with a better patch.
How about that?
Torsten
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> The more I think of it the more I am convinced that this is not good. If you
> think $r->pnotes behaves the way it is designed to then let it be so. There
> is indeed an interface that already does what the new one is intended to do,
> that is $r->pnotes->{key}=value. Hence, no need for an additional interface.
I'm upset that there is a difference in the two interfaces to pnotes() -
this just shouldn't be the case at all.
care to add a TODO test to pnotes in the mp2 test suite? that pnotes()
behaves differently depending on how it's called _needs_ to be fixed imho.
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Thursday 08 June 2006 19:13, Philippe M. Chiasson wrote:
> I wouldn't mind introducing $r->pnotes_noref or
> sth to fix it
The more I think of it the more I am convinced that this is not good. If you
think $r->pnotes behaves the way it is designed to then let it be so. There
is indeed an interface that already does what the new one is intended to do,
that is $r->pnotes->{key}=value. Hence, no need for an additional interface.
The behavior must be well documented and the difference thoroughly explained.
That's all. I'll see if I can come up with a better patch.
When I got bitten by it in the first place it took me about a day to figure
out what had happend but hey it was not documented then at all.
Torsten
Re: [MP2] possible pnotes bug?
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
> were working around it. I wouldn't mind introducing $r->pnotes_noref or
> sth to fix it, but that's
> just me ;-)
Now that idea I LIKE!
+1
--
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F
"It takes a minute to have a crush on someone, an hour to like someone,
and a day to love someone, but it takes a lifetime to forget someone..."
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Tom Schindl <to...@bestsolution.at>.
Hi,
>>From my point of view changing pnotes in mp1/2:
--1 in mp1
--1 in mp2.0.x
+1 in mp2.x
for $r->pnotes_noref():
-1 mp1 who needs that?
-1 in mp-2.0.x adding this api would cause everybody to change code for
mp-2.x without any reason!
-1 in mp-2.x
Tom
Philippe M. Chiasson wrote:
> Perrin Harkins wrote:
>
>>On Thu, 2006-06-08 at 09:21 +0200, Torsten Foertsch wrote:
>>
>>
>>>No, it does not. $r->pnotes->{key}=value behaves like a Perl hash.
>>>$r->pnotes(key, value) does not. But anyway if you all think it's okay the way
>>>it is I'll simply not use the second version anymore.
>>>
>>
>>Oh, you're right, I remember now. It takes a reference to the passed
>>value in a situation where normally one would expect a copy. In
>>practice, I only put references in pnotes anyway, so this has never
>>bothered me.
>>
>
> Same with me, I've never been bitten by that bug either, sticking only
> scalars in there.
>
>>I'd be okay with changing this in future releases as long as it doesn't
>>change in the 1.x series.
>>
>
> Yeah, 1.x is most likely never going to be _fixed_ in that regard. Too
> many people using it
> were working around it. I wouldn't mind introducing $r->pnotes_noref or
> sth to fix it, but that's
> just me ;-)
>
> Gozer out.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Perrin Harkins wrote:
> On Thu, 2006-06-08 at 09:21 +0200, Torsten Foertsch wrote:
>
>> No, it does not. $r->pnotes->{key}=value behaves like a Perl hash.
>> $r->pnotes(key, value) does not. But anyway if you all think it's okay the way
>> it is I'll simply not use the second version anymore.
>>
>
> Oh, you're right, I remember now. It takes a reference to the passed
> value in a situation where normally one would expect a copy. In
> practice, I only put references in pnotes anyway, so this has never
> bothered me.
>
Same with me, I've never been bitten by that bug either, sticking only
scalars in there.
> I'd be okay with changing this in future releases as long as it doesn't
> change in the 1.x series.
>
Yeah, 1.x is most likely never going to be _fixed_ in that regard. Too
many people using it
were working around it. I wouldn't mind introducing $r->pnotes_noref or
sth to fix it, but that's
just me ;-)
Gozer out.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2006-06-08 at 09:21 +0200, Torsten Foertsch wrote:
> No, it does not. $r->pnotes->{key}=value behaves like a Perl hash.
> $r->pnotes(key, value) does not. But anyway if you all think it's okay the way
> it is I'll simply not use the second version anymore.
Oh, you're right, I remember now. It takes a reference to the passed
value in a situation where normally one would expect a copy. In
practice, I only put references in pnotes anyway, so this has never
bothered me.
I'd be okay with changing this in future releases as long as it doesn't
change in the 1.x series.
- Perrin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 07 June 2006 22:07, Perrin Harkins wrote:
> Me too. I don't think this is a bug, since it behaves normally for a
> Perl hash. It's been documented now, and I think that should be the end
> of it.
No, it does not. $r->pnotes->{key}=value behaves like a Perl hash.
$r->pnotes(key, value) does not. But anyway if you all think it's okay the way
it is I'll simply not use the second version anymore.
Look at the implications of this bug. One starts a module with this code in
it:
$r->pnotes( lang=>'de' );
This will work and is okay. Later someone invents a language hash:
%lang=(deutsch=>'de');
...
$r->pnotes( lang=>$lang{CGI::param('language')} );
Even this still works because %lang is in fact read-only. But then in the next
release the code is changed to:
...
my $lang=$lang{CGI::param('language')};
$r->pnotes( lang=>$lang );
...
if( $lang eq 'de' ) {
$lang='de_DE';
} elsif( $lang eq 'us' ) {
$lang='en_US';
}
...
Now the code is faulty. After $lang='de_DE' also the pnote is 'de_DE' not just
'de' as expected.
And please note, this can happen years after the initial innocent looking
$r->pnotes(lang=>'de') had been written. Had it been $r->pnotes->{lang}='de'
in the first place the code would still be okay.
Torsten
Re: [MP2] possible pnotes bug?
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
On 7-Jun-06, at 1:07 PM, Perrin Harkins wrote:
> On Tue, 2006-06-06 at 08:49 -0400, Geoffrey Young wrote:
>> Philip M. Gollucci wrote:
>>> I also agree with whichever faction says this can't happen in 2.0.x.
>>
>> that's (at least) me. I believe philippe was in favor of fixing
>> it...
>
> Me too. I don't think this is a bug, since it behaves normally for a
> Perl hash. It's been documented now, and I think that should be
> the end
> of it.
I hope there is more than just me now that think this is worth fixing ?
As much as I can remeber, wenever a user was caught by this bug, it
was , 95% of
the time, because they expected that $r->pnotes behaved like a hash
even though it didn't
quite so.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2006-06-06 at 08:49 -0400, Geoffrey Young wrote:
> Philip M. Gollucci wrote:
> > I also agree with whichever faction says this can't happen in 2.0.x.
>
> that's (at least) me. I believe philippe was in favor of fixing it...
Me too. I don't think this is a bug, since it behaves normally for a
Perl hash. It's been documented now, and I think that should be the end
of it.
- Perrin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Philip M. Gollucci wrote:
> Torsten Foertsch wrote:
>
>> What is the common understanding on this point by now?
>> - retval = *hv_store(*pnotes, k, len, SvREFCNT_inc(val), 0);
>> + retval = *hv_store(*pnotes, k, len, newSVsv(val), 0);
>
> Pushes the cobwebs aside.....
> I agree that the change you propose will accomplish what you want, but
> at some point later, don't we need to free this new AV()?
>
> I also agree with whichever faction says this can't happen in 2.0.x.
that's (at least) me. I believe philippe was in favor of fixing it...
I'll accept proposing that modify the behavior in 2.2.x, provided we
document it very well. altering 1.x is probably out of the question,
I'd think.
>
> I also don't see the need to change behavior thats been around for 5+
> years. I realize its not necessarily the expected behavior. I vaguely
> recall you submitted a documentation patch which was committed.
and there's also a cpan module that makes things behave in the "new"
way, iirc, so people can get this behavior if they want it...
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Torsten Foertsch wrote:
> What is the common understanding on this point by now?
> - retval = *hv_store(*pnotes, k, len, SvREFCNT_inc(val), 0);
> + retval = *hv_store(*pnotes, k, len, newSVsv(val), 0);
Pushes the cobwebs aside.....
I agree that the change you propose will accomplish what you want, but
at some point later, don't we need to free this new AV()?
I also agree with whichever faction says this can't happen in 2.0.x.
I also don't see the need to change behavior thats been around for 5+
years. I realize its not necessarily the expected behavior. I vaguely
recall you submitted a documentation patch which was committed.
--
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F
"It takes a minute to have a crush on someone, an hour to like someone,
and a day to love someone, but it takes a lifetime to forget someone..."
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Torsten Foertsch <to...@gmx.net>.
Hi,
some time ago there was an argument about the "right" behavior of pnotes, see
http://www.gossamer-threads.com/lists/modperl/dev/87819.
The question was whether $r->pnotes(key=>value) should do exactly the same as
$r->pnotes->{key}=value or for some historical reason not.
The problem is that after:
my $foo = 123;
and storing $foo as a pnote:
$r->pnotes('foo' => $foo);
any subsequent changes on $foo like $foo=456 affect also the pnote and changes
to the pnote like $r->pnotes->{foo}++ affect $foo.
Otherwise, if the pnote is stored as:
$r->pnotes->{foo}=$foo;
subsequent changes to either $foo or $pnotes->{foo} don't affect the other
value.
Back then one fraction said the behavior is right as it is now because it was
so also in mp1 and because such a change is not to be done within a stable
release-cycle. The other saw it this way, for the user both ways of setting a
pnote look identical, hence they should behave identical.
What is the common understanding on this point by now?
I think a possible fix is as simple as this:
Index: src/modules/perl/modperl_util.c
===================================================================
--- src/modules/perl/modperl_util.c (revision 412021)
+++ src/modules/perl/modperl_util.c (working copy)
@@ -889,7 +889,7 @@
char *k = SvPV(key, len);
if (val) {
- retval = *hv_store(*pnotes, k, len, SvREFCNT_inc(val), 0);
+ retval = *hv_store(*pnotes, k, len, newSVsv(val), 0);
}
else if (hv_exists(*pnotes, k, len)) {
retval = *hv_fetch(*pnotes, k, len, FALSE);
Torsten
Re: [MP2] possible pnotes bug?
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Geoffrey Young wrote:
>>>>in order for $o to maintain it's internal state. is that right? if so, I
>>>>don't like that very much.
>>
>>It's not right. You are confusing scalars with references in that example.
>
> ook, my bad - I thought the proposed "solution" was to always dereference
> pnotes behind the scenes, making the additional storage a requirement.
>
> but, just in case I'm not the only one confused, I'd propose a path like this...
>
> o create some (many?) additional pnotes tests that exercise the different
> ways we think people will be using pnotes in almost all normal circumstances
> we can think of. digging through CPAN might be a good idea.
>
> o offer that any fix shouldn't break the tests
>
> o see what falls out
I'll get to it once I am done with the (r|c)->pnotes patch.
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>>in order for $o to maintain it's internal state. is that right? if so, I
>>>don't like that very much.
>
>
> It's not right. You are confusing scalars with references in that example.
ook, my bad - I thought the proposed "solution" was to always dereference
pnotes behind the scenes, making the additional storage a requirement.
but, just in case I'm not the only one confused, I'd propose a path like this...
o create some (many?) additional pnotes tests that exercise the different
ways we think people will be using pnotes in almost all normal circumstances
we can think of. digging through CPAN might be a good idea.
o offer that any fix shouldn't break the tests
o see what falls out
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Perrin Harkins wrote:
> On Wed, 2006-03-15 at 12:23 -0500, Geoffrey Young wrote:
>
>>I actually thing that would be somewhat common. and as I understand things,
>>the fix would require the middle step to be
>>
>> -- next handler
>> my $o = $r->pnotes('foo');
>> $o->set(bar => 1); # sets $o->{_bar} = 1
>> $r->pnotes(foo => $o);
>>
>>in order for $o to maintain it's internal state. is that right? if so, I
>>don't like that very much.
It's not right. You are confusing scalars with references in that example.
> I agree, cloning is not the answer.
Definitely not.
> What you want really want here is
> for it to behave like a normal perl variable assignment, i.e. if you
> assign a reference, it stays a reference,
And the refcount goes up by 1.
> and if you assign a value,
> it's just a value, not a double-secret-probation reference. I don't
> think it's a good idea to change this unless it can be done that way.
Exactly, the behaviour of
$r->pnotes(foo => $bar);
Should be equivalent in all respects to
$pnotes{foo} = $bar;
No magic, no trickery.
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Re: [MP2] possible pnotes bug?
Posted by Perrin Harkins <pe...@elem.com>.
On Wed, 2006-03-15 at 12:23 -0500, Geoffrey Young wrote:
> I actually thing that would be somewhat common. and as I understand things,
> the fix would require the middle step to be
>
> -- next handler
> my $o = $r->pnotes('foo');
> $o->set(bar => 1); # sets $o->{_bar} = 1
> $r->pnotes(foo => $o);
>
> in order for $o to maintain it's internal state. is that right? if so, I
> don't like that very much.
I agree, cloning is not the answer. What you want really want here is
for it to behave like a normal perl variable assignment, i.e. if you
assign a reference, it stays a reference, and if you assign a value,
it's just a value, not a double-secret-probation reference. I don't
think it's a good idea to change this unless it can be done that way.
- Perrin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> + my $foo = 123;
> + $r->pnotes('foo' => $foo);
> + $foo = 456;
> + $r->pnotes('foo') # <== now 456 (in 2.0.2)
> + $r->pnotes('foo') # <== left at 123 (in 2.0.3)
actually, I'm re-thinking my stance on this. a common use of pnotes is to
pass objects around. if I understand things correctly, the current
situation is this
-- some handler
my $o = Foo->new;
$r->pnotes(foo => $o);
-- next handler
my $o = $r->pnotes('foo');
$o->set(bar => 1); # sets $o->{_bar} = 1
-- another handler
my $o = $r->pnotes('foo');
my $bar = $o->bar; # 1
I actually thing that would be somewhat common. and as I understand things,
the fix would require the middle step to be
-- next handler
my $o = $r->pnotes('foo');
$o->set(bar => 1); # sets $o->{_bar} = 1
$r->pnotes(foo => $o);
in order for $o to maintain it's internal state. is that right? if so, I
don't like that very much. in fact, I'll bet that doug originally coded
pnotes to behave the way it currently does on purpose, since the original
force behind pnotes was to be able to pass objects around.
so, I think I'm leaning more towards "the current behavior is not only not
broken, it's intentional" camp.
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Tom Schindl <to...@bestsolution.at>.
Hi Geoff,
As already said I'd also like to see this fix in the next release but
I'd like to have a rc released to users which is announced at the
user-mailing list pointing to this "API"-Change and in the same time I'd
propose the following documentation patch.
Tom
Geoffrey Young wrote:
>>>So does anybody think this behaviour shouldn't be 'fixed' in 2.0 ?
>>>
>>
>>
>>Yes, I do not because I use this feature or think it should be changed
>>but it simply changes how mp2 behaves within a stable release-cycle but
>>that's only my opinion.
>
>
> I agree with you in principle. however, historically mod_perl has been a
> bit more flexible with its public interface based on the general community
> feeling that a "fixed in stone" API is less useful than one that actually
> works or is dwimmy from a developer standpoint. and in truth, this isn't an
> API change - you still call pnotes() the same way you always did, and it
> still behaves the same way under most normal circumstances.
>
> so I think we can get away with changing this behavior in 2.0. not that I'm
> entirely in favor of it, but I also don't have a problem letting the
> community majority decide what to do.
>
> but I will insist on a test that exercises the feature and its fix, so we
> have something to point to if someone ever complains :)
>
> --Geoff
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
>
--
B e s t S o l u t i o n . a t EDV Systemhaus GmbH
------------------------------------------------------------------------
tom schindl leiter softwareentwicklung/CSE mobile ++43 676 3232147
------------------------------------------------------------------------
eduard-bodem-gasse 8/3 A-6020 innsbruck fax ++43 512 935833
http://www.bestsolution.at phone ++43 512 935834
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>So does anybody think this behaviour shouldn't be 'fixed' in 2.0 ?
>>
>
>
> Yes, I do not because I use this feature or think it should be changed
> but it simply changes how mp2 behaves within a stable release-cycle but
> that's only my opinion.
I agree with you in principle. however, historically mod_perl has been a
bit more flexible with its public interface based on the general community
feeling that a "fixed in stone" API is less useful than one that actually
works or is dwimmy from a developer standpoint. and in truth, this isn't an
API change - you still call pnotes() the same way you always did, and it
still behaves the same way under most normal circumstances.
so I think we can get away with changing this behavior in 2.0. not that I'm
entirely in favor of it, but I also don't have a problem letting the
community majority decide what to do.
but I will insist on a test that exercises the feature and its fix, so we
have something to point to if someone ever complains :)
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Tom Schindl <to...@bestsolution.at>.
Philippe M. Chiasson wrote:
> Frank Wiles wrote:
>
>>On Mon, 13 Mar 2006 20:35:45 -0500
>>Geoffrey Young <ge...@modperlcookbook.org> wrote:
>>
>>
>>>I'm fine with fixing things in 2.0 if that's the majority consensus.
>
>
> I'd certainly put my vote in that direction.
>
>
>>>I'd have a really hard time doing anything that changes 1.0 behavior
>>>at this point, though.
>
>
> Oh, absolutely, 1.0 would stay as-is.
>
>
>>>the bugfix that was just committed is a good example of things I
>>>think we ought to be doing in 1.0 - something was clearly broken,
>>>caused things to blow up, so we fix it. but to alter some functinal
>>>nuance simply because it doesn't feel right seems far beyond what we
>>>can do to our 1.0, production userbase.
>
>
> Agreed, unless it's some obvious, non-debatable breakeage/bug
>
>
>> I agree, it makes sense to change it in 2.0 and leave it alone in 1.0
>> provided we make it big, bold, and as idiot proof as possible in the
>> docs. :)
>
>
> The current state of documentation for this 'feature' in 2.0 is certainly
> offputting for a mod_perl newbie, IMO
>
> "
> Note: sharing variables really means it. The variable is not copied.
> Only its reference count is incremented. If it is changed after being
> put in pnotes that change also affects the stored value."
>
>
> So does anybody think this behaviour shouldn't be 'fixed' in 2.0 ?
>
Yes, I do not because I use this feature or think it should be changed
but it simply changes how mp2 behaves within a stable release-cycle but
that's only my opinion.
> --------------------------------------------------------------------------------
> Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
> http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
--
B e s t S o l u t i o n . a t EDV Systemhaus GmbH
------------------------------------------------------------------------
tom schindl leiter softwareentwicklung/CSE mobile ++43 676 3232147
------------------------------------------------------------------------
eduard-bodem-gasse 8/3 A-6020 innsbruck fax ++43 512 935833
http://www.bestsolution.at phone ++43 512 935834
Re: [MP2] possible pnotes bug?
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Frank Wiles wrote:
> On Mon, 13 Mar 2006 20:35:45 -0500
> Geoffrey Young <ge...@modperlcookbook.org> wrote:
>
>>I'm fine with fixing things in 2.0 if that's the majority consensus.
I'd certainly put my vote in that direction.
>>I'd have a really hard time doing anything that changes 1.0 behavior
>>at this point, though.
Oh, absolutely, 1.0 would stay as-is.
>>the bugfix that was just committed is a good example of things I
>>think we ought to be doing in 1.0 - something was clearly broken,
>>caused things to blow up, so we fix it. but to alter some functinal
>>nuance simply because it doesn't feel right seems far beyond what we
>>can do to our 1.0, production userbase.
Agreed, unless it's some obvious, non-debatable breakeage/bug
> I agree, it makes sense to change it in 2.0 and leave it alone in 1.0
> provided we make it big, bold, and as idiot proof as possible in the
> docs. :)
The current state of documentation for this 'feature' in 2.0 is certainly
offputting for a mod_perl newbie, IMO
"
Note: sharing variables really means it. The variable is not copied.
Only its reference count is incremented. If it is changed after being
put in pnotes that change also affects the stored value."
So does anybody think this behaviour shouldn't be 'fixed' in 2.0 ?
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Re: [MP2] possible pnotes bug?
Posted by Frank Wiles <fr...@wiles.org>.
On Mon, 13 Mar 2006 20:35:45 -0500
Geoffrey Young <ge...@modperlcookbook.org> wrote:
> I'm fine with fixing things in 2.0 if that's the majority consensus.
> I'd have a really hard time doing anything that changes 1.0 behavior
> at this point, though.
>
> the bugfix that was just committed is a good example of things I
> think we ought to be doing in 1.0 - something was clearly broken,
> caused things to blow up, so we fix it. but to alter some functinal
> nuance simply because it doesn't feel right seems far beyond what we
> can do to our 1.0, production userbase.
I agree, it makes sense to change it in 2.0 and leave it alone in 1.0
provided we make it big, bold, and as idiot proof as possible in the
docs. :)
---------------------------------
Frank Wiles <fr...@wiles.org>
http://www.wiles.org
---------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Frank Wiles wrote:
> On Mon, 13 Mar 2006 14:55:32 -0800
> "Philippe M. Chiasson" <go...@ectoplasm.org> wrote:
>
>
>>Reviving a somewhat old thread here, so for context, here it is,
>>archived: http://www.gossamer-threads.com/lists/modperl/modperl/86483
>>
>>Basically, I think documenting this as a feature was not such a good
>>idea. Who can expect that this is correct/expected behaviour
>>
>>my $foo = 123;
>>$r->pnotes('foo' => $foo);
>>$foo = 456;
>>$r->pnotes('foo') # <== now 456
>>
>>I understand _why_ this hapenning, but I think that if it's not a
>>bug, it's certainly a very strange behaviour, compared to, say $note
>>{foo} = $foo; I would think that the casual user would be bitten by
>>something like this, even though it's documented.
>>
>>Is there any good reason _not_ to make this pnotes code behave just
>>like a hash, and store a copy of the scalar ?
>
>
> I didn't know about that "feature", so I would have be completely
> lost if I had run into personally. I agree it should be changed and
> behave as you would expect it to.
>
> The only downside I can think of is that it will break anyone who
> is taking advantage of it.
yeah, and that's the problem.
I'm fine with fixing things in 2.0 if that's the majority consensus. I'd
have a really hard time doing anything that changes 1.0 behavior at this
point, though.
the bugfix that was just committed is a good example of things I think we
ought to be doing in 1.0 - something was clearly broken, caused things to
blow up, so we fix it. but to alter some functinal nuance simply because it
doesn't feel right seems far beyond what we can do to our 1.0, production
userbase.
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [MP2] possible pnotes bug?
Posted by Frank Wiles <fr...@wiles.org>.
On Mon, 13 Mar 2006 14:55:32 -0800
"Philippe M. Chiasson" <go...@ectoplasm.org> wrote:
> Reviving a somewhat old thread here, so for context, here it is,
> archived: http://www.gossamer-threads.com/lists/modperl/modperl/86483
>
> Basically, I think documenting this as a feature was not such a good
> idea. Who can expect that this is correct/expected behaviour
>
> my $foo = 123;
> $r->pnotes('foo' => $foo);
> $foo = 456;
> $r->pnotes('foo') # <== now 456
>
> I understand _why_ this hapenning, but I think that if it's not a
> bug, it's certainly a very strange behaviour, compared to, say $note
> {foo} = $foo; I would think that the casual user would be bitten by
> something like this, even though it's documented.
>
> Is there any good reason _not_ to make this pnotes code behave just
> like a hash, and store a copy of the scalar ?
I didn't know about that "feature", so I would have be completely
lost if I had run into personally. I agree it should be changed and
behave as you would expect it to.
The only downside I can think of is that it will break anyone who
is taking advantage of it.
---------------------------------
Frank Wiles <fr...@wiles.org>
http://www.wiles.org
---------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org