summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorAndy Lester <andy@petdance.com>2006-04-23 16:12:39 -0500
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2006-04-24 07:27:33 +0000
commit675c862fe1d4abfd048dce5f1958cca54b16c501 (patch)
treef569d04f7ab102c470d0dc39c1df6677608e820d /sv.c
parentd6f07c0562911cf76e1e5f209b2eb29c706bd31d (diff)
downloadperl-675c862fe1d4abfd048dce5f1958cca54b16c501.tar.gz
Refactor S_glob_2inpuv
Message-ID: <20060424021239.GA5449@petdance.com> p4raw-id: //depot/perl@27942
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/sv.c b/sv.c
index 1c2e0afdbe..598b593f53 100644
--- a/sv.c
+++ b/sv.c
@@ -1718,7 +1718,7 @@ Perl_looks_like_number(pTHX_ SV *sv)
}
STATIC char *
-S_glob_2inpuv(pTHX_ GV *gv, STRLEN *len, bool want_number)
+S_glob_2inpuv_number(pTHX_ GV * const gv)
{
const U32 wasfake = SvFLAGS(gv) & SVf_FAKE;
SV *const buffer = sv_newmortal();
@@ -1729,21 +1729,30 @@ S_glob_2inpuv(pTHX_ GV *gv, STRLEN *len, bool want_number)
gv_efullname3(buffer, gv, "*");
SvFLAGS(gv) |= wasfake;
- if (want_number) {
- /* We know that all GVs stringify to something that is not-a-number,
- so no need to test that. */
- if (ckWARN(WARN_NUMERIC))
- not_a_number(buffer);
- /* We just want something true to return, so that S_sv_2iuv_common
- can tail call us and return true. */
- return (char *) 1;
- } else {
- assert(SvPOK(buffer));
- if (len) {
- *len = SvCUR(buffer);
- }
- return SvPVX(buffer);
- }
+ /* We know that all GVs stringify to something that is not-a-number,
+ so no need to test that. */
+ if (ckWARN(WARN_NUMERIC))
+ not_a_number(buffer);
+ /* We just want something true to return, so that S_sv_2iuv_common
+ can tail call us and return true. */
+ return (char *) 1;
+}
+
+STATIC char *
+S_glob_2inpuv(pTHX_ GV * const gv, STRLEN * const len)
+{
+ const U32 wasfake = SvFLAGS(gv) & SVf_FAKE;
+ SV *const buffer = sv_newmortal();
+
+ /* FAKE globs can get coerced, so need to turn this off temporarily if it
+ is on. */
+ SvFAKE_off(gv);
+ gv_efullname3(buffer, gv, "*");
+ SvFLAGS(gv) |= wasfake;
+
+ assert(SvPOK(buffer));
+ *len = SvCUR(buffer);
+ return SvPVX(buffer);
}
/* Actually, ISO C leaves conversion of UV to IV undefined, but
@@ -2113,9 +2122,8 @@ S_sv_2iuv_common(pTHX_ SV *sv) {
}
}
else {
- if (isGV_with_GP(sv)) {
- return (bool)PTR2IV(glob_2inpuv((GV *)sv, NULL, TRUE));
- }
+ if (isGV_with_GP(sv))
+ return (bool)PTR2IV(glob_2inpuv_number((GV *)sv));
if (!(SvFLAGS(sv) & SVs_PADTMP)) {
if (!PL_localizing && ckWARN(WARN_UNINITIALIZED))
@@ -2465,7 +2473,7 @@ Perl_sv_2nv(pTHX_ register SV *sv)
}
else {
if (isGV_with_GP(sv)) {
- glob_2inpuv((GV *)sv, NULL, TRUE);
+ glob_2inpuv_number((GV *)sv);
return 0.0;
}
@@ -2801,9 +2809,8 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags)
#endif
}
else {
- if (isGV_with_GP(sv)) {
- return glob_2inpuv((GV *)sv, lp, FALSE);
- }
+ if (isGV_with_GP(sv))
+ return glob_2inpuv((GV *)sv, lp);
if (!PL_localizing && !(SvFLAGS(sv) & SVs_PADTMP) && ckWARN(WARN_UNINITIALIZED))
report_uninit(sv);