Re: [RFC] automatic property getters and setters

On Sat, 2004-06-12 at 07:27, Torsten Schoenfeld wrote:
While toying around with, 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

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.

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?

muppet <scott at asofyet dot org>

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