gst/parse/grammar.y (__gst_parse_chain_free): Don't do null checking here, do it before calling the function.

Original commit message from CVS:
* gst/parse/grammar.y (__gst_parse_chain_free): Don't do null
checking here, do it before calling the function.
Clean up, use for loops instead of while loops while iterating
over lists.
This commit is contained in:
Johan Dahlin 2004-04-19 17:40:24 +00:00
parent 66d065963f
commit 272eccde22
2 changed files with 29 additions and 48 deletions

View file

@ -6,6 +6,11 @@
2004-04-19 Johan Dahlin <johan@gnome.org> 2004-04-19 Johan Dahlin <johan@gnome.org>
* gst/parse/grammar.y (__gst_parse_chain_free): Don't do null
checking here, do it before calling the function.
Clean up, use for loops instead of while loops while iterating
over lists.
* gst/autoplug/gstspider.c (gst_spider_request_new_pad): Fix typo * gst/autoplug/gstspider.c (gst_spider_request_new_pad): Fix typo
in debug message. in debug message.
(gst_spider_create_and_plug): Improve debug message. (gst_spider_create_and_plug): Improve debug message.

View file

@ -76,12 +76,10 @@ __gst_parse_chain_new ()
void void
__gst_parse_chain_free (chain_t *data) __gst_parse_chain_free (chain_t *data)
{ {
if (data) { /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
/* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */ g_free (data);
g_free (data); g_return_if_fail (__chains > 0);
g_return_if_fail (__chains > 0); __chains--;
__chains--;
}
} }
#endif /* __GST_PARSE_TRACE */ #endif /* __GST_PARSE_TRACE */
@ -177,20 +175,14 @@ typedef struct {
g_slist_free (assign); \ g_slist_free (assign); \
res = chain; \ res = chain; \
} else { \ } else { \
walk = chain->elements; \ for (walk = chain->elements; walk; walk = walk->next ) \
while (walk) { \
gst_bin_add (bin, GST_ELEMENT (walk->data)); \ gst_bin_add (bin, GST_ELEMENT (walk->data)); \
walk = walk->next; \
} \
g_slist_free (chain->elements); \ g_slist_free (chain->elements); \
chain->elements = g_slist_prepend (NULL, bin); \ chain->elements = g_slist_prepend (NULL, bin); \
res = chain; \ res = chain; \
/* set the properties now */ \ /* set the properties now */ \
walk = assign; \ for (walk = assign; walk; walk = walk->next) \
while (walk) { \
gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \ gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
walk = g_slist_next (walk); \
} \
g_slist_free (assign); \ g_slist_free (assign); \
} \ } \
}G_STMT_END }G_STMT_END
@ -360,9 +352,8 @@ gst_parse_element_lock (GstElement *element, gboolean lock)
if (gst_element_is_locked_state (element) == lock) if (gst_element_is_locked_state (element) == lock)
return; return;
/* check if we have an unlocked peer */ /* check if we have an unlocked peer */
while (walk) { for (; walk; walk = walk->next) {
pad = (GstPad *) GST_PAD_REALIZE (walk->data); pad = (GstPad *) GST_PAD_REALIZE (walk->data);
walk = walk->next;
if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) && if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
!gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) { !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
unlocked_peer = TRUE; unlocked_peer = TRUE;
@ -388,9 +379,8 @@ gst_parse_element_lock (GstElement *element, gboolean lock)
/* check if there are other pads to (un)lock */ /* check if there are other pads to (un)lock */
walk = (GList *) gst_element_get_pad_list (element); walk = (GList *) gst_element_get_pad_list (element);
while (walk) { for (; walk; walk = walk->next) {
pad = (GstPad *) GST_PAD_REALIZE (walk->data); pad = (GstPad *) GST_PAD_REALIZE (walk->data);
walk = walk->next;
if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) { if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad))); GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
if (gst_element_is_locked_state (next) != lock) if (gst_element_is_locked_state (next) != lock)
@ -428,7 +418,7 @@ gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
{ {
GList *templs = gst_element_get_pad_template_list (src); GList *templs = gst_element_get_pad_template_list (src);
while (templs) { for (; templs; templs = templs->next) {
GstPadTemplate *templ = (GstPadTemplate *) templs->data; GstPadTemplate *templ = (GstPadTemplate *) templs->data;
if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES)) if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
{ {
@ -451,7 +441,6 @@ gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
G_CALLBACK (gst_parse_found_pad), data); G_CALLBACK (gst_parse_found_pad), data);
return TRUE; return TRUE;
} }
templs = g_list_next (templs);
} }
return FALSE; return FALSE;
} }
@ -674,7 +663,8 @@ chain: element { $$ = gst_parse_chain_new ();
$1->last = $2->last; $1->last = $2->last;
$1->back = $2->back; $1->back = $2->back;
$1->elements = g_slist_concat ($1->elements, $2->elements); $1->elements = g_slist_concat ($1->elements, $2->elements);
gst_parse_chain_free ($2); if ($2)
gst_parse_chain_free ($2);
$$ = $1; $$ = $1;
} }
| chain linklist { GSList *walk; | chain linklist { GSList *walk;
@ -686,18 +676,16 @@ chain: element { $$ = gst_parse_chain_new ();
((link_t *) $2->data)->src = $1->last; ((link_t *) $2->data)->src = $1->last;
} }
} }
walk = $2; for (walk = $2; walk; walk = walk->next) {
while (walk) {
link_t *link = (link_t *) walk->data; link_t *link = (link_t *) walk->data;
walk = walk->next; if (!link->sink_name && walk->next) {
if (!link->sink_name && walk) {
ERROR (GST_PARSE_ERROR_LINK, _("link without sink element")); ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
gst_parse_free_link (link); gst_parse_free_link (link);
} else if (!link->src_name && !link->src) { } else if (!link->src_name && !link->src) {
ERROR (GST_PARSE_ERROR_LINK, _("link without source element")); ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
gst_parse_free_link (link); gst_parse_free_link (link);
} else { } else {
if (walk) { if (walk->next) {
((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link); ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
} else { } else {
$1->back = link; $1->back = link;
@ -850,26 +838,23 @@ _gst_parse_launch (const gchar *str, GError **error)
g_slist_free (((chain_t *) g.chain)->elements); g_slist_free (((chain_t *) g.chain)->elements);
if (GST_IS_BIN (ret)) if (GST_IS_BIN (ret))
bin = GST_BIN (ret); bin = GST_BIN (ret);
gst_parse_chain_free (g.chain);
} else { } else {
/* put all elements in our bin */ /* put all elements in our bin */
bin = GST_BIN (gst_element_factory_make ("pipeline", NULL)); bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
g_assert (bin); g_assert (bin);
walk = g.chain->elements;
while (walk) { for (walk = g.chain->elements; walk; walk = walk->next)
gst_bin_add (bin, GST_ELEMENT (walk->data)); gst_bin_add (bin, GST_ELEMENT (walk->data));
walk = g_slist_next (walk);
}
g_slist_free (g.chain->elements); g_slist_free (g.chain->elements);
ret = GST_ELEMENT (bin); ret = GST_ELEMENT (bin);
gst_parse_chain_free (g.chain);
} }
gst_parse_chain_free (g.chain);
/* remove links */ /* remove links */
walk = g.links; for (walk = g.links; walk; walk = walk->next) {
while (walk) {
link_t *l = (link_t *) walk->data; link_t *l = (link_t *) walk->data;
GstElement *sink;
walk = g_slist_next (walk);
if (!l->src) { if (!l->src) {
if (l->src_name) { if (l->src_name) {
if (bin) { if (bin) {
@ -898,7 +883,6 @@ _gst_parse_launch (const gchar *str, GError **error)
continue; continue;
} }
} }
sink = l->sink;
gst_parse_perform_link (l, &g); gst_parse_perform_link (l, &g);
} }
g_slist_free (g.links); g_slist_free (g.links);
@ -917,20 +901,12 @@ error1:
g_free (dstr); g_free (dstr);
if (g.chain) { if (g.chain) {
walk = g.chain->elements; g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
while (walk) {
gst_object_unref (GST_OBJECT (walk->data));
walk = walk->next;
}
g_slist_free (g.chain->elements); g_slist_free (g.chain->elements);
gst_parse_chain_free (g.chain);
} }
gst_parse_chain_free (g.chain);
g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
walk = g.links;
while (walk) {
gst_parse_free_link ((link_t *) walk->data);
walk = walk->next;
}
g_slist_free (g.links); g_slist_free (g.links);
g_assert (*error); g_assert (*error);