From: Vincent Pit Date: Thu, 16 Feb 2012 22:51:02 +0000 (+0100) Subject: Move the sv length logic into a new vmg_sv_len() function X-Git-Tag: v0.48~6 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=b0d725bd65b94259e76048f864c972d9b70aac6b;p=perl%2Fmodules%2FVariable-Magic.git Move the sv length logic into a new vmg_sv_len() function --- diff --git a/Magic.xs b/Magic.xs index 0c99f2c..c8de430 100644 --- a/Magic.xs +++ b/Magic.xs @@ -1086,6 +1086,18 @@ STATIC int vmg_svt_set(pTHX_ SV *sv, MAGIC *mg) { return vmg_cb_call1(w->cb_set, w->opinfo, sv, mg->mg_obj); } +STATIC U32 vmg_sv_len(pTHX_ SV *sv) { +#define vmg_sv_len(S) vmg_sv_len(aTHX_ (S)) + STRLEN len; +#if VMG_HAS_PERL(5, 9, 3) + const U8 *s = VOID2(const U8 *, VOID2(const void *, SvPV_const(sv, len))); +#else + U8 *s = SvPV(sv, len); +#endif + + return DO_UTF8(sv) ? utf8_length(s, s + len) : len; +} + STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { const vmg_wizard *w = vmg_wizard_from_mg_nocheck(mg); unsigned int opinfo = w->opinfo; @@ -1103,16 +1115,7 @@ STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { PUSHs(sv_2mortal(newRV_inc(sv))); PUSHs(mg->mg_obj ? mg->mg_obj : &PL_sv_undef); if (t < SVt_PVAV) { - STRLEN l; -#if VMG_HAS_PERL(5, 9, 3) - const U8 *s = VOID2(const U8 *, VOID2(const void *, SvPV_const(sv, l))); -#else - U8 *s = SvPV(sv, l); -#endif - if (DO_UTF8(sv)) - len = utf8_length(s, s + l); - else - len = l; + len = vmg_sv_len(sv); mPUSHu(len); } else if (t == SVt_PVAV) { len = av_len((AV *) sv) + 1;