New attempt below, using the polymorphic g_param_value_set_default() in
all cases, but with the return converted specially as boolSV or newSVpv
for bools and unichars.
Maybe it'd be better to identify bool and unichar cases with some sort
of test of the input pspec's G_PARAM_SPEC_GET_CLASS(), instead of adding
"ALIAS"s.
--- GParamSpec.xs 18 Oct 2005 05:26:09 +1000 1.23
+++ GParamSpec.xs 15 Jul 2008 09:24:22 +1000
@@ -288,6 +288,48 @@
const gchar* g_param_spec_get_blurb (GParamSpec * pspec)
+=for apidoc
+(This is the C level C<g_param_value_set_default> function.)
+=cut
+SV *
+g_param_spec_get_default_value (GParamSpec * pspec)
+ ALIAS:
+ Glib::Param::Boolean::get_default_value = 1
+ Glib::Param::Unichar::get_default_value = 2
+ 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);
+ switch (ix) {
+ default:
+ RETVAL = gperl_sv_from_value (&v);
+ break;
+ case 1:
+ /* For historical compatibility we want boolSV here, the same as
+ gboolean typemap output. But gperl_sv_from_value() only puts
+ out newSViv() on a bool, hence a special case. */
+ RETVAL = boolSV (g_value_get_boolean (&v));
+ break;
+ case 2:
+ /* For usefulness and for historical compatibility we return a
+ single-char string here, the same as gunichar typemap output.
+ The GValue for a GParamSpecUnichar is only left set to a uint,
+ there's nothing gperl_sv_from_value() can look at to identify
+ it as a unichar, hence special code here. */
+ {
+ gchar temp[6];
+ gint length = g_unichar_to_utf8 (g_value_get_uint(&v), temp);
+ RETVAL = newSVpv (temp, length);
+ SvUTF8_on (RETVAL);
+ }
+ break;
+ }
+ g_value_unset (&v);
+ OUTPUT:
+ RETVAL
## stuff from gparamspecs.h
@@ -686,27 +728,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 +793,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 +820,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 +847,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 +901,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
@@ -950,16 +919,6 @@
MODULE = Glib::ParamSpec PACKAGE = Glib::Param::Boolean
-=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 +933,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 +947,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
@@ -1032,16 +961,6 @@
MODULE = Glib::ParamSpec PACKAGE = Glib::Param::Unichar
-=for see_also Glib::ParamSpec
-=cut
-
-gunichar
-get_default_value (GParamSpec * pspec_unichar)
- CODE:
- RETVAL = G_PARAM_SPEC_UNICHAR (pspec_unichar)->default_value;
- OUTPUT:
- RETVAL
-
##MODULE = Glib::ParamSpec PACKAGE = Glib::Param::ValueArray
##element_spec
--- e.t 02 Jun 2008 09:56:28 +1000 1.2
+++ e.t 15 Jul 2008 09:44:59 +1000
@@ -3,7 +3,7 @@
#
use strict;
use Glib ':constants';
-use Test::More tests => 231;
+use Test::More tests => 238;
# first register some types with which to play below.
@@ -58,11 +58,20 @@
'Is you is, or is you ain\'t my baby',
TRUE, 'readable');
pspec_common_ok ($pspec, 'Boolean', 'readable');
-ok ($pspec->get_default_value, "Boolean default (expect TRUE)");
+is ($pspec->get_default_value, 1, "Boolean default (expect TRUE)");
push @params, $pspec;
+$pspec = Glib::ParamSpec->boolean ('untrue', 'Untrue',
+ 'A pernicious falsehood',
+ FALSE, 'readable');
+# this is PL_sv_no, not a 0, for historical compatibility
+is ($pspec->get_default_value, '', "Boolean default (expect TRUE)");
+# not pushed, just checking the default
+# push @params, $pspec;
+
+
#
# all of the integer types have the same interface.
#
@@ -132,6 +141,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 +149,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 +165,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 +183,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 +192,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 +201,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;
_______________________________________________
gtk-perl-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list