Re: fetching unset GParamSpec property



Kevin Ryde wrote:
The program below gets some errors followed by a segv

    GLib-GObject-CRITICAL **: g_param_spec_ref: assertion `G_IS_PARAM_SPEC (pspec)' failed at 
/home/gg/bug/default-value/param-null.pl line 19.
    GLib-GObject-CRITICAL **: g_param_spec_sink: assertion `G_IS_PARAM_SPEC (pspec)' failed at 
/home/gg/bug/default-value/param-null.pl line 19.
    GLib-GObject-CRITICAL **: g_param_spec_get_name: assertion `G_IS_PARAM_SPEC (pspec)' failed at 
/home/gg/bug/default-value/param-null.pl line 19.

I guess newSVGParamSpec() expect NULL.  Is it meant to?  Or is it up to
_gperl_sv_from_value_internal(), per below?

I think newSVGParamSpec should follow the precedent of gperl_new_object,
gperl_new_boxed, and newSVGChar -- accept NULL and return undef.  As in the
attached patch.

muppet?

-- 
Bye,
-Torsten
Index: GParamSpec.xs
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/GParamSpec.xs,v
retrieving revision 1.23
diff -u -d -p -r1.23 GParamSpec.xs
--- GParamSpec.xs       17 Oct 2005 19:26:09 -0000      1.23
+++ GParamSpec.xs       13 Jul 2008 15:34:57 -0000
@@ -147,6 +147,9 @@ newSVGParamSpec (GParamSpec * pspec)
        HV * stash;
        const char * package;
 
+       if (!pspec)
+               return &PL_sv_undef;
+
        g_param_spec_ref (pspec);
        g_param_spec_sink (pspec);
 
Index: t/e.t
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/t/e.t,v
retrieving revision 1.2
diff -u -d -p -r1.2 e.t
--- t/e.t       20 Oct 2004 17:33:56 -0000      1.2
+++ t/e.t       13 Jul 2008 15:34:57 -0000
@@ -1,9 +1,10 @@
+#!/usr/bin/perl
 #
 # ParamSpec stuff.
 #
 use strict;
 use Glib ':constants';
-use Test::More tests => 231;
+use Test::More tests => 232;
 
 # first register some types with which to play below.
 
@@ -204,3 +205,13 @@ Glib::Type->register (
 foreach (@params) {
        is ($_->get_owner_type, 'Bar', ref($_)." owner type after adding");
 }
+
+
+
+#
+# verify that NULL param specs are handled gracefully
+#
+
+my $object = Bar->new;
+my $x = $object->get ('param_spec');
+is ($x, undef);


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