[gjs] build: Add all enum values to switch statements
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] build: Add all enum values to switch statements
- Date: Sat, 22 Oct 2016 01:44:41 +0000 (UTC)
commit 4c33fe5619e8c12700e5ab436fb1bf6bbce4afb2
Author: Philip Chimento <philip endlessm com>
Date: Mon Oct 3 13:48:12 2016 -0700
build: Add all enum values to switch statements
It's become the recommended GNOME style to compile with -Wswitch-enum and
-Wswitch-default; see AX_COMPILER_FLAGS.
Per Philip Withnall, when purposely handling only a few possible enum
values inside a switch statement, it's better to use if statements.
On the other hand, when doing the much more common pattern of
default:
g_assert_not_reached();
it's better to list exactly which cases should not be reached, as well as
guard against invalid values with the default label.
https://bugzilla.gnome.org/show_bug.cgi?id=773297
gi/arg.cpp | 222 +++++++++++++++++++--------------------------
gi/boxed.cpp | 53 ++++++-----
gi/function.cpp | 110 +++++++++++-----------
gi/object.cpp | 2 +
gi/repo.cpp | 15 +++-
gi/value.cpp | 11 +--
gjs/importer.cpp | 3 +
gjs/jsapi-private.cpp | 3 +-
modules/cairo-pattern.cpp | 11 +-
modules/cairo-surface.cpp | 21 ++---
10 files changed, 212 insertions(+), 239 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index ff2b6c6..8f5b0bb 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -116,15 +116,11 @@ _gjs_enum_value_is_valid(JSContext *context,
static bool
_gjs_enum_uses_signed_type (GIEnumInfo *enum_info)
{
- switch (g_enum_info_get_storage_type (enum_info)) {
- case GI_TYPE_TAG_INT8:
- case GI_TYPE_TAG_INT16:
- case GI_TYPE_TAG_INT32:
- case GI_TYPE_TAG_INT64:
- return true;
- default:
- return false;
- }
+ GITypeTag storage = g_enum_info_get_storage_type(enum_info);
+ return (storage == GI_TYPE_TAG_INT8 ||
+ storage == GI_TYPE_TAG_INT16 ||
+ storage == GI_TYPE_TAG_INT32 ||
+ storage == GI_TYPE_TAG_INT64);
}
/* This is hacky - g_function_info_invoke() and g_field_info_get/set_field() expect
@@ -159,16 +155,16 @@ static bool
type_needs_release (GITypeInfo *type_info,
GITypeTag type_tag)
{
- switch (type_tag) {
- case GI_TYPE_TAG_UTF8:
- case GI_TYPE_TAG_FILENAME:
- case GI_TYPE_TAG_ARRAY:
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- case GI_TYPE_TAG_GHASH:
- case GI_TYPE_TAG_ERROR:
+ if (type_tag == GI_TYPE_TAG_UTF8 ||
+ type_tag == GI_TYPE_TAG_FILENAME ||
+ type_tag == GI_TYPE_TAG_ARRAY ||
+ type_tag == GI_TYPE_TAG_GLIST ||
+ type_tag == GI_TYPE_TAG_GSLIST ||
+ type_tag == GI_TYPE_TAG_GHASH ||
+ type_tag == GI_TYPE_TAG_ERROR)
return true;
- case GI_TYPE_TAG_INTERFACE: {
+
+ if (type_tag == GI_TYPE_TAG_INTERFACE) {
GIBaseInfo* interface_info;
GIInfoType interface_type;
GType gtype;
@@ -179,30 +175,23 @@ type_needs_release (GITypeInfo *type_info,
interface_type = g_base_info_get_type(interface_info);
- switch(interface_type) {
-
- case GI_INFO_TYPE_STRUCT:
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
- case GI_INFO_TYPE_OBJECT:
- case GI_INFO_TYPE_INTERFACE:
- case GI_INFO_TYPE_UNION:
- case GI_INFO_TYPE_BOXED:
+ if (interface_type == GI_INFO_TYPE_STRUCT ||
+ interface_type == GI_INFO_TYPE_ENUM ||
+ interface_type == GI_INFO_TYPE_FLAGS ||
+ interface_type == GI_INFO_TYPE_OBJECT ||
+ interface_type == GI_INFO_TYPE_INTERFACE ||
+ interface_type == GI_INFO_TYPE_UNION ||
+ interface_type == GI_INFO_TYPE_BOXED) {
/* These are subtypes of GIRegisteredTypeInfo for which the
* cast is safe */
gtype = g_registered_type_info_get_g_type
((GIRegisteredTypeInfo*)interface_info);
- break;
-
- case GI_INFO_TYPE_VALUE:
+ } else if (interface_type == GI_INFO_TYPE_VALUE) {
/* Special case for GValues */
gtype = G_TYPE_VALUE;
- break;
-
- default:
+ } else {
/* Everything else */
gtype = G_TYPE_NONE;
- break;
}
if (g_type_is_a(gtype, G_TYPE_CLOSURE))
@@ -216,9 +205,8 @@ type_needs_release (GITypeInfo *type_info,
return needs_release;
}
- default:
- return false;
- }
+
+ return false;
}
/* Check if an argument of the given needs to be released if we obtained it
@@ -228,47 +216,38 @@ static bool
type_needs_out_release(GITypeInfo *type_info,
GITypeTag type_tag)
{
- switch (type_tag) {
- case GI_TYPE_TAG_UTF8:
- case GI_TYPE_TAG_FILENAME:
- case GI_TYPE_TAG_ARRAY:
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- case GI_TYPE_TAG_GHASH:
- case GI_TYPE_TAG_ERROR:
+ if (type_tag == GI_TYPE_TAG_UTF8 ||
+ type_tag == GI_TYPE_TAG_FILENAME ||
+ type_tag == GI_TYPE_TAG_ARRAY ||
+ type_tag == GI_TYPE_TAG_GLIST ||
+ type_tag == GI_TYPE_TAG_GSLIST ||
+ type_tag == GI_TYPE_TAG_GHASH ||
+ type_tag == GI_TYPE_TAG_ERROR)
return true;
- case GI_TYPE_TAG_INTERFACE: {
+
+ if (type_tag == GI_TYPE_TAG_INTERFACE) {
GIBaseInfo* interface_info;
GIInfoType interface_type;
- bool needs_release;
+ bool needs_release = true;
interface_info = g_type_info_get_interface(type_info);
g_assert(interface_info != NULL);
interface_type = g_base_info_get_type(interface_info);
- switch(interface_type) {
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
+ if (interface_type == GI_INFO_TYPE_ENUM ||
+ interface_type == GI_INFO_TYPE_FLAGS)
needs_release = false;
- break;
-
- case GI_INFO_TYPE_STRUCT:
- case GI_INFO_TYPE_UNION:
- needs_release = g_type_info_is_pointer (type_info);
- break;
-
- default:
- needs_release = true;
- }
+ else if (interface_type == GI_INFO_TYPE_STRUCT ||
+ interface_type == GI_INFO_TYPE_UNION)
+ needs_release = g_type_info_is_pointer(type_info);
g_base_info_unref(interface_info);
return needs_release;
}
- default:
- return false;
- }
+
+ return false;
}
static bool
@@ -514,25 +493,23 @@ gjs_string_to_intarray(JSContext *context,
element_type = g_type_info_get_tag(param_info);
- switch (element_type) {
- case GI_TYPE_TAG_INT8:
- case GI_TYPE_TAG_UINT8:
+ if (element_type == GI_TYPE_TAG_INT8 || element_type == GI_TYPE_TAG_UINT8) {
if (!gjs_string_to_utf8(context, string_val, &result))
return false;
*arr_p = result;
*length = strlen(result);
return true;
+ }
- case GI_TYPE_TAG_INT16:
- case GI_TYPE_TAG_UINT16:
+ if (element_type == GI_TYPE_TAG_INT16 || element_type == GI_TYPE_TAG_UINT16) {
if (!gjs_string_get_uint16_data(context, string_val,
&result16, length))
return false;
*arr_p = result16;
return true;
+ }
- case GI_TYPE_TAG_UNICHAR:
- {
+ if (element_type == GI_TYPE_TAG_UNICHAR) {
gunichar *result_ucs4;
JS::RootedValue root(context, string_val);
if (!gjs_string_to_ucs4(context, root, &result_ucs4, length))
@@ -541,12 +518,10 @@ gjs_string_to_intarray(JSContext *context,
return true;
}
- default:
- /* can't convert a string to this type */
- gjs_throw(context, "Cannot convert string to array of '%s'",
- g_type_tag_to_string (element_type));
- return false;
- }
+ /* can't convert a string to this type */
+ gjs_throw(context, "Cannot convert string to array of '%s'",
+ g_type_tag_to_string (element_type));
+ return false;
}
static bool
@@ -850,28 +825,18 @@ static bool
is_gvalue(GIBaseInfo *info,
GIInfoType info_type)
{
- bool result = false;
-
- switch(info_type) {
- case GI_INFO_TYPE_VALUE:
- result = true;
- break;
- case GI_INFO_TYPE_STRUCT:
- case GI_INFO_TYPE_OBJECT:
- case GI_INFO_TYPE_INTERFACE:
- case GI_INFO_TYPE_BOXED:
- {
- GType gtype;
- gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo *) info);
+ if (info_type == GI_INFO_TYPE_VALUE)
+ return true;
- result = g_type_is_a(gtype, G_TYPE_VALUE);
- }
- break;
- default:
- break;
+ if (info_type == GI_INFO_TYPE_STRUCT ||
+ info_type == GI_INFO_TYPE_OBJECT ||
+ info_type == GI_INFO_TYPE_INTERFACE ||
+ info_type == GI_INFO_TYPE_BOXED) {
+ GType gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo *) info);
+ return g_type_is_a(gtype, G_TYPE_VALUE);
}
- return result;
+ return false;
}
static bool
@@ -977,6 +942,7 @@ gjs_array_to_array(JSContext *context,
transfer == GI_TRANSFER_CONTAINER ? GI_TRANSFER_NOTHING : transfer,
param_info,
arr_p);
+ case GI_TYPE_TAG_VOID:
default:
gjs_throw(context,
"Unhandled array element type %d", element_type);
@@ -1047,6 +1013,7 @@ gjs_g_array_new_for_type(JSContext *context,
case GI_TYPE_TAG_ERROR:
element_size = sizeof(gpointer);
break;
+ case GI_TYPE_TAG_VOID:
default:
gjs_throw(context,
"Unhandled GArray element-type %d", element_type);
@@ -1073,9 +1040,9 @@ get_argument_display_name(const char *arg_name,
return g_strdup("Hash element");
case GJS_ARGUMENT_ARRAY_ELEMENT:
return g_strdup("Array element");
+ default:
+ g_assert_not_reached ();
}
-
- g_assert_not_reached ();
}
static const char *
@@ -1407,37 +1374,32 @@ gjs_value_to_g_argument(JSContext *context,
expect_object = true;
}
- switch(interface_type) {
- case GI_INFO_TYPE_STRUCT:
- if (g_struct_info_is_foreign((GIStructInfo*)interface_info)) {
- bool ret;
- ret = gjs_struct_foreign_convert_to_g_argument(
- context, value, interface_info, arg_name,
- arg_type, transfer, may_be_null, arg);
- g_base_info_unref(interface_info);
- return ret;
- }
- /* fall through */
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
- case GI_INFO_TYPE_OBJECT:
- case GI_INFO_TYPE_INTERFACE:
- case GI_INFO_TYPE_UNION:
- case GI_INFO_TYPE_BOXED:
+ if (interface_type == GI_INFO_TYPE_STRUCT &&
+ g_struct_info_is_foreign((GIStructInfo*)interface_info)) {
+ bool ret;
+ ret = gjs_struct_foreign_convert_to_g_argument(
+ context, value, interface_info, arg_name,
+ arg_type, transfer, may_be_null, arg);
+ g_base_info_unref(interface_info);
+ return ret;
+ }
+
+ if (interface_type == GI_INFO_TYPE_STRUCT ||
+ interface_type == GI_INFO_TYPE_ENUM ||
+ interface_type == GI_INFO_TYPE_FLAGS ||
+ interface_type == GI_INFO_TYPE_OBJECT ||
+ interface_type == GI_INFO_TYPE_INTERFACE ||
+ interface_type == GI_INFO_TYPE_UNION ||
+ interface_type == GI_INFO_TYPE_BOXED) {
/* These are subtypes of GIRegisteredTypeInfo for which the
* cast is safe */
gtype = g_registered_type_info_get_g_type
((GIRegisteredTypeInfo*)interface_info);
- break;
- case GI_INFO_TYPE_VALUE:
+ } else if (interface_type == GI_INFO_TYPE_VALUE) {
/* Special case for GValues */
gtype = G_TYPE_VALUE;
- break;
-
- default:
- /* Everything else */
+ } else {
gtype = G_TYPE_NONE;
- break;
}
if (gtype != G_TYPE_NONE)
@@ -1956,19 +1918,14 @@ gjs_g_argument_init_default(JSContext *context,
interface_type = g_base_info_get_type(interface_info);
- switch(interface_type) {
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
+ if (interface_type == GI_INFO_TYPE_ENUM ||
+ interface_type == GI_INFO_TYPE_FLAGS)
arg->v_int = 0;
- break;
- case GI_INFO_TYPE_VALUE:
+ else if (interface_type == GI_INFO_TYPE_VALUE)
/* Better to use a non-NULL value holding NULL? */
arg->v_pointer = NULL;
- break;
- default:
+ else
arg->v_pointer = NULL;
- break;
- }
g_base_info_unref( (GIBaseInfo*) interface_info);
}
@@ -2220,6 +2177,7 @@ gjs_array_from_carray_internal (JSContext *context,
case GI_TYPE_TAG_ERROR:
ITERATE(pointer);
break;
+ case GI_TYPE_TAG_VOID:
default:
gjs_throw(context, "Unknown Array element-type %d", element_type);
return false;
@@ -2302,6 +2260,7 @@ gjs_array_from_boxed_array (JSContext *context,
data = ptr_array->pdata;
length = ptr_array->len;
break;
+ case GI_ARRAY_TYPE_C: /* already checked in gjs_value_from_g_argument() */
default:
g_assert_not_reached();
}
@@ -2409,6 +2368,7 @@ gjs_array_from_zero_terminated_c_array (JSContext *context,
case GI_TYPE_TAG_BOOLEAN:
gjs_throw(context, "Boolean zero-terminated array not supported");
return false;
+ case GI_TYPE_TAG_VOID:
default:
gjs_throw(context, "Unknown element-type %d", element_type);
return false;
@@ -3181,6 +3141,7 @@ gjs_g_arg_release_internal(JSContext *context,
g_free (arg->v_pointer);
break;
+ case GI_TYPE_TAG_VOID:
default:
gjs_throw(context,
"Releasing a C array with explicit length, that was nested"
@@ -3243,6 +3204,7 @@ gjs_g_arg_release_internal(JSContext *context,
break;
+ case GI_TYPE_TAG_VOID:
default:
gjs_throw(context,
"Don't know how to release GArray element-type %d",
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index b86cf7a..16aee62 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -940,29 +940,6 @@ type_can_be_allocated_directly(GITypeInfo *type_info)
}
} else {
switch (g_type_info_get_tag(type_info)) {
- case GI_TYPE_TAG_BOOLEAN:
- case GI_TYPE_TAG_INT8:
- case GI_TYPE_TAG_UINT8:
- case GI_TYPE_TAG_INT16:
- case GI_TYPE_TAG_UINT16:
- case GI_TYPE_TAG_INT32:
- case GI_TYPE_TAG_UINT32:
- case GI_TYPE_TAG_INT64:
- case GI_TYPE_TAG_UINT64:
- case GI_TYPE_TAG_FLOAT:
- case GI_TYPE_TAG_DOUBLE:
- case GI_TYPE_TAG_UNICHAR:
- break;
- case GI_TYPE_TAG_VOID:
- case GI_TYPE_TAG_GTYPE:
- case GI_TYPE_TAG_ERROR:
- case GI_TYPE_TAG_UTF8:
- case GI_TYPE_TAG_FILENAME:
- case GI_TYPE_TAG_ARRAY:
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- case GI_TYPE_TAG_GHASH:
- break;
case GI_TYPE_TAG_INTERFACE:
{
GIBaseInfo *interface = g_type_info_get_interface(type_info);
@@ -976,9 +953,6 @@ type_can_be_allocated_directly(GITypeInfo *type_info)
/* FIXME: Need to implement */
is_simple = false;
break;
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
- break;
case GI_INFO_TYPE_OBJECT:
case GI_INFO_TYPE_VFUNC:
case GI_INFO_TYPE_CALLBACK:
@@ -998,11 +972,38 @@ type_can_be_allocated_directly(GITypeInfo *type_info)
case GI_INFO_TYPE_INVALID_0:
g_assert_not_reached();
break;
+ case GI_INFO_TYPE_ENUM:
+ case GI_INFO_TYPE_FLAGS:
+ default:
+ break;
}
g_base_info_unref(interface);
break;
}
+ case GI_TYPE_TAG_BOOLEAN:
+ case GI_TYPE_TAG_INT8:
+ case GI_TYPE_TAG_UINT8:
+ case GI_TYPE_TAG_INT16:
+ case GI_TYPE_TAG_UINT16:
+ case GI_TYPE_TAG_INT32:
+ case GI_TYPE_TAG_UINT32:
+ case GI_TYPE_TAG_INT64:
+ case GI_TYPE_TAG_UINT64:
+ case GI_TYPE_TAG_FLOAT:
+ case GI_TYPE_TAG_DOUBLE:
+ case GI_TYPE_TAG_UNICHAR:
+ case GI_TYPE_TAG_VOID:
+ case GI_TYPE_TAG_GTYPE:
+ case GI_TYPE_TAG_ERROR:
+ case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
+ case GI_TYPE_TAG_ARRAY:
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ default:
+ break;
}
}
return is_simple;
diff --git a/gi/function.cpp b/gi/function.cpp
index ce542d2..3bd2030 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -104,6 +104,8 @@ set_return_ffi_arg_from_giargument (GITypeInfo *ret_type,
GIArgument *return_value)
{
switch (g_type_info_get_tag(ret_type)) {
+ case GI_TYPE_TAG_VOID:
+ g_assert_not_reached();
case GI_TYPE_TAG_INT8:
*(ffi_sarg *) result = return_value->v_int8;
break;
@@ -128,9 +130,6 @@ set_return_ffi_arg_from_giargument (GITypeInfo *ret_type,
case GI_TYPE_TAG_INT64:
*(ffi_sarg *) result = return_value->v_int64;
break;
- case GI_TYPE_TAG_UINT64:
- *(ffi_arg *) result = return_value->v_uint64;
- break;
case GI_TYPE_TAG_INTERFACE:
{
GIBaseInfo* interface_info;
@@ -139,18 +138,26 @@ set_return_ffi_arg_from_giargument (GITypeInfo *ret_type,
interface_info = g_type_info_get_interface(ret_type);
interface_type = g_base_info_get_type(interface_info);
- switch (interface_type) {
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
+ if (interface_type == GI_INFO_TYPE_ENUM ||
+ interface_type == GI_INFO_TYPE_FLAGS)
*(ffi_sarg *) result = return_value->v_long;
- break;
- default:
+ else
*(ffi_arg *) result = (ffi_arg) return_value->v_pointer;
- break;
- }
g_base_info_unref(interface_info);
}
+ case GI_TYPE_TAG_UINT64:
+ /* Other primitive and pointer types need to squeeze into 64-bit ffi_arg too */
+ case GI_TYPE_TAG_FLOAT:
+ case GI_TYPE_TAG_DOUBLE:
+ case GI_TYPE_TAG_GTYPE:
+ case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
+ case GI_TYPE_TAG_ARRAY:
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ case GI_TYPE_TAG_ERROR:
default:
*(ffi_arg *) result = (ffi_arg) return_value->v_uint64;
break;
@@ -265,6 +272,9 @@ gjs_callback_closure(ffi_cif *cif,
(GArgument *) args[i], false))
goto out;
break;
+ case PARAM_CALLBACK:
+ /* Callbacks that accept another callback as a parameter are not
+ * supported, see gjs_callback_trampoline_new() */
default:
g_assert_not_reached();
}
@@ -517,26 +527,23 @@ gjs_callback_trampoline_new(JSContext *context,
static unsigned long
get_length_from_arg (GArgument *arg, GITypeTag tag)
{
- switch (tag) {
- case GI_TYPE_TAG_INT8:
+ if (tag == GI_TYPE_TAG_INT8)
return arg->v_int8;
- case GI_TYPE_TAG_UINT8:
+ if (tag == GI_TYPE_TAG_UINT8)
return arg->v_uint8;
- case GI_TYPE_TAG_INT16:
+ if (tag == GI_TYPE_TAG_INT16)
return arg->v_int16;
- case GI_TYPE_TAG_UINT16:
+ if (tag == GI_TYPE_TAG_UINT16)
return arg->v_uint16;
- case GI_TYPE_TAG_INT32:
+ if (tag == GI_TYPE_TAG_INT32)
return arg->v_int32;
- case GI_TYPE_TAG_UINT32:
+ if (tag == GI_TYPE_TAG_UINT32)
return arg->v_uint32;
- case GI_TYPE_TAG_INT64:
+ if (tag == GI_TYPE_TAG_INT64)
return arg->v_int64;
- case GI_TYPE_TAG_UINT64:
+ if (tag == GI_TYPE_TAG_UINT64)
return arg->v_uint64;
- default:
- g_assert_not_reached ();
- }
+ g_assert_not_reached();
}
static bool
@@ -550,9 +557,7 @@ gjs_fill_method_instance(JSContext *context,
GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)container);
GITransfer transfer = g_callable_info_get_instance_ownership_transfer (function->info);
- switch (type) {
- case GI_INFO_TYPE_STRUCT:
- case GI_INFO_TYPE_BOXED:
+ if (type == GI_INFO_TYPE_STRUCT || type == GI_INFO_TYPE_BOXED) {
/* GError must be special cased */
if (g_type_is_a(gtype, G_TYPE_ERROR)) {
if (!gjs_typecheck_gerror(context, obj, true))
@@ -600,19 +605,16 @@ gjs_fill_method_instance(JSContext *context,
}
}
}
- break;
- case GI_INFO_TYPE_UNION:
+ } else if (type == GI_INFO_TYPE_UNION) {
if (!gjs_typecheck_union(context, obj, container, gtype, true))
return false;
out_arg->v_pointer = gjs_c_union_from_union(context, obj);
if (transfer == GI_TRANSFER_EVERYTHING)
out_arg->v_pointer = g_boxed_copy (gtype, out_arg->v_pointer);
- break;
- case GI_INFO_TYPE_OBJECT:
- case GI_INFO_TYPE_INTERFACE:
+ } else if (type == GI_INFO_TYPE_OBJECT || type == GI_INFO_TYPE_INTERFACE) {
if (g_type_is_a(gtype, G_TYPE_OBJECT)) {
if (!gjs_typecheck_object(context, obj, gtype, true))
return false;
@@ -652,9 +654,8 @@ gjs_fill_method_instance(JSContext *context,
g_base_info_get_name(container));
return false;
}
- break;
- default:
+ } else {
g_assert_not_reached();
}
@@ -795,35 +796,31 @@ gjs_invoke_c_function(JSContext *context,
g_arg_info_load_type(&arg_info, &ainfo);
type_tag = g_type_info_get_tag(&ainfo);
- switch (type_tag) {
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo* interface_info;
- GIInfoType interface_type;
- gsize size;
+ if (type_tag == GI_TYPE_TAG_INTERFACE) {
+ GIBaseInfo* interface_info;
+ GIInfoType interface_type;
+ gsize size;
- interface_info = g_type_info_get_interface(&ainfo);
- g_assert(interface_info != NULL);
+ interface_info = g_type_info_get_interface(&ainfo);
+ g_assert(interface_info != NULL);
- interface_type = g_base_info_get_type(interface_info);
+ interface_type = g_base_info_get_type(interface_info);
- if (interface_type == GI_INFO_TYPE_STRUCT) {
- size = g_struct_info_get_size((GIStructInfo*)interface_info);
- } else if (interface_type == GI_INFO_TYPE_UNION) {
- size = g_union_info_get_size((GIUnionInfo*)interface_info);
- } else {
- failed = true;
- }
+ if (interface_type == GI_INFO_TYPE_STRUCT) {
+ size = g_struct_info_get_size((GIStructInfo*)interface_info);
+ } else if (interface_type == GI_INFO_TYPE_UNION) {
+ size = g_union_info_get_size((GIUnionInfo*)interface_info);
+ } else {
+ failed = true;
+ }
- g_base_info_unref((GIBaseInfo*)interface_info);
+ g_base_info_unref((GIBaseInfo*)interface_info);
- if (!failed) {
- in_arg_cvalues[c_arg_pos].v_pointer = g_slice_alloc0(size);
- out_arg_cvalues[c_arg_pos].v_pointer = in_arg_cvalues[c_arg_pos].v_pointer;
- }
- break;
+ if (!failed) {
+ in_arg_cvalues[c_arg_pos].v_pointer = g_slice_alloc0(size);
+ out_arg_cvalues[c_arg_pos].v_pointer = in_arg_cvalues[c_arg_pos].v_pointer;
}
- default:
+ } else {
failed = true;
}
if (failed)
@@ -945,6 +942,9 @@ gjs_invoke_c_function(JSContext *context,
failed = true;
break;
}
+
+ default:
+ ;
}
if (direction == GI_DIRECTION_INOUT && !arg_removed && !failed) {
diff --git a/gi/object.cpp b/gi/object.cpp
index 71b16c5..163dc75 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -359,6 +359,7 @@ object_instance_set_prop(JSContext *context,
case NO_SUCH_G_PROPERTY:
goto out;
case VALUE_WAS_SET:
+ default:
break;
}
@@ -721,6 +722,7 @@ object_instance_props_to_g_parameters(JSContext *context,
g_free(name);
goto free_array_and_fail;
case VALUE_WAS_SET:
+ default:
break;
}
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 8ba1659..6051a9d 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -528,6 +528,17 @@ gjs_define_info(JSContext *context,
&ignored);
}
break;
+ case GI_INFO_TYPE_INVALID:
+ case GI_INFO_TYPE_INVALID_0:
+ case GI_INFO_TYPE_CALLBACK:
+ case GI_INFO_TYPE_VALUE:
+ case GI_INFO_TYPE_SIGNAL:
+ case GI_INFO_TYPE_VFUNC:
+ case GI_INFO_TYPE_PROPERTY:
+ case GI_INFO_TYPE_FIELD:
+ case GI_INFO_TYPE_ARG:
+ case GI_INFO_TYPE_TYPE:
+ case GI_INFO_TYPE_UNRESOLVED:
default:
gjs_throw(context, "API of type %s not implemented, cannot define %s.%s",
gjs_info_type_name(g_base_info_get_type(info)),
@@ -706,9 +717,9 @@ gjs_info_type_name(GIInfoType type)
case GI_INFO_TYPE_INVALID_0:
g_assert_not_reached();
break;
+ default:
+ return "???";
}
-
- return "???";
}
char*
diff --git a/gi/value.cpp b/gi/value.cpp
index c2114c7..a3da3fc 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -890,17 +890,14 @@ gjs_value_from_g_value_internal(JSContext *context,
return ret;
}
- switch (g_base_info_get_type(info)) {
- case GI_INFO_TYPE_BOXED:
- case GI_INFO_TYPE_STRUCT:
+ GIInfoType type = g_base_info_get_type(info);
+ if (type == GI_INFO_TYPE_BOXED || type == GI_INFO_TYPE_STRUCT) {
if (no_copy)
boxed_flags = (GjsBoxedCreationFlags) (boxed_flags | GJS_BOXED_CREATION_NO_COPY);
obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)info, gboxed, boxed_flags);
- break;
- case GI_INFO_TYPE_UNION:
+ } else if (type == GI_INFO_TYPE_UNION) {
obj = gjs_union_from_c_union(context, (GIUnionInfo *)info, gboxed);
- break;
- default:
+ } else {
gjs_throw(context,
"Unexpected introspection type %d for %s",
g_base_info_get_type(info),
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 966caac..4ea961e 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -813,6 +813,9 @@ importer_new_enumerate(JSContext *context,
statep.setNull();
}
}
+
+ default:
+ ;
}
return true;
diff --git a/gjs/jsapi-private.cpp b/gjs/jsapi-private.cpp
index 6469c82..36a83d6 100644
--- a/gjs/jsapi-private.cpp
+++ b/gjs/jsapi-private.cpp
@@ -59,13 +59,12 @@ gjs_error_reporter(JSContext *context,
level = G_LOG_LEVEL_MESSAGE;
/* suppress bogus warnings. See mozilla/js/src/js.msg */
- switch (report->errorNumber) {
+ if (report->errorNumber == 162) {
/* 162, JSMSG_UNDEFINED_PROP: warns every time a lazy property
* is resolved, since the property starts out
* undefined. When this is a real bug it should usually
* fail somewhere else anyhow.
*/
- case 162:
return;
}
} else {
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index cab1a09..7d00ffe 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -167,13 +167,14 @@ gjs_cairo_pattern_from_pattern(JSContext *context,
return gjs_cairo_linear_gradient_from_pattern(context, pattern);
case CAIRO_PATTERN_TYPE_RADIAL:
return gjs_cairo_radial_gradient_from_pattern(context, pattern);
+ case CAIRO_PATTERN_TYPE_MESH:
+ case CAIRO_PATTERN_TYPE_RASTER_SOURCE:
default:
- break;
+ gjs_throw(context,
+ "failed to create pattern, unsupported pattern type %d",
+ cairo_pattern_get_type(pattern));
+ return NULL;
}
-
- gjs_throw(context, "failed to create pattern, unsupported pattern type %d",
- cairo_pattern_get_type(pattern));
- return NULL;
}
/**
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index e1a43ed..2eb8614 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -195,18 +195,15 @@ gjs_cairo_surface_from_surface(JSContext *context,
g_return_val_if_fail(context != NULL, NULL);
g_return_val_if_fail(surface != NULL, NULL);
- switch (cairo_surface_get_type(surface)) {
- case CAIRO_SURFACE_TYPE_IMAGE:
- return gjs_cairo_image_surface_from_surface(context, surface);
- case CAIRO_SURFACE_TYPE_PDF:
- return gjs_cairo_pdf_surface_from_surface(context, surface);
- case CAIRO_SURFACE_TYPE_PS:
- return gjs_cairo_ps_surface_from_surface(context, surface);
- case CAIRO_SURFACE_TYPE_SVG:
- return gjs_cairo_svg_surface_from_surface(context, surface);
- default:
- break;
- }
+ cairo_surface_type_t type = cairo_surface_get_type(surface);
+ if (type == CAIRO_SURFACE_TYPE_IMAGE)
+ return gjs_cairo_image_surface_from_surface(context, surface);
+ if (type == CAIRO_SURFACE_TYPE_PDF)
+ return gjs_cairo_pdf_surface_from_surface(context, surface);
+ if (type == CAIRO_SURFACE_TYPE_PS)
+ return gjs_cairo_ps_surface_from_surface(context, surface);
+ if (type == CAIRO_SURFACE_TYPE_SVG)
+ return gjs_cairo_svg_surface_from_surface(context, surface);
JS::RootedObject object(context,
JS_NewObject(context, &gjs_cairo_surface_class, NULL, NULL));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]