mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
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()
This commit is contained in:
parent
e816e9c86f
commit
898baa07b1
@ -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;
|
||||
|
@ -168,8 +168,7 @@ value_flags_enum_lcopy_value (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -4022,8 +4022,7 @@ g_value_object_lcopy_value (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
@ -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;
|
||||
|
@ -1179,16 +1179,12 @@ struct _GInterfaceInfo
|
||||
* a look at an exemplary implementation for collect_value() of
|
||||
* #GObject:
|
||||
* |[<!-- language="C" -->
|
||||
* if (collect_values[0].v_pointer)
|
||||
* {
|
||||
* 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
|
||||
|
@ -56,8 +56,7 @@ value_lcopy_char (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
@ -72,8 +71,7 @@ value_lcopy_boolean (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
@ -99,8 +97,7 @@ value_lcopy_int (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
@ -126,8 +123,7 @@ value_lcopy_long (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
@ -166,8 +162,7 @@ value_lcopy_int64 (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
@ -206,8 +201,7 @@ value_lcopy_float (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
@ -246,8 +240,7 @@ value_lcopy_double (const GValue *value,
|
||||
{
|
||||
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;
|
||||
|
||||
@ -310,8 +303,7 @@ value_lcopy_string (const GValue *value,
|
||||
{
|
||||
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;
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user