Edwin Pratomo <[EMAIL PROTECTED]> writes:
>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.
It will do. You can also use the un(der) documented ${Package} variable
(which comes from the PACKAGE = part of module line)
rather than hard coding "Foo::Baz";
>What is the recommended way to overcome this problem?
Personally I don't trust the "canned" typemaps to get objects right.
I always write my own typemap, and usually having it call a function:
TkWindow * T_TKWINDOW
INPUT
T_TKWINDOW
$var = SVtoWindow($arg)
OUTPUT
T_TKWINDOW
sv_setsv($arg,WindowToSV($var,\"${Package}\"));
>
>rgds,
>Edwin.
--
Nick Ing-Simmons