summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorJerry D. Hedden <jdhedden@cpan.org>2007-10-18 10:49:40 -0400
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-10-19 07:47:45 +0000
commit800401ee2a8a5a67ef478227b68426cf701d0116 (patch)
tree25f017405848df7adfd1d53360318ef4466dc76a /sv.c
parentc62eb2047c09034e319c2e6d5aaba369cad92b76 (diff)
downloadperl-800401ee2a8a5a67ef478227b68426cf701d0116.tar.gz
Fix overloading for 64-bit ints (revised)
From: "Jerry D. Hedden" <jdhedden@cpan.org> Message-ID: <1ff86f510710181149s1c096dd9qffa8fe42046e675b@mail.gmail.com> p4raw-id: //depot/perl@32141
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/sv.c b/sv.c
index df7a1b85a4..f418b058a9 100644
--- a/sv.c
+++ b/sv.c
@@ -2501,6 +2501,29 @@ Perl_sv_2nv(pTHX_ register SV *sv)
return SvNVX(sv);
}
+/*
+=for apidoc sv_2num
+
+Return an SV with the numeric value of the source SV, doing any necessary
+reference or overload conversion.
+
+=cut
+*/
+
+SV *
+Perl_sv_2num(pTHX_ register SV *sv)
+{
+ if (!SvROK(sv))
+ return sv;
+
+ if (SvAMAGIC(sv)) {
+ SV * const tmpsv = AMG_CALLun(sv,numer);
+ if (tmpsv && (!SvROK(tmpsv) || (SvRV(tmpsv) != SvRV(sv))))
+ return sv_2num(tmpsv);
+ }
+ return sv_2mortal(newSVuv(PTR2UV(SvRV(sv))));
+}
+
/* uiv_2buf(): private routine for use by sv_2pv_flags(): print an IV or
* UV as a string towards the end of buf, and return pointers to start and
* end of it.