[glib/fix-gnulib-msvc-isnan: 23/37] gobject: Handle runtime checks as such
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/fix-gnulib-msvc-isnan: 23/37] gobject: Handle runtime checks as such
- Date: Tue, 9 Jun 2020 10:23:06 +0000 (UTC)
commit d8d7a5507466eefc939c5d018625fa5bf0d82766
Author: Edward Hervey <edward centricular com>
Date: Wed May 20 17:37:46 2020 +0200
gobject: Handle runtime checks as such
The various `g_strdup_printf()` returns values in the implementations of GValue
lcopy_func are runtime checks which could be disabled if one wants and therefore
should be handled as such with g_return_val_if_fail()
gobject/gboxed.c | 3 +--
gobject/genums.c | 7 +++---
gobject/gobject.c | 5 ++---
gobject/gparam.c | 3 +--
gobject/gtype.h | 18 ++++++---------
gobject/gvaluetypes.c | 62 +++++++++++++++++++++------------------------------
6 files changed, 40 insertions(+), 58 deletions(-)
---
diff --git a/gobject/gboxed.c b/gobject/gboxed.c
index 87cc5d2c2..a4c2c3805 100644
--- a/gobject/gboxed.c
+++ b/gobject/gboxed.c
@@ -256,8 +256,7 @@ boxed_proxy_lcopy_value (const GValue *value,
{
gpointer *boxed_p = collect_values[0].v_pointer;
- if (!boxed_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+ g_return_val_if_fail (boxed_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
if (!value->data[0].v_pointer)
*boxed_p = NULL;
diff --git a/gobject/genums.c b/gobject/genums.c
index f78370053..7fb2521a2 100644
--- a/gobject/genums.c
+++ b/gobject/genums.c
@@ -167,10 +167,9 @@ value_flags_enum_lcopy_value (const GValue *value,
guint collect_flags)
{
gint *int_p = collect_values[0].v_pointer;
-
- if (!int_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (int_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*int_p = value->data[0].v_long;
return NULL;
diff --git a/gobject/gobject.c b/gobject/gobject.c
index c5b3b83a8..5c4aa60a6 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -4021,9 +4021,8 @@ g_value_object_lcopy_value (const GValue *value,
guint collect_flags)
{
GObject **object_p = collect_values[0].v_pointer;
-
- if (!object_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+
+ g_return_val_if_fail (object_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
if (!value->data[0].v_pointer)
*object_p = NULL;
diff --git a/gobject/gparam.c b/gobject/gparam.c
index 5fd895312..2cd4c692c 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -871,8 +871,7 @@ value_param_lcopy_value (const GValue *value,
{
GParamSpec **param_p = collect_values[0].v_pointer;
- if (!param_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+ g_return_val_if_fail (param_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
if (!value->data[0].v_pointer)
*param_p = NULL;
diff --git a/gobject/gtype.h b/gobject/gtype.h
index 479b405e9..89178411f 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -1178,17 +1178,13 @@ struct _GInterfaceInfo
* array. To deviate from our string example for a moment, and taking
* a look at an exemplary implementation for collect_value() of
* #GObject:
- * |[<!-- language="C" -->
- * if (collect_values[0].v_pointer)
- * {
+ * |[<!-- language="C" -->
* GObject *object = G_OBJECT (collect_values[0].v_pointer);
+ * g_return_val_if_fail (object != NULL,
+ * g_strdup_printf ("Object passed as invalid NULL pointer"));
* // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types
* value->data[0].v_pointer = g_object_ref (object);
* return NULL;
- * }
- * else
- * return g_strdup_printf ("Object passed as invalid NULL pointer");
- * }
* ]|
* The reference count for valid objects is always incremented,
* regardless of @collect_flags. For invalid objects, the example
@@ -1220,8 +1216,8 @@ struct _GInterfaceInfo
* To complete the string example:
* |[<!-- language="C" -->
* gchar **string_p = collect_values[0].v_pointer;
- * if (!string_p)
- * return g_strdup_printf ("string location passed as NULL");
+ * g_return_val_if_fail (string_p != NULL,
+ * g_strdup_printf ("string location passed as NULL"));
* if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
* *string_p = value->data[0].v_pointer;
* else
@@ -1231,8 +1227,8 @@ struct _GInterfaceInfo
* reference-counted types:
* |[<!-- language="C" -->
* GObject **object_p = collect_values[0].v_pointer;
- * if (!object_p)
- * return g_strdup_printf ("object location passed as NULL");
+ * g_return_val_if_fail (object_p != NULL,
+ * g_strdup_printf ("object location passed as NULL"));
* if (!value->data[0].v_pointer)
* *object_p = NULL;
* else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) // always honour
diff --git a/gobject/gvaluetypes.c b/gobject/gvaluetypes.c
index 8052c315e..9eaba43ce 100644
--- a/gobject/gvaluetypes.c
+++ b/gobject/gvaluetypes.c
@@ -55,10 +55,9 @@ value_lcopy_char (const GValue *value,
guint collect_flags)
{
gint8 *int8_p = collect_values[0].v_pointer;
-
- if (!int8_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (int8_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*int8_p = value->data[0].v_int;
return NULL;
@@ -71,10 +70,9 @@ value_lcopy_boolean (const GValue *value,
guint collect_flags)
{
gboolean *bool_p = collect_values[0].v_pointer;
-
- if (!bool_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (bool_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*bool_p = value->data[0].v_int;
return NULL;
@@ -98,10 +96,9 @@ value_lcopy_int (const GValue *value,
guint collect_flags)
{
gint *int_p = collect_values[0].v_pointer;
-
- if (!int_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (int_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*int_p = value->data[0].v_int;
return NULL;
@@ -125,10 +122,9 @@ value_lcopy_long (const GValue *value,
guint collect_flags)
{
glong *long_p = collect_values[0].v_pointer;
-
- if (!long_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (long_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*long_p = value->data[0].v_long;
return NULL;
@@ -165,10 +161,9 @@ value_lcopy_int64 (const GValue *value,
guint collect_flags)
{
gint64 *int64_p = collect_values[0].v_pointer;
-
- if (!int64_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (int64_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*int64_p = value->data[0].v_int64;
return NULL;
@@ -205,10 +200,9 @@ value_lcopy_float (const GValue *value,
guint collect_flags)
{
gfloat *float_p = collect_values[0].v_pointer;
-
- if (!float_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (float_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*float_p = value->data[0].v_float;
return NULL;
@@ -245,10 +239,9 @@ value_lcopy_double (const GValue *value,
guint collect_flags)
{
gdouble *double_p = collect_values[0].v_pointer;
-
- if (!double_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (double_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
*double_p = value->data[0].v_double;
return NULL;
@@ -309,10 +302,9 @@ value_lcopy_string (const GValue *value,
guint collect_flags)
{
gchar **string_p = collect_values[0].v_pointer;
-
- if (!string_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
-
+
+ g_return_val_if_fail (string_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
+
if (!value->data[0].v_pointer)
*string_p = NULL;
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
@@ -361,8 +353,7 @@ value_lcopy_pointer (const GValue *value,
{
gpointer *pointer_p = collect_values[0].v_pointer;
- if (!pointer_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+ g_return_val_if_fail (pointer_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
*pointer_p = value->data[0].v_pointer;
@@ -414,8 +405,7 @@ value_lcopy_variant (const GValue *value,
{
GVariant **variant_p = collect_values[0].v_pointer;
- if (!variant_p)
- return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+ g_return_val_if_fail (variant_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL",
G_VALUE_TYPE_NAME (value)));
if (!value->data[0].v_pointer)
*variant_p = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]