Change 34055 by [EMAIL PROTECTED] on 2008/06/15 15:20:41
Subject: [perl #55786] [PATCH blead] Re: Overload Segfaulting
From: Rick Delaney (via RT) <[EMAIL PROTECTED]>
Date: Sat, 14 Jun 2008 11:51:01 -0700
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
... //depot/perl/lib/overload.pm#56 edit
... //depot/perl/lib/overload.t#36 edit
... //depot/perl/pp.h#82 edit
Differences ...
==== //depot/perl/lib/overload.pm#56 (text) ====
Index: perl/lib/overload.pm
--- perl/lib/overload.pm#55~31076~ 2007-04-25 08:19:21.000000000 -0700
+++ perl/lib/overload.pm 2008-06-15 08:20:41.000000000 -0700
@@ -588,7 +588,8 @@
If the copy constructor is required during the execution of some mutator,
but a method for C<'='> was not specified, it can be autogenerated as a
-string copy if the object is a plain scalar.
+string copy if the object is a plain scalar or a simple assignment if it
+is not.
=over 5
@@ -675,7 +676,8 @@
=item I<Copy operator>
can be expressed in terms of an assignment to the dereferenced value, if this
-value is a scalar and not a reference.
+value is a scalar and not a reference, or simply a reference assignment
+otherwise.
=back
==== //depot/perl/lib/overload.t#36 (text) ====
Index: perl/lib/overload.t
--- perl/lib/overload.t#35~32880~ 2008-01-06 12:33:48.000000000 -0800
+++ perl/lib/overload.t 2008-06-15 08:20:41.000000000 -0700
@@ -47,7 +47,7 @@
package main;
$| = 1;
-use Test::More tests => 556;
+use Test::More tests => 558;
$a = new Oscalar "087";
@@ -1427,4 +1427,20 @@
is($aref**1, $num_val, 'exponentiation of ref');
}
+{
+ package CopyConstructorFallback;
+ use overload
+ '++' => sub { "$_[0]"; $_[0] },
+ fallback => 1;
+ sub new { bless {} => shift }
+
+ package main;
+
+ my $o = CopyConstructorFallback->new;
+ my $x = $o++; # would segfault
+ my $y = ++$o;
+ is($x, $o, "copy constructor falls back to assignment (postinc)");
+ is($y, $o, "copy constructor falls back to assignment (preinc)");
+}
+
# EOF
==== //depot/perl/pp.h#82 (text) ====
Index: perl/pp.h
--- perl/pp.h#81~32834~ 2008-01-04 12:27:42.000000000 -0800
+++ perl/pp.h 2008-06-15 08:20:41.000000000 -0700
@@ -487,9 +487,9 @@
/* SV* ref causes confusion with the member variable
changed SV* ref to SV* tmpRef */
-#define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
- if (SvREFCNT(tmpRef)>1) { \
- SvRV_set(rv, AMG_CALLun(rv,copy)); \
+#define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); SV* rv_copy; \
+ if (SvREFCNT(tmpRef)>1 && (rv_copy = AMG_CALLun(rv,copy))) { \
+ SvRV_set(rv, rv_copy); \
SvREFCNT_dec(tmpRef); \
} } STMT_END
End of Patch.