1212package B::C ;
1313use strict;
1414
15- our $VERSION = ' 1.54_12 ' ;
15+ our $VERSION = ' 1.54_13 ' ;
1616our (%debug , $check , %Config );
1717BEGIN {
1818 require B::C::Config;
@@ -1284,6 +1284,16 @@ sub nvx ($) {
12841284 return $sval ;
12851285}
12861286
1287+ sub mg_RC_off {
1288+ my ($mg , $sym , $type ) = @_ ;
1289+ warn " MG->FLAGS " ,$mg -> FLAGS," turn off MGf_REFCOUNTED\n " if $debug {mg };
1290+ if (!ref $sym ) {
1291+ $init -> add(sprintf (" my_mg_RC_off(aTHX_ (SV*)$sym , %s );" , cchar($type )));
1292+ } else {
1293+ $init -> add(sprintf (" my_mg_RC_off(aTHX_ (SV*)s\\ _%x , %s );" , $$sym , cchar($type )));
1294+ }
1295+ }
1296+
12871297# for bytes and utf8 only
12881298# TODO: Carp::Heavy, Exporter::Heavy
12891299# special case: warnings::register via -fno-warnings
@@ -3660,7 +3670,7 @@ sub B::PVMG::save_magic {
36603670 $len = $mg -> LENGTH;
36613671 $magic .= $type ;
36623672 if ( $debug {mg } ) {
3663- warn sprintf ( " %s %s magic\n " , $fullname , cchar($type ) );
3673+ warn sprintf ( " %s %s magic 0x %x \n " , $fullname , cchar($type ), $mg -> FLAGS );
36643674 # eval {
36653675 # warn sprintf( "magic %s (0x%x), obj %s (0x%x), type %s, ptr %s\n",
36663676 # B::class($sv), $$sv, B::class($obj), $$obj, cchar($type),
@@ -3691,6 +3701,9 @@ sub B::PVMG::save_magic {
36913701 warn " MG->PTR is an SV*\n " if $debug {mg };
36923702 $init -> add(sprintf (" sv_magic((SV*)s\\ _%x , (SV*)s\\ _%x , %s , (char *)%s , %d );" ,
36933703 $$sv , $$obj , cchar($type ), $ptrsv , $len ));
3704+ if (!($mg -> FLAGS & 2)) {
3705+ mg_RC_off($mg , $sv , $type );
3706+ }
36943707 }
36953708 # coverage $Template::Stash::PRIVATE
36963709 elsif ( $type eq ' r' ) { # qr magic, for 5.6 done in C.xs. test 20
@@ -3768,7 +3781,10 @@ CODE2
37683781 else {
37693782 $init -> add(sprintf (
37703783 " sv_magic((SV*)s\\ _%x , (SV*)s\\ _%x , %s , %s , %d );" ,
3771- $$sv , $$obj , cchar($type ), cstring($ptr ), $len ))
3784+ $$sv , $$obj , cchar($type ), cstring($ptr ), $len ));
3785+ if (!($mg -> FLAGS & 2)) {
3786+ mg_RC_off($mg , $sv , $type );
3787+ }
37723788 }
37733789 }
37743790 $init -> add(sprintf (" SvREADONLY_on((SV*)s\\ _%x );" , $$sv ))
@@ -5307,9 +5323,13 @@ sub B::GV::save {
53075323 if ($PERL514 and $cvsym and $cvsym !~ / (get_cv|NULL|lexwarn)/ and $gv -> MAGICAL) {
53085324 my @magic = $gv -> MAGIC;
53095325 foreach my $mg (@magic ) {
5310- $init -> add( " sv_magic((SV*)$sym , (SV*)$cvsym , '<', 0, 0);" ,
5311- " CvCVGV_RC_off($cvsym );"
5312- ) if $mg -> TYPE eq ' <' ;
5326+ if ($mg -> TYPE eq ' <' ) {
5327+ $init -> add( " sv_magic((SV*)$sym , (SV*)$cvsym , '<', 0, 0);" ,
5328+ " CvCVGV_RC_off($cvsym );" );
5329+ if (!($mg -> FLAGS & 2)) {
5330+ mg_RC_off($mg , $sym , ' <' ); # 390
5331+ }
5332+ }
53135333 }
53145334 }
53155335 }
@@ -6440,6 +6460,15 @@ sub output_declarations {
64406460#define UNUSED 0
64416461#define sym_0 0
64426462
6463+ static void
6464+ my_mg_RC_off(pTHX_ SV* sv, int type) {
6465+ MAGIC *mg;
6466+ for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
6467+ if (mg->mg_type == type && (mg->mg_flags | MGf_REFCOUNTED))
6468+ mg->mg_flags &= ~MGf_REFCOUNTED;
6469+ }
6470+ }
6471+
64436472EOT
64446473 if ($PERL510 and IS_MSVC) {
64456474 # initializing char * differs in levels of indirection from int
@@ -6450,7 +6479,7 @@ EOT
64506479
64516480 # Need fresh re-hash of strtab. share_hek does not allow hash = 0
64526481 if ( $PERL510 ) {
6453- print <<'_EOT0' ;
6482+ print <<'_EOT0' ;
64546483PERL_STATIC_INLINE HEK *
64556484my_share_hek( pTHX_ const char *str, I32 len );
64566485#undef share_hek
0 commit comments