我正在尝试为Augeas(Config :: Augeas)添加对Perl绑定的调用。我想这个新的调用返回一个Perl哈希。我写了这个:
void
aug_span(aug, path);
Config_Augeas* aug
char* path
PREINIT:
int ret ;
char *filename = NULL;
uint label_start, label_end, value_start, value_end, span_start, span_end;
HV *span_hash;
CODE:
ret = aug_span(aug, path, &filename, &label_start, &label_end, &value_start, &value_end, &span_start, &span_end);
span_hash = newHV();
hv_store(span_hash, "filename", 8, newSVpv(filename, strlen(filename)), 0);
hv_store(span_hash, "label_start", 11, newSViv(label_start), 0);
hv_store(span_hash, "label_end", 9, newSViv(label_end), 0);
hv_store(span_hash, "value_start", 11, newSViv(value_start), 0);
hv_store(span_hash, "value_end", 9, newSViv(value_end), 0);
hv_store(span_hash, "span_start", 10, newSViv(span_start), 0);
hv_store(span_hash, "span_end", 8, newSViv(span_end), 0);
RETVAL = newRV_noinc((SV *)span_hash);
OUTPUT:
RETVAL
但是当我建造它时,我得到了:
lib/Config/Augeas.xs -> lib/Config/Augeas.c
Use of uninitialized value within %ExtUtils::ParseXS::type_kind in hash element at /usr/share/perl/5.10/ExtUtils/ParseXS.pm line 785, <GEN7> line 170.
Error: 'void' not in typemap in Augeas.xs, line 167
cc -I/usr/lib/perl/5.10/CORE -DXS_VERSION="0.701" -DVERSION="0.701" -fPIC -Wall -Wformat -Werror=format-security -c -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -o lib/Config/Augeas.o lib/Config/Augeas.c
lib/Config/Augeas.xs: In function \u2018XS_Config__AugeasPtr_span\u2019:
lib/Config/Augeas.xs:158: warning: value computed is not used
lib/Config/Augeas.xs:159: warning: value computed is not used
lib/Config/Augeas.xs:160: warning: value computed is not used
lib/Config/Augeas.xs:161: warning: value computed is not used
lib/Config/Augeas.xs:162: warning: value computed is not used
lib/Config/Augeas.xs:163: warning: value computed is not used
lib/Config/Augeas.xs:164: warning: value computed is not used
lib/Config/Augeas.xs:165: error: \u2018RETVAL\u2019 undeclared (first use in this function)
lib/Config/Augeas.xs:165: error: (Each undeclared identifier is reported only once
lib/Config/Augeas.xs:165: error: for each function it appears in.)
error building lib/Config/Augeas.o from 'lib/Config/Augeas.c' at /usr/share/perl/5.10/ExtUtils/CBuilder/Base.pm line 110.
我做错了什么?
答案 0 :(得分:3)
您的功能属于void
类型,应为SV *
。请参阅perlxs
的{{3}}。
答案 1 :(得分:3)
试一试:
SV *
aug_span(aug, path);
Config_Augeas* aug
char* path
PREINIT:
int ret ;
char *filename = NULL;
uint label_start, label_end, value_start, value_end, span_start, span_end;
HV *span_hash;
CODE:
ret = aug_span(aug, path, &filename, &label_start, &label_end, &value_start, &value_end, &span_start, &span_end);
span_hash = newHV();
hv_store(span_hash, "filename", 8, newSVpv(filename, strlen(filename)), 0);
hv_store(span_hash, "label_start", 11, newSViv(label_start), 0);
hv_store(span_hash, "label_end", 9, newSViv(label_end), 0);
hv_store(span_hash, "value_start", 11, newSViv(value_start), 0);
hv_store(span_hash, "value_end", 9, newSViv(value_end), 0);
hv_store(span_hash, "span_start", 10, newSViv(span_start), 0);
hv_store(span_hash, "span_end", 8, newSViv(span_end), 0);
RETVAL = sv_2mortal((SV*)newRV_noinc((SV *)span_hash));
OUTPUT:
RETVAL
更改是:返回类型(void =&gt; SV *),我在返回的SV *上使用sv_2mortal。由于堆栈不是引用计数,因此必须在下一个“合适”的机会标记SV *以进行销毁。