Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Not able to pass the hash reference to callback from xsubpp

by ikegami (Pope)
on Aug 13, 2013 at 13:36 UTC ( #1049271=note: print w/replies, xml ) Need Help??


in reply to Not able to pass the hash reference to callback from xsubpp

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 */

Replies are listed 'Best First'.
Re^2: Not able to pass the hash reference to callback from xsubpp
by sriniiyer (Initiate) on Aug 13, 2013 at 15:56 UTC

    Thank you ikegami!

    That worked perfectly.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049271]
help
Chatterbox?
[stevieb]: perldigious You should start by writing some unit tests. That'll ensure current functionality doesn't break with changes.
[choroba]: unit tests++
[choroba]: The only problem you can't solve by adding more tests is the problem of having too many tests.
[stevieb]: choroba Been there, done that :) Better too many than not enough though!
[stevieb]: I very often write a base set of unit tests before writing any code. It helps dictate the API, and ensures my earliest of ideas stay on track.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-07-21 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (335 votes). Check out past polls.