Re: [RFC] automatic property getters and setters



On Sat, 2004-06-12 at 15:23, muppet wrote:

While toying around with param_test.pl, I found a small glitch in
gperl_value_from_sv, though:  it never checks if the sv is NULL or undef
-- so returning undef from the custom GET_PROPERTY made it croak in
gperl_get_object_check.  The attached patch (hopefully) fixes that by
returning FALSE if the sv is not ok.

i had seen that, too, and meant to fix it but decided not to conflate
things.

gperl_value_from_sv() and gperl_sv_from_value() should fail only by
croaking and should always return TRUE.  this is something decided a
long, long time ago, but the signatures were never unchanged to avoid
breaking existing code.

Ah, I didn't know about that.

and, rationalizing it to myself; g_value_init() sets a default value
(whatever 0 means to that type) that should correspond roughly to
whatever we would map undef to, so bailing out early should be fine, and
should not be an error because we did map the sv (undef) to a value.

   if (!sv || !SvOK(sv))
       return TRUE;

now, is it really a good idea?  there's an implicit behavior for most of
those types; enums will croak on undef (currently) telling you that you
sent an invalid value through.  this change will silently skip that
warning.  of course, that warning was often hard to track down...  is
that alright?

Yeah, I see your point.  What about doing that check in the
G_TYPE_OBJECT branch of the switch then?  If we don't check the SV,
gperl_get_object_check will always croak and returning undef from a
subroutine that is supposed to return an object will not work.

Bye,
-Torsten




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]