Subs can only take scalars as arguments; you can't pass a hash. You can pass a reference to the hash, though.
Also, you hold two references to the hash for no reason.
You want
HV* data_hash = newHV(); SV* data_hash_ref = newRV_inc(data_hash); ... call_perl_sub("test_callback", data_hash_ref); ... SvREFCNT_dec(data_hash_ref); /* Or motalise and return to caller */ SvREFCNT_dec(data_hash);
Since we know data_hash_ref will outlive data_hash, we can avoid a ref count increment and decrement pair and simplify the above to the following:
HV* data_hash = newHV(); SV* data_hash_ref = newRV_noinc(data_hash); ... call_perl_sub("test_callback", data_hash_ref); ... SvREFCNT_dec(data_hash_ref); /* Or motalise and return to caller */
In reply to Re: Not able to pass the hash reference to callback from xsubpp
by ikegami
in thread Not able to pass the hash reference to callback from xsubpp
by sriniiyer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |