diff options
author | Jerry D. Hedden <jdhedden@cpan.org> | 2007-10-18 10:49:40 -0400 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-10-19 07:47:45 +0000 |
commit | 800401ee2a8a5a67ef478227b68426cf701d0116 (patch) | |
tree | 25f017405848df7adfd1d53360318ef4466dc76a /sv.c | |
parent | c62eb2047c09034e319c2e6d5aaba369cad92b76 (diff) | |
download | perl-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.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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. |