How do I build a Perl hash in C, using SWIG?

I'm trying to create a Perl hash from within a C library. Here's what I've got so far: static void add_string_to_perl_hash ( HV *hv, char * key, char *value ) { SV *obj = sv_2mortal(newSVpv(value, 0)); hv_store(hv, (const char *)key, strlen (key), obj, 0); SvREFCNT_inc(obj); } SV * do_get_test_hash () { static char *foo ="foo"; static char *bar ="bar"; HV *hv; hv = newHV(); add_string_to_perl_hash ( hv, "foo", foo); add_string_to_perl_hash ( hv, "bar", bar); return sv_2mortal(newRV_noinc((SV*)hv)); } Trying it out: I don't get anything that makes any sense to me: use testlib; use Data::Dumper; print Dumper (testlib::do_get_test_hash()); $VAR1 = bless( do{\(my $o = 5359872)}, '_p_SV' ); Ideas?

以上就是How do I build a Perl hash in C, using SWIG?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏