On Fri, Apr 08, 2011 at 02:18:19AM +0100, Patrick Dupre wrote:
> Hello,
> 
> I created my interface in c by using xs.
> 
> This work fine:
> 
> transition_HF*
> init___ ()
>   PREINIT:
>     transition_HF *trans ;
>   CODE:
>     trans = (transition_HF*) malloc (sizeof (transition_HF)) ;
>    RETVAL = trans ;
>   OUTPUT:
>     RETVAL
> 
> but if I make a push:
> like:
> 
> XPUSHs (sv_2mortal (newRV ((SV*) (trans)))) ;
> or:
> XPUSHs (sv_2mortal (newRV (trans))) ;
> 
> I always get an error like:
> 
> is not of type transition_HFPtr

This message comes from the typemap for T_PTROBJ:

T_PTROBJ
        if (sv_derived_from($arg, \"${ntype}\")) {
            IV tmp = SvIV((SV*)SvRV($arg));
            $var = INT2PTR($type,tmp);
        }
        else
            Perl_croak(aTHX_ \"%s: %s is not of type %s\",
                        ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
                        \"$var\", \"$ntype\")

This definition is found in .../ExtUtils/typemap in the directory tree where
perl is installed.

> when I try to access to this structure (in the first case, it works
> fine).
> 
> I set typemap like:
> TYPEMAP
> transition_HF *               T_PTROBJ
> 
> What am I doing wrong ?

>From perldoc perlxs:

  When dealing with C structures one should select either T_PTROBJ or T_PTRREF
  for the XS type.  Both types are designed to handle pointers to complex
  objects.  The T_PTRREF type will allow the Perl object to be unblessed while
  the T_PTROBJ type requires that the object be blessed.  By using T_PTROBJ
  one can achieve a form of type-checking because the XSUB will attempt to
  verify that the Perl object is of the expected type.

I suspect that you want to be using T_PTRREF rather than T_PTROBJ.  You can read
more about the different types in Typemap.xs:

  http://search.cpan.org/~rjbs/perl-5.12.3/ext/XS-Typemap/Typemap.xs

> Thank.

Welc.

I see no problem with asking beginner XS questions on a Perl beginners group.
but you might not find a large number or people who are able and willing to
help.  Fortunately, there is a mailing list for XS.  Details can be found at
http://lists.perl.org/list/perl-xs.html

Although the list is quite low in volume, you'll find people there who can
help further.

Good luck.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to