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
In reply to how to get stash name of SV? by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |