Patrick Dupre wrote: > > I am desesperated ! > > Assuming the following perl sub: > sub sub1 { > my %a ; > $a {a} = 1 ; > $a {b} = 2 ; > foreach (keys %a) { > print $_, " => ", $a {$_}, "\n" ; > } > return \%a ; > } > > Using XS, I am tring to get the hash using: > PREINIT: > int count ; > SV *ret ; > HV *ptr ; > SV ** hv ; > CODE: > dSP ; > ENTER ; > SAVETMPS ; > count = call_pv ("sub_::sub1", G_ARRAY | G_NOARGS | G_EVAL) ; > SPAGAIN ; > if (SvTRUE (ERRSV)) { > printf ("An error occured in the Perl preprocessor: %s\n", > SvPV_nolen (ERRSV)) ; > } > else { > printf ("Nb values returned: %d\n", count) ; > ret = POPs ; > ptr = (HV*) SvRV (ret) ; > } > FREETMPS ; > LEAVE ; > > But it is just wrong !!! > For example, how can I make a : > hv_fetch (ptr, "a", 1, FALSE) ; > > Ultimately, I need to pass the reference to the hash to another > perl sub by using (a reference on a hash is expected): > > XPUSHs () > but I did not guessed the right syntax > > I will appreciate a bit of help.
It would be nice to have been told the symptoms you are getting, as your code looks basically correct. All I can see that is wrong is that you need to add PUSHMARK(SP) before the call to the Perl subroutine to mark the end of any parameters you push onto the stack. Presumably you have had the XS subroutine working at some point? In which case you need to look at the last thing you added that stopped it working. In addition it would be nice to see proper variable names: using things like 'ptr' is bad practice, and it is even worse here where you have variables with multiple levels of both C and Perl indirection and it is easy to get confused. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/