Commit 6585e550 authored by Christian Kellner's avatar Christian Kellner

common: flags: stronger pre-condition checking

Make having a valid flags class and type a precondition instead
of doing standard error checking on the parameters. Passing an
invalid type/class is a programming error, treat is as such.
parent c30fa308
......@@ -138,15 +138,7 @@ bolt_flags_class_to_string (GFlagsClass *flags_class,
const char *name;
GFlagsValue *fv;
if (flags_class == NULL)
{
name = g_type_name_from_class ((GTypeClass *) flags_class);
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"could not determine flags class for '%s'",
name);
return FALSE;
}
g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), FALSE);
fv = g_flags_get_first_value (flags_class, value);
if (fv == NULL)
......@@ -195,13 +187,7 @@ bolt_flags_class_from_string (GFlagsClass *flags_class,
const char *name;
guint flags = 0;
if (flags_class == NULL)
{
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
"could not determine flags class");
return FALSE;
}
g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), FALSE);
if (string == NULL)
{
......@@ -247,7 +233,10 @@ bolt_flags_to_string (GType flags_type,
{
g_autoptr(GFlagsClass) klass = NULL;
g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
klass = g_type_class_ref (flags_type);
return bolt_flags_class_to_string (klass, value, error);
}
......@@ -259,7 +248,10 @@ bolt_flags_from_string (GType flags_type,
{
g_autoptr(GFlagsClass) klass = NULL;
g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), FALSE);
klass = g_type_class_ref (flags_type);
return bolt_flags_class_from_string (klass, string, flags_out, error);
}
......
......@@ -328,17 +328,6 @@ test_flags (TestRng *tt, gconstpointer user_data)
g_assert_cmpuint (val, ==, ftt[i].value);
}
/* handle NULL for flags class */
ok = bolt_flags_class_from_string (NULL, "fax-machine", &val, &err);
g_assert_error (err, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_false (ok);
g_clear_error (&err);
str = bolt_flags_class_to_string (NULL, 0xFFFF, &err);
g_assert_error (err, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_null (str);
g_clear_error (&err);
/* handle invalid values */
klass = g_type_class_ref (BOLT_TYPE_KITT_FLAGS);
g_assert_nonnull (klass);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment