On Aug 23, 2004, at 2:14 AM, Bjoern Hoehrmann wrote:

Should my XS code check whether an object 'can' a specific method before calling call_method() for a reason other than performance? It seems that such a check is not commonly performed so it is probably not very important. What's the best way to check whether an object 'can' a specific method?

in gtk2-perl we have several "interesting" marshaling situations in which we search for methods that are optional for perl-implemented objects to implement. if the method can be found, we invoke it, otherwise, we chain up to the parent's C vfunc. to do this, we try to get the actual CV* from the stash, and call_sv() it if it exists.


we do this because in some instances the method we're looking for doesn't actually behave like a method.

for example: gperl_signal_class_closure_marshal(), gperl_type_get_property() and gperl_type_set_property() in http://cvs.sourceforge.net/viewcvs.py/gtk2-perl/gtk2-perl-xs/Glib/ GType.xs?rev=1.64&view=auto

in other words, we have to do some magic to make non-perlish semantics seem more perlish.

in general, however, you just let perl's own mechanisms do the work. if you have to clean up anything when a method doesn't exist, then you can either trap with eval or make sure that stuff on the stack is mortal and will trigger the proper cleanup.

--
Holy crap, dude, we have kids!
        -- Elysse, six days after giving birth to twins



Reply via email to