使用 XS 返回 Perl 哈希(错误:'void'不在类型映射中)



我正在尝试添加对Augas(Config::Augas(的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_spanu2019:
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: u2018RETVALu2019 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.

我做错了什么?

尝试一下:

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=>SV*(,我对返回的SV*使用SV_2moral。由于堆栈没有被引用计数,因此必须标记SV*,以便在下一个"合适"的机会进行销毁。

您的函数的类型是void,而它应该是SV *。参见perlxs的本节。

相关内容

  • 没有找到相关文章

最新更新