gst/: Don't put functional code in g_return_if_fail() or g_return_val_if_fail() statements, otherwise things will bre...

Original commit message from CVS:
* gst/base/gstbasetransform.c: (gst_base_transform_transform_size):
* gst/gstutils.c: (gst_util_set_value_from_string),
(gst_util_set_object_arg):
Don't put functional code in g_return_if_fail() or
g_return_val_if_fail() statements, otherwise things will
break when G_DISABLE_CHECKS is defined during compilation.
This commit is contained in:
Tim-Philipp Müller 2005-09-21 11:52:04 +00:00
parent d13c1a7b10
commit 9894c90109
4 changed files with 63 additions and 26 deletions

View file

@ -1,3 +1,12 @@
2005-09-21 Tim-Philipp Müller <tim at centricular dot net>
* gst/base/gstbasetransform.c: (gst_base_transform_transform_size):
* gst/gstutils.c: (gst_util_set_value_from_string),
(gst_util_set_object_arg):
Don't put functional code in g_return_if_fail() or
g_return_val_if_fail() statements, otherwise things will
break when G_DISABLE_CHECKS is defined during compilation.
2005-09-21 Stefan Kost <ensonic@users.sf.net> 2005-09-21 Stefan Kost <ensonic@users.sf.net>
* docs/gst/tmpl/.cvsignore: * docs/gst/tmpl/.cvsignore:

View file

@ -430,8 +430,11 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
ret = klass->transform_size (trans, direction, caps, size, othercaps, ret = klass->transform_size (trans, direction, caps, size, othercaps,
othersize); othersize);
} else { } else {
g_return_val_if_fail (gst_base_transform_get_unit_size (trans, caps, gboolean got_in_unit_size, got_out_unit_size;
&inunitsize), FALSE);
got_in_unit_size = gst_base_transform_get_unit_size (trans, caps,
&inunitsize);
g_return_val_if_fail (got_in_unit_size == TRUE, FALSE);
GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size, GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size,
inunitsize); inunitsize);
g_return_val_if_fail (inunitsize != 0, FALSE); g_return_val_if_fail (inunitsize != 0, FALSE);
@ -441,8 +444,9 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
} }
units = size / inunitsize; units = size / inunitsize;
g_return_val_if_fail (gst_base_transform_get_unit_size (trans, othercaps, got_out_unit_size = gst_base_transform_get_unit_size (trans, othercaps,
&outunitsize), FALSE); &outunitsize);
g_return_val_if_fail (got_out_unit_size == TRUE, FALSE);
*othersize = units * outunitsize; *othersize = units * outunitsize;
GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize); GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);

View file

@ -87,6 +87,7 @@ gst_util_dump_mem (const guchar * mem, guint size)
void void
gst_util_set_value_from_string (GValue * value, const gchar * value_str) gst_util_set_value_from_string (GValue * value, const gchar * value_str)
{ {
gint sscanf_ret;
g_return_if_fail (value != NULL); g_return_if_fail (value != NULL);
g_return_if_fail (value_str != NULL); g_return_if_fail (value_str != NULL);
@ -102,35 +103,39 @@ gst_util_set_value_from_string (GValue * value, const gchar * value_str)
case G_TYPE_INT:{ case G_TYPE_INT:{
gint i; gint i;
g_return_if_fail (sscanf (value_str, "%d", &i) == 1); sscanf_ret = sscanf (value_str, "%d", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_int (value, i); g_value_set_int (value, i);
break; break;
} }
case G_TYPE_UINT:{ case G_TYPE_UINT:{
guint i; guint i;
g_return_if_fail (sscanf (value_str, "%u", &i) == 1); sscanf_ret = sscanf (value_str, "%u", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_uint (value, i); g_value_set_uint (value, i);
break; break;
} }
case G_TYPE_LONG:{ case G_TYPE_LONG:{
glong i; glong i;
g_return_if_fail (sscanf (value_str, "%ld", &i) == 1); sscanf_ret = sscanf (value_str, "%ld", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_long (value, i); g_value_set_long (value, i);
break; break;
} }
case G_TYPE_ULONG:{ case G_TYPE_ULONG:{
gulong i; gulong i;
g_return_if_fail (sscanf (value_str, "%lu", &i) == 1); sscanf_ret = sscanf (value_str, "%lu", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_ulong (value, i); g_value_set_ulong (value, i);
break; break;
} }
case G_TYPE_BOOLEAN:{ case G_TYPE_BOOLEAN:{
gboolean i = FALSE; gboolean i = FALSE;
if (!strncmp ("true", value_str, 4)) if (!g_ascii_strncasecmp ("true", value_str, 4))
i = TRUE; i = TRUE;
g_value_set_boolean (value, i); g_value_set_boolean (value, i);
break; break;
@ -138,28 +143,32 @@ gst_util_set_value_from_string (GValue * value, const gchar * value_str)
case G_TYPE_CHAR:{ case G_TYPE_CHAR:{
gchar i; gchar i;
g_return_if_fail (sscanf (value_str, "%c", &i) == 1); sscanf_ret = sscanf (value_str, "%c", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_char (value, i); g_value_set_char (value, i);
break; break;
} }
case G_TYPE_UCHAR:{ case G_TYPE_UCHAR:{
guchar i; guchar i;
g_return_if_fail (sscanf (value_str, "%c", &i) == 1); sscanf_ret = sscanf (value_str, "%c", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_uchar (value, i); g_value_set_uchar (value, i);
break; break;
} }
case G_TYPE_FLOAT:{ case G_TYPE_FLOAT:{
gfloat i; gfloat i;
g_return_if_fail (sscanf (value_str, "%f", &i) == 1); sscanf_ret = sscanf (value_str, "%f", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_float (value, i); g_value_set_float (value, i);
break; break;
} }
case G_TYPE_DOUBLE:{ case G_TYPE_DOUBLE:{
gfloat i; gfloat i;
g_return_if_fail (sscanf (value_str, "%g", &i) == 1); sscanf_ret = sscanf (value_str, "%g", &i);
g_return_if_fail (sscanf_ret == 1);
g_value_set_double (value, (gdouble) i); g_value_set_double (value, (gdouble) i);
break; break;
} }
@ -181,6 +190,8 @@ void
gst_util_set_object_arg (GObject * object, const gchar * name, gst_util_set_object_arg (GObject * object, const gchar * name,
const gchar * value) const gchar * value)
{ {
gboolean sscanf_ret;
if (name && value) { if (name && value) {
GParamSpec *paramspec; GParamSpec *paramspec;
@ -203,28 +214,32 @@ gst_util_set_object_arg (GObject * object, const gchar * name,
case G_TYPE_INT:{ case G_TYPE_INT:{
gint i; gint i;
g_return_if_fail (sscanf (value, "%d", &i) == 1); sscanf_ret = sscanf (value, "%d", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
break; break;
} }
case G_TYPE_UINT:{ case G_TYPE_UINT:{
guint i; guint i;
g_return_if_fail (sscanf (value, "%u", &i) == 1); sscanf_ret = sscanf (value, "%u", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
break; break;
} }
case G_TYPE_LONG:{ case G_TYPE_LONG:{
glong i; glong i;
g_return_if_fail (sscanf (value, "%ld", &i) == 1); sscanf_ret = sscanf (value, "%ld", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
break; break;
} }
case G_TYPE_ULONG:{ case G_TYPE_ULONG:{
gulong i; gulong i;
g_return_if_fail (sscanf (value, "%lu", &i) == 1); sscanf_ret = sscanf (value, "%lu", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
break; break;
} }
@ -239,28 +254,32 @@ gst_util_set_object_arg (GObject * object, const gchar * name,
case G_TYPE_CHAR:{ case G_TYPE_CHAR:{
gchar i; gchar i;
g_return_if_fail (sscanf (value, "%c", &i) == 1); sscanf_ret = sscanf (value, "%c", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
break; break;
} }
case G_TYPE_UCHAR:{ case G_TYPE_UCHAR:{
guchar i; guchar i;
g_return_if_fail (sscanf (value, "%c", &i) == 1); sscanf_ret = sscanf (value, "%c", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
break; break;
} }
case G_TYPE_FLOAT:{ case G_TYPE_FLOAT:{
gfloat i; gfloat i;
g_return_if_fail (sscanf (value, "%f", &i) == 1); sscanf_ret = sscanf (value, "%f", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
break; break;
} }
case G_TYPE_DOUBLE:{ case G_TYPE_DOUBLE:{
gfloat i; gfloat i;
g_return_if_fail (sscanf (value, "%g", &i) == 1); sscanf_ret = sscanf (value, "%g", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, (gdouble) i, NULL); g_object_set (G_OBJECT (object), name, (gdouble) i, NULL);
break; break;
} }
@ -268,7 +287,8 @@ gst_util_set_object_arg (GObject * object, const gchar * name,
if (G_IS_PARAM_SPEC_ENUM (paramspec)) { if (G_IS_PARAM_SPEC_ENUM (paramspec)) {
gint i; gint i;
g_return_if_fail (sscanf (value, "%d", &i) == 1); sscanf_ret = sscanf (value, "%d", &i);
g_return_if_fail (sscanf_ret == 1);
g_object_set (G_OBJECT (object), name, i, NULL); g_object_set (G_OBJECT (object), name, i, NULL);
} else if (paramspec->value_type == GST_TYPE_URI) { } else if (paramspec->value_type == GST_TYPE_URI) {
g_object_set (G_OBJECT (object), name, value, NULL); g_object_set (G_OBJECT (object), name, value, NULL);

View file

@ -430,8 +430,11 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
ret = klass->transform_size (trans, direction, caps, size, othercaps, ret = klass->transform_size (trans, direction, caps, size, othercaps,
othersize); othersize);
} else { } else {
g_return_val_if_fail (gst_base_transform_get_unit_size (trans, caps, gboolean got_in_unit_size, got_out_unit_size;
&inunitsize), FALSE);
got_in_unit_size = gst_base_transform_get_unit_size (trans, caps,
&inunitsize);
g_return_val_if_fail (got_in_unit_size == TRUE, FALSE);
GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size, GST_DEBUG_OBJECT (trans, "input size %d, input unit size %d", size,
inunitsize); inunitsize);
g_return_val_if_fail (inunitsize != 0, FALSE); g_return_val_if_fail (inunitsize != 0, FALSE);
@ -441,8 +444,9 @@ gst_base_transform_transform_size (GstBaseTransform * trans,
} }
units = size / inunitsize; units = size / inunitsize;
g_return_val_if_fail (gst_base_transform_get_unit_size (trans, othercaps, got_out_unit_size = gst_base_transform_get_unit_size (trans, othercaps,
&outunitsize), FALSE); &outunitsize);
g_return_val_if_fail (got_out_unit_size == TRUE, FALSE);
*othersize = units * outunitsize; *othersize = units * outunitsize;
GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize); GST_DEBUG_OBJECT (trans, "transformed size to %d", *othersize);