Thanks. That's interesting, but not the case for my code which greatly simplified looks like this:
#! perl -slw
use strict;
package O;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'END_C', NAME => 'xso', CLEAN_AFTER_BUILD => 0;
typedef struct {
SV**sv;
} O;
void *mem( size_t size ) {
void *p;
Newx( p, size, char );
return p;
}
SV *new( char *package ) {
O *o = (O*)mem( sizeof( O ) );
SV *oh = newSVpv( (char*)&o, sizeof( O* ) );
SV *rv = newRV( oh );
o->sv = mem( sizeof( SV* ) );
sv_bless( rv, gv_stashpv( package, 0 ) );
SvREADONLY_on( oh );
SvREADONLY_on( rv );
printf( "N:rv:%p oh:%p o:%p\n", rv, oh, o );
return rv;
}
int set( SV *rv, SV *in ) {
O *o = *(O**)SvPV( SvRV( rv ), PL_na );
printf( "S:rv;%p o:%p\n", rv, o );
o->sv = newSVsv( in );
return 1;
}
SV *get( SV *rv ) {
O *o = *(O**)SvPV( SvRV( rv ), PL_na );
printf( "G:rv;%p o:%p\n", rv, o );
return newSVsv( o->sv );
}
void DESTROY( SV *rv ) {
printf( "DESTROY:%s\n", SvPV_nolen( rv ) );
}
void CLONE( SV *rv ) {
printf( "CLONE:%s\n", SvPV_nolen( rv ) );
}
END_C
package main;
use threads;
use Devel::Peek;
my $o = O->new();
print $o;
$o->set( "abcde" );
print $o->get();
print "\nthreaded\n";
async {
$o->set( "12345" );
}->join;
<>;
print $o->get();
__END__
C:\test>xso
N:rv:000000000002E218 oh:000000000002E128 o:00000000040FCA98
O=SCALAR(0x2e128)
S:rv;000000000002E248 o:00000000040FCA98
G:rv;000000000002E248 o:00000000040FCA98
abcde
threaded
CLONE:O
S:rv;000000000435D8F0 o:00000000040FCA98
DESTROY:O=SCALAR(0x435d908)
G:rv;000000000002E248 o:00000000040FCA98
semi-panic: attempt to dup freed string at C:\test\xso.pl line 72, <>
+line 1.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|