diff options
author | Nicholas Clark <nick@ccl4.org> | 2006-04-28 16:34:14 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2006-04-28 16:34:14 +0000 |
commit | 923318002ce505ec75344304b64394034456b5b8 (patch) | |
tree | 833a99dd20cac6fddcd316164035d1d87b67b8f4 /pp.c | |
parent | 2bfc3eabdb0f2b7bb8953cf725f1f43ee9e85d30 (diff) | |
download | perl-923318002ce505ec75344304b64394034456b5b8.tar.gz |
Fix bug 34297 (length of overloaded UTF-8 strings)
p4raw-id: //depot/perl@28006
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -2950,7 +2950,22 @@ PP(pp_length) dVAR; dSP; dTARGET; SV * const sv = TOPs; - if (DO_UTF8(sv)) + if (SvAMAGIC(sv)) { + /* For an overloaded scalar, we can't know in advance if it's going to + be UTF-8 or not. Also, we can't call sv_len_utf8 as it likes to + cache the length. Maybe that should be a documented feature of it. + */ + STRLEN len; + const char *const p = SvPV_const(sv, len); + + if (DO_UTF8(sv)) { + SETi(Perl_utf8_length(aTHX_ p, p + len)); + } + else + SETi(len); + + } + else if (DO_UTF8(sv)) SETi(sv_len_utf8(sv)); else SETi(sv_len(sv)); |