Index: GParamSpec.xs
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/GParamSpec.xs,v
retrieving revision 1.24
diff -u -d -p -r1.24 GParamSpec.xs
--- GParamSpec.xs	17 Aug 2008 19:09:16 -0000	1.24
+++ GParamSpec.xs	17 Aug 2008 19:18:44 -0000
@@ -288,6 +288,45 @@ const gchar* g_param_spec_get_nick (GPar
 
 const gchar* g_param_spec_get_blurb (GParamSpec * pspec)
 
+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
 
@@ -697,27 +736,6 @@ get_maximum (GParamSpec * pspec)
 	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
@@ -794,27 +812,6 @@ get_maximum (GParamSpec * pspec)
 	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
@@ -847,13 +844,6 @@ get_maximum (GParamSpec * pspec)
     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
@@ -886,13 +876,6 @@ get_maximum (GParamSpec * pspec)
     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
@@ -955,23 +938,6 @@ get_maximum (GParamSpec * pspec)
 	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
 
@@ -988,27 +954,6 @@ get_epsilon (GParamSpec * pspec)
     OUTPUT:
 	RETVAL
 
-MODULE = Glib::ParamSpec	PACKAGE = Glib::Param::Boolean
-
-=for position post_hierarchy
-
-=head1 HIERARCHY
-
-  Glib::ParamSpec
-  +----Glib::Param::Boolean
-
-=cut
-
-=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 position post_hierarchy
@@ -1032,17 +977,6 @@ get_enum_class (GParamSpec * pspec_enum)
     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 position post_hierarchy
@@ -1066,74 +1000,13 @@ get_flags_class (GParamSpec * pspec_flag
     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 position post_hierarchy
-
-=head1 HIERARCHY
-
-  Glib::ParamSpec
-  +----Glib::Param::String
-
-=cut
-
-=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
-##  char substitutor
-##  bool null_fold_if_empty
-##  bool ensure_non_null
-
-MODULE = Glib::ParamSpec	PACKAGE = Glib::Param::Unichar
-
-=for position post_hierarchy
-
-=head1 HIERARCHY
-
-  Glib::ParamSpec
-  +----Glib::Param::Unichar
-
-=cut
-
-=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
-##fixed_n_elements
-
-## G_TYPE_PARAM_PARAM, "Glib::Param::Param" -- no members
-## G_TYPE_PARAM_BOXED, "Glib::Param::Boxed" -- no members
-## G_TYPE_PARAM_POINTER, "Glib::Param::Pointer" -- no members
-## G_TYPE_PARAM_OBJECT, "Glib::Param::Object" -- no members
-## G_TYPE_PARAM_OVERRIDE, "Glib::Param::Override" -- no public members
+# These don't have their MODULE section since they have no or no interesting
+# members:
+## Glib::Param::Boolean
+## Glib::Param::String
+## Glib::Param::Unichar
+## Glib::Param::Param
+## Glib::Param::Boxed
+## Glib::Param::Pointer
+## Glib::Param::Object
+## Glib::Param::Override
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	17 Aug 2008 19:18:44 -0000
@@ -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 @@ $pspec = Glib::ParamSpec->boolean ('bool
 	                           '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 @@ $pspec = Glib::ParamSpec->boxed ('boxed'
 	                         # 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 @@ $pspec = Glib::ParamSpec->object ('objec
 	                          '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 @@ is ($pspec->get_blurb, '', 'Param blurb'
 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 @@ push @params, $pspec;
 $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 @@ $pspec = Glib::ParamSpec->UV ('uv', 'UV'
 	                      '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 @@ $pspec = Glib::ParamSpec->scalar ('scala
 	                          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;
 
 
