[perl-Glib/enum-constants] Ensure that incorrect enum string values still raise an exception
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib/enum-constants] Ensure that incorrect enum string values still raise an exception
- Date: Thu, 13 Aug 2015 20:40:46 +0000 (UTC)
commit 9b2a6332438824cee66ae4a78dc2bf4d14528408
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date: Thu Aug 13 22:38:03 2015 +0200
Ensure that incorrect enum string values still raise an exception
This was inadvertently changed when the numeric enum value subs were
introduced.
GType.xs | 19 ++++++++++---------
t/c.t | 9 ++++++++-
2 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/GType.xs b/GType.xs
index 16b6123..8687043 100644
--- a/GType.xs
+++ b/GType.xs
@@ -397,14 +397,16 @@ gperl_try_convert_enum (GType type,
}
/* then, try again as an integer */
- val_i = SvIV (sv);
- vals_iter = vals;
- while (vals_iter && vals_iter->value_nick && vals_iter->value_name) {
- if (vals_iter->value == val_i) {
- *val = vals_iter->value;
- return TRUE;
+ if (SvIOK (sv) || SvUOK (sv) || SvNOK (sv)) {
+ val_i = SvIV (sv);
+ vals_iter = vals;
+ while (vals_iter && vals_iter->value_nick && vals_iter->value_name) {
+ if (vals_iter->value == val_i) {
+ *val = vals_iter->value;
+ return TRUE;
+ }
+ vals_iter++;
}
- vals_iter++;
}
/* give up */
@@ -515,8 +517,7 @@ gperl_check_flag_int (GType type,
guint val_i)
{
GFlagsValue * vals;
- guint i, remainder;
- GArray *vals_i;
+ guint remainder;
vals = gperl_type_flags_get_values (type);
remainder = val_i;
while (vals && vals->value_nick && vals->value_name) {
diff --git a/t/c.t b/t/c.t
index 13f6211..13b333c 100644
--- a/t/c.t
+++ b/t/c.t
@@ -14,7 +14,7 @@ use List::Util qw/sum/;
#########################
-use Test::More tests => 125;
+use Test::More tests => 126;
BEGIN { use_ok('Glib') };
#########################
@@ -308,6 +308,13 @@ ok ($obj->get ('some_flags') ne [qw/value-one/], 'ne is overloaded');
is_deeply ([map { *{'Glib::IOCondition::' . $_}->() } @subs], \ values,
'Glib::IOCondition: the constants and Glib::Type->list_values agree');
+ # Check that using an incorrect enum string value still raises an exception.
+ {
+ local $@;
+ eval { Glib::get_user_special_dir ("desktopp") };
+ like ($@, qr/invalid/, 'invalid enum value dies');
+ }
+
skip 'new 2.14 stuff', 1
unless Glib->CHECK_VERSION (2, 14, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]