Hello Rob,

I am trying to investigate more, but, one problem seems to that that the
SvTYPE (ret) is 3, ie that it is a RV reference when it should be a
hash reference. Am I correct ?

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




--
---
==========================================================================
 Patrick DUPRÉ                      |   |
 Department of Chemistry            |   |    Phone: (44)-(0)-1904-434384
 The University of York             |   |    Fax:   (44)-(0)-1904-432516
 Heslington                         |   |
 York YO10 5DD  United Kingdom      |   |    email: [EMAIL PROTECTED]
==========================================================================
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/

Reply via email to