xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
As described in perlapi, you can get stash of an SV by SvSTASH, but the following code always crashes!
Please help! Thanks in advance!use strict; use warnings; package dd; our $dd = "hello world"; main_pp(\$dd); use Inline Config => BUILD_NOISY => 1, CLEAN_AFTER_BUILD => 0; use Inline 'C' => Config => ccflagsex => '-g'; use Inline 'C' => <<'CODE'; int main_pp(SV* rx){ SV* x = get_sv("dd::dd", 0); /* below 2 statement both crash! */ // printf("stash is %s \n", HvNAME(SvSTASH((SV*)SvRV(rx)))); // printf("stash is %s \n", HvNAME(SvSTASH(x))); printf("pv is %s \n", (SvPVX(x))); HV* h = gv_stashpv("dd", 0); HE* hash_entry; SV* sv_key; SV* sv_val; int num_keys = hv_iterinit(h); for (int i = 0; i < num_keys; i++) { hash_entry = hv_iternext(h); sv_key = hv_iterkeysv(hash_entry); sv_val = hv_iterval(h, hash_entry); printf("%s => %s\n", SvPV(sv_key, PL_na), SvPV(sv_val, PL_na)); } return 0; } CODE
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how get stash name of SV?
by dave_the_m (Monsignor) on Oct 11, 2019 at 10:36 UTC | |
by xiaoyafeng (Deacon) on Oct 12, 2019 at 07:19 UTC | |
by dave_the_m (Monsignor) on Oct 12, 2019 at 11:04 UTC | |
by jcb (Parson) on Oct 14, 2019 at 00:28 UTC | |
|
Re: how get stash name of SV?
by jcb (Parson) on Oct 11, 2019 at 23:43 UTC | |
by soonix (Chancellor) on Oct 12, 2019 at 08:02 UTC | |
by xiaoyafeng (Deacon) on Oct 12, 2019 at 07:12 UTC | |
|
Re: how get stash name of SV?
by Anonymous Monk on Oct 11, 2019 at 12:00 UTC |