develooper Front page | perl.perl5.porters | Postings from February 2000

Re: [5.5.660] class methods and xsubpp

Thread Previous | Thread Next
From:
Hugo
Date:
February 24, 2000 18:03
Subject:
Re: [5.5.660] class methods and xsubpp
Message ID:
200002250208.CAA08581@crypt.compulink.co.uk
In <E12O7i3-0000AB-00@mserv1c.u-net.net>, Nick Ing-Simmons writes:
:Hugo <hv@crypt0.demon.co.uk> writes:
:>This XS code:
:>
:>int
:>MyClass::method()
:>
:>.. checks the THIS argument like this:
:>
:>        if (sv_derived_from(ST(0), "MyClassPtr")) {
:>            IV tmp = SvIV((SV*)SvRV(ST(0)));
:>            THIS = INT2PTR(MyClass *,tmp);
:>        }
:>        else
:>            croak("THIS is not of type MyClassPtr");
:>
:>.. which is a problem, since the method will be invoked by perl on a
:>MyClass object, not on a MyClassPtr object. I'm not sure what the right
:>solution is for this - has anyone successfully used this type of
:>invocation? (I note that it does not appear to be documented in perlxs.)
:
:The whole MyClass * :-> MyClassPtr stuff is a mess.
:Just write your own typemap ;-)
:
:Or maybe just fake things so it _is_:
:
:package MyClass;
:@ISA = qw(MyClassPtr);

I'm happy to duck the issue by using the function style: I can't actually
see anything that the method style buys me beyond saving the declaration
of THIS, even before you take into account its apparent brokenness. I tried
to use it only because it felt vaguely like it might be better style, but
didn't realise at the time that it wasn't documented. Maybe this is why.

Hugo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About