Torsten Schoenfeld <[EMAIL PROTECTED]> writes: > > So what you're suggesting is that we implement a generic > Glib::ParamSpec->get_default_value by using g_param_value_set_default.
Yep. > It won't work like this though, I think. The XSUB would need to be > called simply g_param_spec_get_default_value and would need to reside in > a MODULE section with "PREFIX = g_param_spec_". Ah yes. I was playing with the other couple that are only g_param_foo instead of g_param_spec_foo. > Then you'd have to > remove all the get_default_value XSUBs from the various subclasses. Though I see the gunichar one stays, to continue to return a string. > If the test suite still passes after these changes, we have a winner. Plus a couple more tests for object, boxed, etc which now get the generic method. The "param" one tickles the NULL problem too, per other message. > Also, your patch mixes spaces and tabs for indention. Ah, that'll be a combination of cut and paste and me having `indent-tabs' off normally. I've yet to find an emacs setup that works decently for xs. I tend to use cc-mode with some settings, and then get annoyed when it indents wrong, and then switch to text-mode or pod-mode for the doc bits :-( * GParamSpec.xs (get_default_value): Use g_param_value_set_default instead of explicit code, except keep Glib::Param::Unichar. * t/e.t: Exercise get_default_value on Object, Boxed, Param, Scalar, IV and UV, as they now get that func. Note Glib::Param::Boolean::get_default_value previously returned the empty string '' for false, but now ends up 0 from the generic gperl_sv_from_value. This may be a good thing since 0 is what $obj->get() itself returns for a false bool property.
--- GParamSpec.xs 18 Oct 2005 05:26:09 +1000 1.23 +++ GParamSpec.xs 23 Jun 2008 19:12:06 +1000 @@ -288,6 +288,26 @@ const gchar* g_param_spec_get_blurb (GParamSpec * pspec) +=for apidoc +This is the C level C<value_set_default> method of GParamSpecClass. +If C<$pspec> doesn't have a C<default_value> field the return is +C<undef> (for example object or scalar). + +See also L<Glib::Param::Unichar> which has its own version of this method. +=cut +SV * +g_param_spec_get_default_value (GParamSpec * pspec) + PREINIT: + GValue v = { 0, }; + GType type; + CODE: + type = G_PARAM_SPEC_VALUE_TYPE (pspec); + g_value_init (&v, type); + g_param_value_set_default (pspec, &v); + RETVAL = gperl_sv_from_value (&v); + g_value_unset (&v); + OUTPUT: + RETVAL ## stuff from gparamspecs.h @@ -686,27 +706,6 @@ RETVAL -=for apidoc Glib::Param::Char::get_default_value __hide__ -=cut - -=for apidoc Glib::Param::Long::get_default_value __hide__ -=cut - -IV -get_default_value (GParamSpec * pspec) - ALIAS: - Glib::Param::Int::get_default_value = 1 - Glib::Param::Long::get_default_value = 2 - CODE: - switch (ix) { - case 0: RETVAL = G_PARAM_SPEC_CHAR (pspec)->default_value; break; - case 1: RETVAL = G_PARAM_SPEC_INT (pspec)->default_value; break; - case 2: RETVAL = G_PARAM_SPEC_LONG (pspec)->default_value; break; - default: g_assert_not_reached (); RETVAL = 0; - } - OUTPUT: - RETVAL - MODULE = Glib::ParamSpec PACKAGE = Glib::Param::UChar ## similarly, all unsigned integer types @@ -772,27 +771,6 @@ RETVAL -=for apidoc Glib::Param::UChar::get_default_value __hide__ -=cut - -=for apidoc Glib::Param::ULong::get_default_value __hide__ -=cut - -UV -get_default_value (GParamSpec * pspec) - ALIAS: - Glib::Param::UInt::get_default_value = 1 - Glib::Param::ULong::get_default_value = 2 - CODE: - switch (ix) { - case 0: RETVAL = G_PARAM_SPEC_UCHAR (pspec)->default_value; break; - case 1: RETVAL = G_PARAM_SPEC_UINT (pspec)->default_value; break; - case 2: RETVAL = G_PARAM_SPEC_ULONG (pspec)->default_value; break; - default: g_assert_not_reached (); RETVAL = 0; - } - OUTPUT: - RETVAL - MODULE = Glib::ParamSpec PACKAGE = Glib::Param::Int64 =for object Glib::Param::Int64 @@ -820,13 +798,6 @@ OUTPUT: RETVAL -gint64 -get_default_value (GParamSpec * pspec) - CODE: - RETVAL = G_PARAM_SPEC_INT64 (pspec)->default_value; - OUTPUT: - RETVAL - MODULE = Glib::ParamSpec PACKAGE = Glib::Param::UInt64 =for object Glib::Param::UInt64 @@ -854,13 +825,6 @@ OUTPUT: RETVAL -guint64 -get_default_value (GParamSpec * pspec) - CODE: - RETVAL = G_PARAM_SPEC_UINT64 (pspec)->default_value; - OUTPUT: - RETVAL - MODULE = Glib::ParamSpec PACKAGE = Glib::Param::Float ## and again for the floating-point types @@ -915,23 +879,6 @@ RETVAL -=for apidoc Glib::Param::Float::get_default_value __hide__ -=cut - -double -get_default_value (GParamSpec * pspec) - ALIAS: - Glib::Param::Double::get_default_value = 1 - CODE: - switch (ix) { - case 0: RETVAL = G_PARAM_SPEC_FLOAT (pspec)->default_value; break; - case 1: RETVAL = G_PARAM_SPEC_DOUBLE (pspec)->default_value; break; - default: g_assert_not_reached (); RETVAL = 0.0; - } - OUTPUT: - RETVAL - - =for apidoc Glib::Param::Float::get_epsilon __hide__ =cut @@ -953,13 +900,6 @@ =for see_also Glib::ParamSpec =cut -gboolean -get_default_value (GParamSpec * pspec_boolean) - CODE: - RETVAL = G_PARAM_SPEC_BOOLEAN (pspec_boolean)->default_value; - OUTPUT: - RETVAL - MODULE = Glib::ParamSpec PACKAGE = Glib::Param::Enum =for see_also Glib::ParamSpec @@ -974,17 +914,6 @@ OUTPUT: RETVAL -SV * -get_default_value (GParamSpec * pspec_enum) - PREINIT: - GParamSpecEnum * penum; - CODE: - penum = G_PARAM_SPEC_ENUM (pspec_enum); - RETVAL = gperl_convert_back_enum (G_ENUM_CLASS_TYPE (penum->enum_class), - penum->default_value); - OUTPUT: - RETVAL - MODULE = Glib::ParamSpec PACKAGE = Glib::Param::Flags =for see_also Glib::ParamSpec @@ -999,30 +928,11 @@ OUTPUT: RETVAL -SV * -get_default_value (GParamSpec * pspec_flags) - PREINIT: - GParamSpecFlags * pflags; - CODE: - pflags = G_PARAM_SPEC_FLAGS (pspec_flags); - RETVAL = gperl_convert_back_flags - (G_FLAGS_CLASS_TYPE (pflags->flags_class), - pflags->default_value); - OUTPUT: - RETVAL - MODULE = Glib::ParamSpec PACKAGE = Glib::Param::String =for see_also Glib::ParamSpec =cut -gchar * -get_default_value (GParamSpec * pspec_string) - CODE: - RETVAL = G_PARAM_SPEC_STRING (pspec_string)->default_value; - OUTPUT: - RETVAL - ## the others are fairly uninteresting. ## string cset_first ## string cset_nth @@ -1035,6 +945,14 @@ =for see_also Glib::ParamSpec =cut +# this overrides the base get_default_value() in Glib::ParamSpec above +# because a GParamSpecUnichar is only type G_TYPE_UINT and so comes +# back from gperl_sv_from_value() as an integer, where we prefer a +# string (a single-char Perl wide-char string) +# +=for apidoc +Return the default value as a single-character string. +=cut gunichar get_default_value (GParamSpec * pspec_unichar) CODE:
--- e.t 02 Jun 2008 09:56:28 +1000 1.2 +++ e.t 23 Jun 2008 16:50:32 +1000 @@ -3,7 +3,7 @@ # use strict; use Glib ':constants'; -use Test::More tests => 231; +use Test::More tests => 237; # first register some types with which to play below. @@ -132,6 +132,7 @@ # we only know one boxed type at this point. 'Glib::Scalar', G_PARAM_READWRITE); pspec_common_ok ($pspec, 'Boxed', G_PARAM_READWRITE, 'Glib::Scalar'); +is ($pspec->get_default_value, undef, 'Boxed default'); push @params, $pspec; @@ -139,6 +140,7 @@ 'I object, Your Honor, that\'s pure conjecture!', 'Skeezle', G_PARAM_READWRITE); pspec_common_ok ($pspec, 'Object', G_PARAM_READWRITE, 'Skeezle'); +is ($pspec->get_default_value, undef, 'Object default'); push @params, $pspec; @@ -154,6 +156,7 @@ ok ($pspec->get_flags == G_PARAM_READWRITE, 'Param flags'); is ($pspec->get_value_type, 'Glib::Param::Enum', 'Param value type'); ok (! $pspec->get_owner_type, 'Param owner type'); +is ($pspec->get_default_value, undef, 'Param default'); push @params, $pspec; @@ -171,6 +174,7 @@ $pspec = Glib::ParamSpec->IV ('iv', 'IV', 'This is the same as Int', -20, 10, -5, G_PARAM_READWRITE); +is ($pspec->get_default_value, -5, 'IV default'); isa_ok ($pspec, 'Glib::Param::Long', 'IV is actually Long'); push @params, $pspec; @@ -179,6 +183,7 @@ 'This is the same as UInt', 10, 20, 15, G_PARAM_READWRITE); isa_ok ($pspec, 'Glib::Param::ULong', 'UV is actually ULong'); +is ($pspec->get_default_value, 15, 'UV default'); push @params, $pspec; @@ -187,6 +192,7 @@ G_PARAM_READWRITE); isa_ok ($pspec, 'Glib::Param::Boxed', 'Scalar is actually Boxed'); is ($pspec->get_value_type, 'Glib::Scalar', 'boxed holding scalar'); +is ($pspec->get_default_value, undef, 'Scalar default'); push @params, $pspec;
-- The sigfile one-line movie reviews series: "Razorback" -- easily the best homicidal wild pig movie ever made.
_______________________________________________ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list