In trying to deal with references at the C level I can't seem to figure out the difference (in practice) between newRV_inc
and newRV_noinc
. To that end I have mocked up this little Inline::C
example.
#!/usr/bin/env perl
use strict;
use warnings;
use Devel::Peek 'SvREFCNT';
my $arrayref_inc = make_arrayref_inc();
print "inc: ", SvREFCNT($arrayref_inc), "\n";
my $arrayref_noinc = make_arrayref_noinc();
print "noinc: ", SvREFCNT($arrayref_noinc), "\n";
use Inline C => <<'END_C';
SV* make_arrayref_inc () {
AV * array = newAV();
SV * arrayref = newRV_inc((SV *)array);
return arrayref;
}
SV* make_arrayref_noinc () {
AV * array = newAV();
SV * arrayref = newRV_noinc((SV *)array);
return arrayref;
}
END_C
gives:
inc: 1
noinc: 1
Can anyone help me understand why this code behaves this way?