summaryrefslogtreecommitdiff
path: root/gv.c
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>1998-07-25 17:28:16 -0400
committerGurusamy Sarathy <gsar@cpan.org>1998-08-01 19:52:19 +0000
commitee239bfe47dc5d504cf50bb8f48401031aa791d7 (patch)
treed639b7f5512d058ca4c8b24cbcd2f0fc5efab604 /gv.c
parent3654eb6c94c503df3bbf29cfeb2429609f7a0879 (diff)
downloadperl-ee239bfe47dc5d504cf50bb8f48401031aa791d7.tar.gz
fixes for overloading bugs and docs, tweaked some
Message-Id: <199807260128.VAA10543@monk.mps.ohio-state.edu> Subject: [PATCH 5.004_76] better overloading p4raw-id: //depot/maint-5.005/perl@1677
Diffstat (limited to 'gv.c')
-rw-r--r--gv.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/gv.c b/gv.c
index e8a2f9d82e..a01956fd25 100644
--- a/gv.c
+++ b/gv.c
@@ -1154,7 +1154,7 @@ amagic_call(SV *left, SV *right, int method, int flags)
CV **cvp=NULL, **ocvp=NULL;
AMT *amtp, *oamtp;
int fl=0, off, off1, lr=0, assign=AMGf_assign & flags, notfound=0;
- int postpr=0, inc_dec_ass=0, assignshift=assign?1:0;
+ int postpr = 0, force_cpy = 0, assignshift = assign ? 1 : 0;
HV* stash;
if (!(AMGf_noleft & flags) && SvAMAGIC(left)
&& (mg = mg_find((SV*)(stash=SvSTASH(SvRV(left))),'c'))
@@ -1171,16 +1171,19 @@ amagic_call(SV *left, SV *right, int method, int flags)
int logic;
/* look for substituted methods */
+ /* In all the covered cases we should be called with assign==0. */
switch (method) {
case inc_amg:
- if (((cv = cvp[off=add_ass_amg]) && (inc_dec_ass=1))
- || ((cv = cvp[off=add_amg]) && (postpr=1))) {
+ force_cpy = 1;
+ if ((cv = cvp[off=add_ass_amg])
+ || ((cv = cvp[off = add_amg]) && (force_cpy = 0, postpr = 1))) {
right = &PL_sv_yes; lr = -1; assign = 1;
}
break;
case dec_amg:
- if (((cv = cvp[off=subtr_ass_amg]) && (inc_dec_ass=1))
- || ((cv = cvp[off=subtr_amg]) && (postpr=1))) {
+ force_cpy = 1;
+ if ((cv = cvp[off = subtr_ass_amg])
+ || ((cv = cvp[off = subtr_amg]) && (force_cpy = 0, postpr=1))) {
right = &PL_sv_yes; lr = -1; assign = 1;
}
break;
@@ -1327,6 +1330,7 @@ amagic_call(SV *left, SV *right, int method, int flags)
}
return NULL;
}
+ force_cpy = force_cpy || assign;
}
}
if (!notfound) {
@@ -1343,14 +1347,33 @@ amagic_call(SV *left, SV *right, int method, int flags)
flags & AMGf_unary? " for argument" : "",
HvNAME(stash),
fl? ",\n\tassignment variant used": "") );
+ }
/* Since we use shallow copy during assignment, we need
* to dublicate the contents, probably calling user-supplied
* version of copy operator
*/
- if ((method + assignshift==off
- && (assign || method==inc_amg || method==dec_amg))
- || inc_dec_ass) RvDEEPCP(left);
- }
+ /* We need to copy in following cases:
+ * a) Assignment form was called.
+ * assignshift==1, assign==T, method + 1 == off
+ * b) Increment or decrement, called directly.
+ * assignshift==0, assign==0, method + 0 == off
+ * c) Increment or decrement, translated to assignment add/subtr.
+ * assignshift==0, assign==T,
+ * force_cpy == T
+ * d) Increment or decrement, translated to nomethod.
+ * assignshift==0, assign==0,
+ * force_cpy == T
+ * e) Assignment form translated to nomethod.
+ * assignshift==1, assign==T, method + 1 != off
+ * force_cpy == T
+ */
+ /* off is method, method+assignshift, or a result of opcode substitution.
+ * In the latter case assignshift==0, so only notfound case is important.
+ */
+ if (( (method + assignshift == off)
+ && (assign || (method == inc_amg) || (method == dec_amg)))
+ || force_cpy)
+ RvDEEPCP(left);
{
dSP;
BINOP myop;