summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2013-10-16 21:09:00 -0600
committerKarl Williamson <public@khwilliamson.com>2013-11-26 21:03:40 -0700
commitd9fe7d23bdbf0c9aeef4f48ea4e0c277e6c504d8 (patch)
treec07bda32e9f7ee6c6da221908374559aac73786e /mg.c
parent2a99ff865b7e95ea4a62ce50e45f728a34bdcb1f (diff)
downloadperl-d9fe7d23bdbf0c9aeef4f48ea4e0c277e6c504d8.tar.gz
mg.c: Extract code into a function.
This is in preparation for the same code to be used in additional places. There should be no logic changes.
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/mg.c b/mg.c
index eec2997a5f..ff827d1c09 100644
--- a/mg.c
+++ b/mg.c
@@ -739,6 +739,36 @@ Perl_emulate_cop_io(pTHX_ const COP *const c, SV *const sv)
}
}
+STATIC void
+S_fixup_errno_string(pTHX_ SV* sv)
+{
+ /* Do what is necessary to fixup the non-empty string in 'sv' for return to
+ * Perl space. */
+
+ PERL_ARGS_ASSERT_FIXUP_ERRNO_STRING;
+
+ assert(SvOK(sv));
+ assert(strNE(SvPVX(sv), ""));
+
+ /* In some locales the error string may come back as UTF-8, in
+ * which case we should turn on that flag. This didn't use to
+ * happen, and to avoid any possible backward compatibility issues,
+ * we don't turn on the flag unless we have to. So the flag stays
+ * off for an entirely ASCII string. We assume that if the string
+ * looks like UTF-8, it really is UTF-8: "text in any other
+ * encoding that uses bytes with the high bit set is extremely
+ * unlikely to pass a UTF-8 validity test"
+ * (http://en.wikipedia.org/wiki/Charset_detection). There is a
+ * potential that we will get it wrong however, especially on short
+ * error message text. (If it turns out to be necessary, we could
+ * also keep track if the current LC_MESSAGES locale is UTF-8) */
+ if (! is_ascii_string((U8*) SvPVX_const(sv), SvCUR(sv))
+ && is_utf8_string((U8*) SvPVX_const(sv), SvCUR(sv)))
+ {
+ SvUTF8_on(sv);
+ }
+}
+
#ifdef VMS
#include <descrip.h>
#include <starlet.h>
@@ -860,24 +890,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
* 'sv' not being considered SvOK. The SvNOK_on() below will cause
* just the number part to be valid */
sv_setpv(sv, Strerror(errno));
-
- /* In some locales the error string may come back as UTF-8, in
- * which case we should turn on that flag. This didn't use to
- * happen, and to avoid any possible backward compatibility issues,
- * we don't turn on the flag unless we have to. So the flag stays
- * off for an entirely ASCII string. We assume that if the string
- * looks like UTF-8, it really is UTF-8: "text in any other
- * encoding that uses bytes with the high bit set is extremely
- * unlikely to pass a UTF-8 validity test"
- * (http://en.wikipedia.org/wiki/Charset_detection). There is a
- * potential that we will get it wrong however, especially on short
- * error message text. (If it turns out to be necessary, we could
- * also keep track if the current LC_MESSAGES locale is UTF-8) */
- if (SvOK(sv) /* It could be that Strerror returned invalid */
- && ! is_ascii_string((U8*) SvPVX_const(sv), SvCUR(sv))
- && is_utf8_string((U8*) SvPVX_const(sv), SvCUR(sv)))
- {
- SvUTF8_on(sv);
+ if (SvOK(sv)) {
+ fixup_errno_string(sv);
}
}
RESTORE_ERRNO;