On Tue, Sep 13, 2005 at 03:08:51PM +0800, Dongxu Ma wrote:
> In some case, a class will have a static object for special purpose. For 
> instance:
> static foo foo::bar
> I want to port this object to perl by wrapping it as a sub like this:
> foo * 
> foo::bar()
> CODE:
> RETVAL = &(foo::bar);
> OUTPUT:
> RETVAL
> 
> This will always cause a segfault while invoking the sub in perl script.
> Does anyone know the reason?

You can't return a C++ object on the perl stack; perl wouldn't know what
to do with it. How you get round this problems depends on what visibility
you want the object to have within perl.

If you just want to access the value of the object (eg if it just contains
an integer value), then return an SV with user magic attached; the magic
has a pointer to the static object, and the magic's get and set functions
copy the integer value between the SV and the object.

If you want to be able (at the perl level) to call methods on the object;
then you need to return a Perl object, whose methods are written in XS.

But anyway, this this is for discusiing the development of the perl
interpreter, not for XS programming questions.

-- 
Lady Nancy Astor: If you were my husband, I would flavour your coffee
with poison.
Churchill: Madam - if I were your husband, I would drink it.

Reply via email to