develooper Front page | perl.perl5.porters | Postings from April 2008

Re: [perl #51370] Clearing magic (was: [#perl 51370] length($@)>0for empty $@ if utf8 is in use)

Thread Previous | Thread Next
From:
Bram
Date:
April 30, 2008 04:37
Subject:
Re: [perl #51370] Clearing magic (was: [#perl 51370] length($@)>0for empty $@ if utf8 is in use)
Message ID:
20080430133640.qj6vpagjy8kko84k@horde.wizbit.be
>>  And: if it has to change everywhere then what would the best approach
>>  be?
>>  Placing it in a separate function? (If so, in what file, what
>>  name, ...)

My current plan:

Adding Perl_sv_setpvn_clearmg in sv.c which basically contains:
   sv_setpvn(sv,ptr,len);
   if (SvMAGICAL(sv)) {
     mg_free(sv);
     mg_clear(sv);
   }
   SvPOK_only(sv);


Defining sv_setpvn_clearmg in embed.h
#define sv_setpvn_clearmg            Perl_sv_setpvn_clearmg

Changing: sv_setpvn(ERRSV,"",0) into sv_setpvn_clearmg(ERRSV,"",0);

Testing-A:

eval { 1 };
eval { die "\x{a10d};"; }
$_ = length $@;
eval { 1 };
print "ok" if (not $@ and not length $@);


Testing-B:

use Devel::Peek;
eval { 1 };
{ no warnings; $_ = $@ + 0 }
my $eval_1 = _get_output_of_Dump($@);

eval { die "\x{a10d};"; }
$_ = length $@;

eval { 1 };
my $eval_2 = _get_output_of_Dump($@);

print "ok" if $eval_1 eq $eval_2;


The $@ + 0 is needed because the Dump of the second eval always includes:
   IV = 0
   NV = 0

Which the first does not. (Or is there another way to get rid of it?)



Can someone comment on this approach?


Kind regards,

Bram



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About