dVAR; dSP; dTARGET;
SV * const sv = TOPs;
- if (SvGAMAGIC(sv)) {
- /* For an overloaded or magic 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
- = sv_2pv_flags(sv, &len,
- SV_UNDEF_RETURNS_NULL|SV_CONST_RETURN|SV_GMAGIC);
-
- if (!p) {
- if (!SvPADTMP(TARG)) {
- sv_setsv(TARG, &PL_sv_undef);
- SETTARG;
- }
- SETs(&PL_sv_undef);
- }
- else if (DO_UTF8(sv)) {
- SETi(utf8_length((U8*)p, (U8*)p + len));
- }
- else
- SETi(len);
- } else if (SvOK(sv)) {
- /* Neither magic nor overloaded. */
+ SvGETMAGIC(sv);
+ if (SvOK(sv)) {
if (!IN_BYTES)
- SETi(sv_len_utf8(sv));
+ SETi(sv_len_utf8_nomg(sv));
else
- SETi(sv_len(sv));
+ {
+ STRLEN len;
+ (void)SvPV_nomg_const(sv,len);
+ SETi(len);
+ }
} else {
if (!SvPADTMP(TARG)) {
sv_setsv_nomg(TARG, &PL_sv_undef);
@INC = '../lib';
}
-plan (tests => 39);
+plan (tests => 41);
print "not " unless length("") == 0;
print "ok 1\n";
my $uo = bless [], 'U';
-is(length($uo), undef, "Length of overloaded reference");
+{
+ my $w;
+ local $SIG{__WARN__} = sub { $w = shift };
+ is(length($uo), 0, "Length of overloaded reference");
+ like $w, qr/uninitialized/, 'uninit warning for stringifying as undef';
+}
my $ul = 3;
is(($ul = length(undef)), undef,
is($ul, undef, "Assigned length of tied undef with result in TARG");
$ul = 3;
-is(($ul = length($uo)), undef,
+{
+ my $w;
+ local $SIG{__WARN__} = sub { $w = shift };
+ is(($ul = length($uo)), 0,
"Returned length of overloaded undef with result in TARG");
-is($ul, undef, "Assigned length of overloaded undef with result in TARG");
-
-# ok(!defined $uo); Turns you can't test this. FIXME for pp_defined?
+ like $w, qr/uninitialized/, 'uninit warning for stringifying as undef';
+}
+is($ul, 0, "Assigned length of overloaded undef with result in TARG");
{
my $y = "\x{100}BC";