Hi all,

I'm working on an interface to a C lib.
There are two structs, Bar and Baz. BarPtr and BazPtr are pointers to
them, respectively. 
Both are treated as O_OBJECT, because they have special cleanup
functions which will be conveniently placed in the DESTROY.
here is the snippet to describe my problem.

MODULE = Foo::Bar PACKAGE = Foo::Bar

BarPtr
new(CLASS, file)
   blah blah blah...

BazPtr
result_of_comp(self, obj)
   BarPtr self
   BazPtr obj
   CODE:
   RETVAL = get_the_result(self, obj);
   OUTPUT:
   RETVAL

MODULE = Foo::Bar PACKAGE = Foo::Baz

BazPtr
new(CLASS, file)
   blah blah blah...


The expected usage is:
$a = new BarPtr($file_a);
$b = new BazPtr($file_b);
$res = $a->result_of_comp($b);

where $res is a BazPtr object.

But the .xs won't compile because result_of_comp() will follow the
typemap rule by doing this:
 sv_setref_pv( ST(0), CLASS, (void*)RETVAL);
prior to returning the result value, and CLASS is not defined anywhere.

My solution is to add:
    PREINIT:
    char *  CLASS = "Foo::Baz";

But I'm not sure whether this is the best practice. 
What is the recommended way to overcome this problem?

rgds,
Edwin.

Reply via email to