Hi Monks.
I have a bit of a problem with some XS code I'm writing.
I have a constructor "method" that creates a C struct and returns a reference to it:
VOX_PARSER *VOX_new_parser(void);
Here's the XSUB for it:
VOX_PARSER * new(CLASS) char * CLASS CODE: RETVAL = VOX_new_parser(); OUTPUT: RETVAL
And then in the typemap I map VOX_PARSER * to an O_OBJECT, and specify this for its OUTPUT filter:
# The Perl object is blessed into 'CLASS', which should be a # char* having the name of the package for the blessing. O_OBJECT sv_setref_pv($arg, (char *) CLASS, (void *) $var);
The problem is that another function calls that one to get the struct, uses it, and then returns it, and so does its XSUB. Consequently, the OUTPUT filter that should have only been applied once ends up getting applied twice, and a fatal error about the nonexistent "CLASS" variable (since the calling XSUB isn't a constructor, it doesn't take that argument like the new() XSUB does) gets raised when compiling. What would be the best way to take care of this? Should I stuff the filter code into the CODE portion of the new() XSUB? If so, what should I leave as the OUTPUT filter in the typemap?
There are at least a half a dozen other structs ("objects") that share this same problem: one function creates and returns, another calls, uses, returns.
Any advice would be appreciated. Thanks.
In reply to XSubs and returning blessed references? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |