Commit a9d1a493 authored by Benjamin Otte's avatar Benjamin Otte

Fixes for -Wwrite-strings

This changes some APIs in compatible ways:
- Some functions now take "const char *" arguments, not "char *"
- Some structs now have "conts char *" members, not "char *"
The changes may cause warnings when compiling with the right warning
flags. You've been warned.

Also adds -Wwrite-strings as a warning flag in configure.ac.

https://bugzilla.gnome.org/show_bug.cgi?id=611692
parent 22f87a52
......@@ -578,7 +578,7 @@ GST_PKG_DEPS="glib-2.0, gobject-2.0, gmodule-no-export-2.0, gthread-2.0"
AC_SUBST(GST_PKG_DEPS)
dnl define an ERROR_CFLAGS Makefile variable
AG_GST_SET_ERROR_CFLAGS($GST_GIT, [-Wredundant-decls -Wundef])
AG_GST_SET_ERROR_CFLAGS($GST_GIT, [-Wredundant-decls -Wundef -Wwrite-strings])
dnl define correct level for debugging messages
AG_GST_SET_LEVEL_DEFAULT($GST_GIT)
......
......@@ -528,7 +528,7 @@ prepare_for_load_plugin_func (gpointer data, gpointer user_data)
#ifndef GST_DISABLE_OPTION_PARSING
static void
split_and_iterate (const gchar * stringlist, gchar * separator,
split_and_iterate (const gchar * stringlist, const gchar * separator,
GFunc iterator, gpointer user_data)
{
gchar **strings;
......@@ -957,7 +957,7 @@ parse_goption_arg (const gchar * opt,
{
static const struct
{
gchar *opt;
const gchar *opt;
int val;
} options[] = {
{
......
......@@ -128,7 +128,7 @@
#define GST_CAT_DEFAULT GST_CAT_BUFFER_LIST
#define GROUP_START NULL
static const gpointer STOLEN = "";
static gconstpointer STOLEN = "";
/**
* GstBufferList:
......@@ -736,7 +736,7 @@ gst_buffer_list_iterator_steal (GstBufferListIterator * it)
g_assert (it->last_returned->data != GROUP_START);
buffer = it->last_returned->data;
it->last_returned->data = STOLEN;
it->last_returned->data = (gpointer) STOLEN;
return buffer;
}
......
......@@ -136,12 +136,14 @@ debug_dump_get_element_params (GstElement * element)
}
static void
debug_dump_pad (GstPad * pad, gchar * color_name, gchar * element_name,
GstDebugGraphDetails details, FILE * out, const gint indent)
debug_dump_pad (GstPad * pad, const gchar * color_name,
const gchar * element_name, GstDebugGraphDetails details, FILE * out,
const gint indent)
{
GstPadTemplate *pad_templ;
GstPadPresence presence;
gchar *pad_name, *style_name;
gchar *pad_name;
const gchar *style_name;
const gchar *spc = &spaces[MAX (sizeof (spaces) - (1 + indent * 2), 0)];
pad_name = debug_dump_make_object_name (GST_OBJECT (pad));
......@@ -191,7 +193,7 @@ debug_dump_element_pad (GstPad * pad, GstElement * element,
GstPadDirection dir;
gchar *element_name;
gchar *target_element_name;
gchar *color_name;
const gchar *color_name;
dir = gst_pad_get_direction (pad);
element_name = debug_dump_make_object_name (GST_OBJECT (element));
......@@ -206,14 +208,13 @@ debug_dump_element_pad (GstPad * pad, GstElement * element,
target_element_name =
debug_dump_make_object_name (GST_OBJECT (target_element));
} else {
target_element_name = "";
target_element_name = g_strdup ("");
}
debug_dump_pad (target_pad, color_name, target_element_name, details,
out, indent);
if (target_element) {
g_free (target_element_name);
g_free (target_element_name);
if (target_element)
gst_object_unref (target_element);
}
gst_object_unref (target_pad);
}
gst_object_unref (tmp_pad);
......@@ -265,8 +266,7 @@ string_append_field (GQuark field, const GValue * value, gpointer ptr)
}
static gchar *
debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details,
gboolean * need_free)
debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details)
{
gchar *media = NULL;
......@@ -274,7 +274,6 @@ debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details,
if (gst_caps_is_any (caps) || gst_caps_is_empty (caps)) {
media = gst_caps_to_string (caps);
*need_free = TRUE;
} else {
GString *str = NULL;
......@@ -297,16 +296,14 @@ debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details,
}
media = g_string_free (str, FALSE);
*need_free = TRUE;
}
} else {
if (GST_CAPS_IS_SIMPLE (caps))
media =
(gchar *) gst_structure_get_name (gst_caps_get_structure (caps, 0));
g_strdup (gst_structure_get_name (gst_caps_get_structure (caps, 0)));
else
media = "*";
*need_free = FALSE;
media = g_strdup ("*");
}
return media;
}
......@@ -318,8 +315,6 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
GstElement *peer_element, *target_element;
GstPad *peer_pad, *target_pad, *tmp_pad;
GstCaps *caps, *peer_caps;
gboolean free_caps, free_peer_caps;
gboolean free_media, free_media_src, free_media_sink;
gchar *media = NULL;
gchar *media_src = NULL, *media_sink = NULL;
gchar *pad_name, *element_name;
......@@ -328,69 +323,47 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
const gchar *spc = &spaces[MAX (sizeof (spaces) - (1 + indent * 2), 0)];
if ((peer_pad = gst_pad_get_peer (pad))) {
free_media = free_media_src = free_media_sink = FALSE;
if ((details & GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE) ||
(details & GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS)
) {
if ((caps = gst_pad_get_negotiated_caps (pad))) {
free_caps = TRUE;
} else {
free_caps = FALSE;
if (!(caps = (GstCaps *)
gst_pad_get_pad_template_caps (pad))) {
/* this should not happen */
media = "?";
}
}
if ((peer_caps = gst_pad_get_negotiated_caps (peer_pad))) {
free_peer_caps = TRUE;
} else {
free_peer_caps = FALSE;
peer_caps = (GstCaps *) gst_pad_get_pad_template_caps (peer_pad);
}
if (caps) {
media = debug_dump_describe_caps (caps, details, &free_media);
/* check if peer caps are different */
if (peer_caps && !gst_caps_is_equal (caps, peer_caps)) {
gchar *tmp;
gboolean free_tmp;
tmp = debug_dump_describe_caps (peer_caps, details, &free_tmp);
if (gst_pad_get_direction (pad) == GST_PAD_SRC) {
media_src = media;
free_media_src = free_media;
media_sink = tmp;
free_media_sink = free_tmp;
} else {
media_src = tmp;
free_media_src = free_tmp;
media_sink = media;
free_media_sink = free_media;
}
media = NULL;
free_media = FALSE;
}
if (free_caps) {
gst_caps_unref (caps);
caps = gst_pad_get_negotiated_caps (pad);
if (!caps)
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
peer_caps = gst_pad_get_negotiated_caps (peer_pad);
if (!peer_caps)
peer_caps = gst_caps_copy (gst_pad_get_pad_template_caps (peer_pad));
media = debug_dump_describe_caps (caps, details);
/* check if peer caps are different */
if (peer_caps && !gst_caps_is_equal (caps, peer_caps)) {
gchar *tmp;
tmp = debug_dump_describe_caps (peer_caps, details);
if (gst_pad_get_direction (pad) == GST_PAD_SRC) {
media_src = media;
media_sink = tmp;
} else {
media_src = tmp;
media_sink = media;
}
media = NULL;
}
if (free_peer_caps && peer_caps) {
gst_caps_unref (peer_caps);
}
gst_caps_unref (peer_caps);
gst_caps_unref (caps);
}
pad_name = debug_dump_make_object_name (GST_OBJECT (pad));
if (element) {
element_name = debug_dump_make_object_name (GST_OBJECT (element));
} else {
element_name = "";
element_name = g_strdup ("");
}
peer_pad_name = debug_dump_make_object_name (GST_OBJECT (peer_pad));
if ((peer_element = gst_pad_get_parent_element (peer_pad))) {
peer_element_name =
debug_dump_make_object_name (GST_OBJECT (peer_element));
} else {
peer_element_name = "";
peer_element_name = g_strdup ("");
}
if (GST_IS_GHOST_PAD (pad)) {
......@@ -402,17 +375,16 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
target_element_name =
debug_dump_make_object_name (GST_OBJECT (target_element));
} else {
target_element_name = "";
target_element_name = g_strdup ("");
}
/* src ghostpad relationship */
fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
target_element_name, target_pad_name, element_name, pad_name);
g_free (target_pad_name);
if (target_element) {
g_free (target_element_name);
g_free (target_element_name);
if (target_element)
gst_object_unref (target_element);
}
gst_object_unref (target_pad);
}
gst_object_unref (tmp_pad);
......@@ -427,7 +399,7 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
target_element_name =
debug_dump_make_object_name (GST_OBJECT (target_element));
} else {
target_element_name = "";
target_element_name = g_strdup ("");
}
/* sink ghostpad relationship */
fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
......@@ -442,10 +414,9 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
debug_dump_element_pad_link (target_pad, target_element, details, out,
indent);
g_free (target_pad_name);
if (target_element) {
g_free (target_element_name);
g_free (target_element_name);
if (target_element)
gst_object_unref (target_element);
}
gst_object_unref (target_pad);
}
gst_object_unref (tmp_pad);
......@@ -456,9 +427,7 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
if (media) {
fprintf (out, "%s%s_%s -> %s_%s [label=\"%s\"]\n", spc,
element_name, pad_name, peer_element_name, peer_pad_name, media);
if (free_media) {
g_free (media);
}
g_free (media);
} else if (media_src && media_sink) {
/* dot has some issues with placement of head and taillabels,
* we need an empty label to make space */
......@@ -467,24 +436,19 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
"headlabel=\"%s\", taillabel=\"%s\"]\n",
spc, element_name, pad_name, peer_element_name, peer_pad_name,
media_src, media_sink);
if (free_media_src)
g_free (media_src);
if (free_media_sink)
g_free (media_sink);
g_free (media_src);
g_free (media_sink);
} else {
fprintf (out, "%s%s_%s -> %s_%s\n", spc,
element_name, pad_name, peer_element_name, peer_pad_name);
}
g_free (pad_name);
if (element) {
g_free (element_name);
}
g_free (element_name);
g_free (peer_pad_name);
if (peer_element) {
g_free (peer_element_name);
g_free (peer_element_name);
if (peer_element)
gst_object_unref (peer_element);
}
gst_object_unref (peer_pad);
}
}
......
......@@ -65,7 +65,8 @@ _gst_format_initialize (void)
while (standards->nick) {
standards->quark = g_quark_from_static_string (standards->nick);
g_hash_table_insert (_nick_to_format, standards->nick, standards);
g_hash_table_insert (_nick_to_format, (gpointer) standards->nick,
standards);
g_hash_table_insert (_format_to_nick, GINT_TO_POINTER (standards->value),
standards);
......@@ -157,7 +158,7 @@ gst_format_register (const gchar * nick, const gchar * description)
format->description = g_strdup (description);
format->quark = g_quark_from_static_string (format->nick);
g_hash_table_insert (_nick_to_format, format->nick, format);
g_hash_table_insert (_nick_to_format, (gpointer) format->nick, format);
g_hash_table_insert (_format_to_nick, GINT_TO_POINTER (format->value),
format);
_gst_formats = g_list_append (_gst_formats, format);
......
......@@ -86,10 +86,10 @@ typedef struct _GstFormatDefinition GstFormatDefinition;
*/
struct _GstFormatDefinition
{
GstFormat value;
gchar *nick;
gchar *description;
GQuark quark;
GstFormat value;
const gchar *nick;
const gchar *description;
GQuark quark;
};
const gchar* gst_format_get_name (GstFormat format);
......
......@@ -866,7 +866,6 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
gint pid;
GstClockTime elapsed;
gchar *obj = NULL;
gboolean free_obj = TRUE;
gboolean is_colored;
if (level > gst_debug_category_get_threshold (category))
......@@ -881,15 +880,14 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
if (object) {
obj = gst_debug_print_object (object);
} else {
obj = "\0";
free_obj = FALSE;
obj = g_strdup ("");
}
if (is_colored) {
#ifndef G_OS_WIN32
/* colors, non-windows */
gchar *color = NULL;
gchar *clear;
const gchar *clear;
gchar pidcolor[10];
const gchar *levelcolor;
......@@ -947,8 +945,7 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
#undef PRINT_FMT
}
if (free_obj)
g_free (obj);
g_free (obj);
}
/**
......
......@@ -76,9 +76,9 @@ gst_mini_object_get_type (void)
gst_value_mini_object_free,
gst_value_mini_object_copy,
gst_value_mini_object_peek_pointer,
"p",
(char *) "p",
gst_value_mini_object_collect,
"p",
(char *) "p",
gst_value_mini_object_lcopy
};
GTypeInfo mini_object_info = {
......
......@@ -501,7 +501,8 @@ gst_object_dispatch_properties_changed (GObject * object,
{
GstObject *gst_object, *parent, *old_parent;
guint i;
gchar *name, *debug_name;
gchar *name;
const gchar *debug_name;
/* do the standard dispatching */
parent_class->dispatch_properties_changed (object, n_pspecs, pspecs);
......@@ -1075,7 +1076,7 @@ gst_object_get_path_string (GstObject * object)
gchar *prevpath, *path;
const gchar *typename;
gchar *component;
gchar *separator;
const gchar *separator;
/* ref object before adding to list */
gst_object_ref (object);
......
......@@ -257,7 +257,7 @@ struct _GstObject {
struct _GstObjectClass {
GObjectClass parent_class;
gchar *path_string_separator;
const gchar *path_string_separator;
GObject *signal_object;
/* FIXME-0.11: remove this, plus the above GST_CLASS_*_LOCK macros */
......
......@@ -105,7 +105,6 @@ static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
const GstPluginDesc * desc, gpointer user_data);
static void gst_plugin_desc_copy (GstPluginDesc * dest,
const GstPluginDesc * src);
static void gst_plugin_desc_free (GstPluginDesc * desc);
static void gst_plugin_ext_dep_free (GstPluginDep * dep);
......@@ -133,7 +132,6 @@ gst_plugin_finalize (GObject * object)
}
g_free (plugin->filename);
g_free (plugin->basename);
gst_plugin_desc_free (&plugin->desc);
g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
g_list_free (plugin->priv->deps);
......@@ -224,7 +222,7 @@ _gst_plugin_register_static (GstPluginDesc * desc)
*/
gboolean
gst_plugin_register_static (gint major_version, gint minor_version,
const gchar * name, gchar * description, GstPluginInitFunc init_func,
const gchar * name, const gchar * description, GstPluginInitFunc init_func,
const gchar * version, const gchar * license, const gchar * source,
const gchar * package, const gchar * origin)
{
......@@ -291,7 +289,7 @@ gst_plugin_register_static (gint major_version, gint minor_version,
*/
gboolean
gst_plugin_register_static_full (gint major_version, gint minor_version,
const gchar * name, gchar * description,
const gchar * name, const gchar * description,
GstPluginInitFullFunc init_full_func, const gchar * version,
const gchar * license, const gchar * source, const gchar * package,
const gchar * origin, gpointer user_data)
......@@ -623,9 +621,6 @@ gst_plugin_load_file (const gchar * filename, GError ** error)
CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
} else {
/* this is overwritten by gst_plugin_register_func() */
g_free (plugin->desc.description);
}
GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
......@@ -680,8 +675,7 @@ gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
dest->major_version = src->major_version;
dest->minor_version = src->minor_version;
dest->name = g_intern_string (src->name);
/* maybe intern the description too, just for convenience? */
dest->description = g_strdup (src->description);
dest->description = g_intern_string (src->description);
dest->plugin_init = src->plugin_init;
dest->version = g_intern_string (src->version);
dest->license = g_intern_string (src->license);
......@@ -690,14 +684,6 @@ gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
dest->origin = g_intern_string (src->origin);
}
/* unused */
static void
gst_plugin_desc_free (GstPluginDesc * desc)
{
g_free (desc->description);
memset (desc, 0, sizeof (GstPluginDesc));
}
/**
* gst_plugin_get_name:
* @plugin: plugin to get the name of
......
......@@ -160,7 +160,7 @@ struct _GstPluginDesc {
gint major_version;
gint minor_version;
const gchar *name;
gchar *description;
const gchar *description;
GstPluginInitFunc plugin_init;
const gchar *version;
const gchar *license;
......@@ -329,7 +329,7 @@ void _gst_plugin_register_static (GstPluginDesc *desc);
gboolean gst_plugin_register_static (gint major_version,
gint minor_version,
const gchar *name,
gchar *description,
const gchar *description,
GstPluginInitFunc init_func,
const gchar *version,
const gchar *license,
......@@ -340,7 +340,7 @@ gboolean gst_plugin_register_static (gint major_version,
gboolean gst_plugin_register_static_full (gint major_version,
gint minor_version,
const gchar *name,
gchar *description,
const gchar *description,
GstPluginInitFullFunc init_full_func,
const gchar *version,
const gchar *license,
......
......@@ -348,7 +348,7 @@ plugin_loader_create_blacklist_plugin (GstPluginLoader * l,
static gboolean
gst_plugin_loader_try_helper (GstPluginLoader * loader, gchar * location)
{
char *argv[] = { location, "-l", NULL };
char *argv[] = { location, (char *) "-l", NULL };
GST_LOG ("Trying to spawn gst-plugin-scanner helper at %s", location);
if (!g_spawn_async_with_pipes (NULL, argv, NULL,
......
......@@ -114,7 +114,7 @@ _gst_query_initialize (void)
while (standards->nick) {
standards->quark = g_quark_from_static_string (standards->nick);
g_hash_table_insert (_nick_to_query, standards->nick, standards);
g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
g_hash_table_insert (_query_type_to_nick,
GINT_TO_POINTER (standards->value), standards);
......@@ -245,7 +245,7 @@ gst_query_type_register (const gchar * nick, const gchar * description)
query->quark = g_quark_from_static_string (query->nick);
g_static_mutex_lock (&mutex);
g_hash_table_insert (_nick_to_query, query->nick, query);
g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
query);
_gst_queries = g_list_append (_gst_queries, query);
......
......@@ -104,8 +104,8 @@ typedef struct _GstQueryClass GstQueryClass;
struct _GstQueryTypeDefinition
{
GstQueryType value;
gchar *nick;
gchar *description;
const gchar *nick;
const gchar *description;
GQuark quark;
};
......
......@@ -1488,7 +1488,7 @@ gst_structure_get_fraction (const GstStructure * structure,
typedef struct _GstStructureAbbreviation
{
gchar *type_name;
const gchar *type_name;
GType type;
}
GstStructureAbbreviation;
......
......@@ -111,7 +111,7 @@ gint _gst_trace_on = 1;
* Returns: a new #GstTrace.
*/
GstTrace *
gst_trace_new (gchar * filename, gint size)
gst_trace_new (const gchar * filename, gint size)
{
GstTrace *trace = g_malloc (sizeof (GstTrace));
......
......@@ -88,7 +88,7 @@ struct _GstTraceEntry {
gchar message[112];
};
GstTrace* gst_trace_new (gchar *filename, gint size);
GstTrace* gst_trace_new (const gchar *filename, gint size);
void gst_trace_destroy (GstTrace *trace);
void gst_trace_flush (GstTrace *trace);
......
......@@ -3986,9 +3986,9 @@ static const GTypeValueTable _gst_fourcc_value_table = {
NULL,
gst_value_copy_fourcc,
NULL,
"i",
(char *) "i",
gst_value_collect_fourcc,
"p",
(char *) "p",
gst_value_lcopy_fourcc
};
......@@ -3999,9 +3999,9 @@ static const GTypeValueTable _gst_int_range_value_table = {
NULL,
gst_value_copy_int_range,
NULL,
"ii",
(char *) "ii",
gst_value_collect_int_range,
"pp",
(char *) "pp",
gst_value_lcopy_int_range
};
......@@ -4012,9 +4012,9 @@ static const GTypeValueTable _gst_double_range_value_table = {
NULL,
gst_value_copy_double_range,
NULL,