从 Perl 调用 C 函数时,例如使用Inline::C
:
use feature qw(say);
use strict;
use warnings;
use Inline C => './test.c';
say "Calling test()..";
test();
say "Finished.";
哪里test.c
是:
void test()
{
SV *sv_variable = newSVpv("test", 0);
// do something..
//SvREFCNT_dec(sv_variable); // free variable
printf( "Returning from test()..\n");
return;
}
无论我是否打电话,该脚本似乎都可以正常工作SvREFCNT_dec(sv_variable)
。根据perlguts
:
要释放您创建的 SV,请调用 SvREFCNT_dec(SV*)。通常不需要这个调用