[perl-Glib] Fix fetching default values for unichar properties of custom subclasses
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib] Fix fetching default values for unichar properties of custom subclasses
- Date: Wed, 24 Nov 2010 20:37:26 +0000 (UTC)
commit 9cfd1bd7bfc560a8e2d9d8a589e19523ae1d2a15
Author: Kevin Ryde <user42 zip com au>
Date: Wed Nov 24 07:52:18 2010 +1100
Fix fetching default values for unichar properties of custom subclasses
In gperl_type_get_property() use g_param_value_set_default() for the pspec
default value instead of a call out to the Perl level get_default_value()
method.
Fixes Perl-implemented object $obj->get_property() of a
GParamSpecUnichar property. Previously got a warning like "Argument
"\x{78}" isn't numeric in subroutine entry" and the wrong value due to
get_default_value() giving a string but GValue wanting a uint
codepoint. (Both before and after the recent get_default_value()
unification changes.)
This doesn't lose any support for Perl-code subclassed ParamSpecs,
since such subclassing doesn't work properly yet. There's no boxed
subclassing, and a mere re-blessing has never reached
gperl_type_get_property(), it sees only the C-level object, so a
different get_default_value() in a reblessing was never reached by
this gperl_type_get_property().
https://bugzilla.gnome.org/show_bug.cgi?id=567668
GType.xs | 63 +-------------------------------------------------------------
NEWS | 5 ++++
t/e.t | 17 +++++++++++++++-
3 files changed, 22 insertions(+), 63 deletions(-)
---
diff --git a/GType.xs b/GType.xs
index 92332ed..3f36241 100644
--- a/GType.xs
+++ b/GType.xs
@@ -1539,67 +1539,6 @@ add_interfaces (GType instance_type, AV * interfaces)
}
-/* set value to the default value of the given pspec, if the pspec supports
- * default values.
- */
-static void
-get_default_property_value (GValue * value,
- GParamSpec * pspec)
-{
- /*
- * not all pspec types support a default value, and user code can
- * add pspec types; thus, glib does not provide a unified way to
- * get a default value for a param. also, the default value member
- * may be at different offsets in the various param spec structs,
- * so to do this in pure C we'd have to create a whole slew of
- * helper functions to set the default values and put them in a
- * hash table (or an if-else tree -- since the type codes are dynamic,
- * we can't use them in a switch). however, that would leave us with
- * code bloat and a maintenance problem, since we'd have to add code
- * for each new param type, and we'd never handle custom params.
- *
- * instead, let's use the existing infrastructure in the bindings,
- * and let perl's oo system do the hard work for us. this will catch
- * any custom params as well (provided their default_value accessors
- * have been bound), at a slight cost in performance.
- */
- const char * package;
- GV * method = NULL;
- HV * stash;
- package = gperl_param_spec_package_from_type (G_PARAM_SPEC_TYPE (pspec));
- if (!package)
- croak ("Param spec type %s is not registered with GPerl",
- g_type_name (G_PARAM_SPEC_TYPE (pspec)));
- stash = gv_stashpv (package, TRUE);
- assert (stash);
- method = gv_fetchmethod (stash, "get_default_value");
-
- if (method) {
- SV * sv;
-
- dSP;
- ENTER;
- SAVETMPS;
- PUSHMARK (SP);
- PUSHs (sv_2mortal (newSVGParamSpec (pspec)));
- PUTBACK;
-
- call_sv ((SV *)GvCV (method), G_SCALAR);
- SPAGAIN;
-
- sv = POPs;
- gperl_value_from_sv (value, sv);
-
- PUTBACK;
- FREETMPS;
- LEAVE;
-
- } else {
- /* no method, so no way to fetch a default value.
- * do nothing. */
- }
-}
-
static void
gperl_type_get_property (GObject * object,
guint property_id,
@@ -1663,7 +1602,7 @@ gperl_type_get_property (GObject * object,
else {
/* no value in the wrapper hash. get the pspec's
* default, if it has one. */
- get_default_property_value (value, pspec);
+ g_param_value_set_default (pspec, value);
}
}
}
diff --git a/NEWS b/NEWS
index 329521d..271367f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+Overview of changes in the next unstable release of Glib
+========================================================
+
+* Fix fetching default values for unichar properties of custom subclasses.
+
Overview of changes in Glib 1.230
=================================
diff --git a/t/e.t b/t/e.t
index 9072a82..81e3173 100644
--- a/t/e.t
+++ b/t/e.t
@@ -5,7 +5,7 @@
use strict;
use utf8;
use Glib ':constants';
-use Test::More tests => 311;
+use Test::More tests => 312;
# first register some types with which to play below.
@@ -243,6 +243,21 @@ foreach (@params) {
is ($_->get_owner_type, 'Bar', ref($_)." owner type after adding");
}
+{
+ my $object = Bar->new;
+
+ # exercise default GET_PROPERTY fetching pspec default value
+ foreach my $pspec (@params) {
+ if ($pspec->get_flags & 'readable') {
+ my $pname = $pspec->get_name;
+ $object->get($pname);
+ }
+ }
+
+ is ($object->get_property('unichar'), ord('ö'),
+ 'get_property() unichar default value (unicode code point number)');
+}
+
SKIP: {
skip "GParamSpecOverride is new in glib 2.4.0", 27
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]