2 #include <glib-object.h>
8 #include "../gst_private.h"
9 #include "../gst-i18n-lib.h"
11 #include "../gstconfig.h"
12 #include "../gstparse.h"
13 #include "../gstinfo.h"
14 #include "../gsterror.h"
15 #include "../gsturi.h"
16 #include "../gstutils.h"
17 #include "../gstvalue.h"
18 #include "../gstchildproxy.h"
21 /* All error messages in this file are user-visible and need to be translated.
22 * Don't start the message with a capital, and don't end them with a period,
23 * as they will be presented inside a sentence/error.
26 #define YYERROR_VERBOSE 1
27 #define YYPARSE_PARAM graph
29 #ifdef __GST_PARSE_TRACE
30 static guint __strings;
32 static guint __chains;
34 __gst_parse_strdup (gchar *org)
39 /* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */
43 __gst_parse_strfree (gchar *str)
46 /* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */
48 g_return_if_fail (__strings > 0);
52 link_t *__gst_parse_link_new ()
56 ret = g_new0 (link_t, 1);
57 /* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */
61 __gst_parse_link_free (link_t *data)
64 /* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */
66 g_return_if_fail (__links > 0);
71 __gst_parse_chain_new ()
75 ret = g_new0 (chain_t, 1);
76 /* g_print ("ALLOCATED CHAIN (%3u): %p\n", __chains, ret); */
80 __gst_parse_chain_free (chain_t *data)
82 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
84 g_return_if_fail (__chains > 0);
88 #endif /* __GST_PARSE_TRACE */
96 /* FIXME: need to connect to "disposed" signal to clean up,
97 * but there is no such signal */
100 /*** define SET_ERROR and ERROR macros/functions */
102 #ifdef G_HAVE_ISO_VARARGS
104 # define SET_ERROR(error, type, ...) \
106 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
107 if ((error) && !*(error)) { \
108 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
112 # define ERROR(type, ...) \
113 SET_ERROR (((graph_t *) graph)->error, (type), __VA_ARGS__ )
115 #elif defined(G_HAVE_GNUC_VARARGS)
117 # define SET_ERROR(error, type, args...) \
119 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
120 if ((error) && !*(error)) { \
121 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
125 # define ERROR(type, args...) \
126 SET_ERROR (((graph_t *) graph)->error,(type) , args )
131 SET_ERROR (GError **error, gint type, const char *format, ...)
135 g_warning ("error while parsing");
140 va_start (varargs, format);
141 string = g_strdup_vprintf (format, varargs);
144 g_set_error (error, GST_PARSE_ERROR, type, string);
151 #endif /* G_HAVE_ISO_VARARGS */
153 /*** define YYPRINTF macro/function if we're debugging */
155 /* bison 1.35 calls this macro with side effects, we need to make sure the
156 side effects work - crappy bison */
158 #ifndef GST_DISABLE_GST_DEBUG
161 # ifdef G_HAVE_ISO_VARARGS
163 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
164 # define YYFPRINTF(a, ...) \
166 gchar *temp = g_strdup_printf (__VA_ARGS__); \
167 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
171 # elif defined(G_HAVE_GNUC_VARARGS)
173 # define YYFPRINTF(a, args...) \
175 gchar *temp = g_strdup_printf ( args ); \
176 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
183 YYPRINTF(const char *format, ...)
188 va_start (varargs, format);
189 temp = g_strdup_vprintf (format, varargs);
190 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
195 # endif /* G_HAVE_ISO_VARARGS */
197 #endif /* GST_DISABLE_GST_DEBUG */
199 #define GST_BIN_MAKE(res, type, chainval, assign) \
201 chain_t *chain = chainval; \
203 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
205 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY_BIN, \
206 _("specified empty bin \"%s\", not allowed"), type); \
207 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
208 g_slist_free (assign); \
211 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, \
212 _("no bin \"%s\", skipping"), type); \
213 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
214 g_slist_free (assign); \
217 for (walk = chain->elements; walk; walk = walk->next ) \
218 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
219 g_slist_free (chain->elements); \
220 chain->elements = g_slist_prepend (NULL, bin); \
222 /* set the properties now */ \
223 for (walk = assign; walk; walk = walk->next) \
224 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
225 g_slist_free (assign); \
229 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) \
231 link = gst_parse_link_new (); \
233 link->sink = _sink; \
234 link->src_name = _src_name; \
235 link->sink_name = _sink_name; \
236 link->src_pads = _src_pads; \
237 link->sink_pads = _sink_pads; \
241 #define MAKE_REF(link, _src, _pads) \
243 gchar *padname = _src; \
244 GSList *pads = _pads; \
246 while (*padname != '.') padname++; \
249 if (*padname != '\0') \
250 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
252 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
256 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
264 /* parse the string, so the property name is null-terminated an pos points
265 to the beginning of the value */
266 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
272 while (g_ascii_isspace (*pos)) pos++;
275 while (g_ascii_isspace (*pos)) pos++;
278 pos[strlen (pos) - 1] = '\0';
280 gst_parse_unescape (pos);
282 if (gst_child_proxy_lookup (GST_OBJECT (element), value, &target, &pspec)) {
283 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
284 GST_LOG ("parsing property %s as a %s", pspec->name,
285 g_type_name (value_type));
286 g_value_init (&v, value_type);
287 if (!gst_value_deserialize (&v, pos))
289 g_object_set_property (G_OBJECT (target), pspec->name, &v);
290 gst_object_unref (target);
292 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
293 _("no property \"%s\" in element \"%s\""), value, \
294 GST_ELEMENT_NAME (element));
298 gst_parse_strfree (value);
304 gst_object_unref (target);
305 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
306 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
307 value, GST_ELEMENT_NAME (element), pos);
311 gst_parse_free_link (link_t *link)
313 gst_parse_strfree (link->src_name);
314 gst_parse_strfree (link->sink_name);
315 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
316 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
317 g_slist_free (link->src_pads);
318 g_slist_free (link->sink_pads);
319 if (link->caps) gst_caps_unref (link->caps);
320 gst_parse_link_free (link);
324 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
326 DelayedLink *link = (DelayedLink *) data;
328 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
329 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
330 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
332 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
333 link->sink_pad, link->caps)) {
334 /* do this here, we don't want to get any problems later on when
335 * unlocking states */
336 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
337 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
338 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
339 g_signal_handler_disconnect (src, link->signal_id);
340 g_free (link->src_pad);
341 g_free (link->sink_pad);
342 if (link->caps) gst_caps_unref (link->caps);
346 /* both padnames and the caps may be NULL */
348 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
349 GstElement *sink, const gchar *sink_pad,
352 GList *templs = gst_element_class_get_pad_template_list (
353 GST_ELEMENT_GET_CLASS (src));
355 for (; templs; templs = templs->next) {
356 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
357 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
358 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
360 DelayedLink *data = g_new (DelayedLink, 1);
362 /* TODO: maybe we should check if src_pad matches this template's names */
364 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
365 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
366 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
368 data->src_pad = g_strdup (src_pad);
370 data->sink_pad = g_strdup (sink_pad);
372 data->caps = gst_caps_copy (caps);
376 data->signal_id = g_signal_connect (G_OBJECT (src), "pad-added",
377 G_CALLBACK (gst_parse_found_pad), data);
384 * performs a link and frees the struct. src and sink elements must be given
385 * return values 0 - link performed
390 gst_parse_perform_link (link_t *link, graph_t *graph)
392 GstElement *src = link->src;
393 GstElement *sink = link->sink;
394 GSList *srcs = link->src_pads;
395 GSList *sinks = link->sink_pads;
396 g_assert (GST_IS_ELEMENT (src));
397 g_assert (GST_IS_ELEMENT (sink));
399 GST_CAT_INFO (GST_CAT_PIPELINE,
400 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
401 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
402 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
403 g_slist_length (srcs), g_slist_length (sinks), link->caps);
405 if (!srcs || !sinks) {
406 if (gst_element_link_pads_filtered (src,
407 srcs ? (const gchar *) srcs->data : NULL, sink,
408 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
411 if (gst_parse_perform_delayed_link (src,
412 srcs ? (const gchar *) srcs->data : NULL,
413 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
420 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
423 while (srcs && sinks) {
424 const gchar *src_pad = (const gchar *) srcs->data;
425 const gchar *sink_pad = (const gchar *) sinks->data;
426 srcs = g_slist_next (srcs);
427 sinks = g_slist_next (sinks);
428 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
432 if (gst_parse_perform_delayed_link (src, src_pad,
443 gst_parse_free_link (link);
447 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
448 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
449 GST_ELEMENT_NAME (sink));
450 gst_parse_free_link (link);
455 static int yylex (void *lvalp);
456 static int yyerror (const char *s);
469 %token <s> IDENTIFIER
470 %left <s> REF PADREF BINREF
471 %token <s> ASSIGNMENT
477 %type <l> linkpart link
480 %type <p> padlist pads assignments
492 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
494 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
495 gst_parse_strfree ($1);
498 gst_parse_strfree ($1);
500 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
504 assignments: /* NOP */ { $$ = NULL; }
505 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
507 bin: '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
508 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
509 gst_parse_strfree ($1);
511 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
512 gst_parse_strfree ($1);
514 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
515 gst_parse_strfree ($1);
519 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
520 | PADREF padlist { $$ = $2;
521 $$ = g_slist_prepend ($$, $1);
524 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
525 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
528 reference: REF { MAKE_REF ($$, $1, NULL); }
529 | REF padlist { MAKE_REF ($$, $1, $2); }
532 linkpart: reference { $$ = $1; }
533 | pads { MAKE_REF ($$, NULL, $1); }
534 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
537 link: linkpart LINK linkpart { $$ = $1;
539 $$->caps = gst_caps_from_string ($2);
540 if ($$->caps == NULL)
541 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
542 gst_parse_strfree ($2);
544 $$->sink_name = $3->src_name;
545 $$->sink_pads = $3->src_pads;
546 gst_parse_link_free ($3);
550 linklist: link { $$ = g_slist_prepend (NULL, $1); }
551 | link linklist { $$ = g_slist_prepend ($2, $1); }
552 | linklist error { $$ = $1; }
555 chain: element { $$ = gst_parse_chain_new ();
556 $$->first = $$->last = $1;
557 $$->front = $$->back = NULL;
558 $$->elements = g_slist_prepend (NULL, $1);
561 | chain chain { if ($1->back && $2->front) {
562 if (!$1->back->sink_name) {
563 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
564 gst_parse_free_link ($1->back);
566 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
568 if (!$2->front->src_name) {
569 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
570 gst_parse_free_link ($2->front);
572 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
575 } else if ($1->back) {
576 if (!$1->back->sink_name) {
577 $1->back->sink = $2->first;
579 } else if ($2->front) {
580 if (!$2->front->src_name) {
581 $2->front->src = $1->last;
583 $1->back = $2->front;
587 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
591 $1->elements = g_slist_concat ($1->elements, $2->elements);
593 gst_parse_chain_free ($2);
596 | chain linklist { GSList *walk;
598 $2 = g_slist_prepend ($2, $1->back);
601 if (!((link_t *) $2->data)->src_name) {
602 ((link_t *) $2->data)->src = $1->last;
605 for (walk = $2; walk; walk = walk->next) {
606 link_t *link = (link_t *) walk->data;
607 if (!link->sink_name && walk->next) {
608 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
609 gst_parse_free_link (link);
610 } else if (!link->src_name && !link->src) {
611 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
612 gst_parse_free_link (link);
615 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
624 | chain error { $$ = $1; }
625 | link chain { if ($2->front) {
626 if (!$2->front->src_name) {
627 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
628 gst_parse_free_link ($2->front);
630 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
633 if (!$1->sink_name) {
634 $1->sink = $2->first;
639 | PARSE_URL chain { $$ = $2;
641 GstElement *element =
642 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
644 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
645 _("no source element for URI \"%s\""), $1);
647 $$->front->src = element;
648 ((graph_t *) graph)->links = g_slist_prepend (
649 ((graph_t *) graph)->links, $$->front);
651 $$->elements = g_slist_prepend ($$->elements, element);
654 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
655 _("no element to link URI \"%s\" to"), $1);
659 | link PARSE_URL { GstElement *element =
660 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
662 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
663 _("no sink element for URI \"%s\""), $2);
664 gst_parse_link_free ($1);
667 } else if ($1->sink_name || $1->sink_pads) {
668 gst_object_unref (element);
669 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
670 _("could not link sink element for URI \"%s\""), $2);
671 gst_parse_link_free ($1);
675 $$ = gst_parse_chain_new ();
676 $$->first = $$->last = element;
678 $$->front->sink = element;
679 $$->elements = g_slist_prepend (NULL, element);
684 graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
685 $$ = (graph_t *) graph;
687 | chain { $$ = (graph_t *) graph;
689 if (!$1->front->src_name) {
690 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
691 gst_parse_free_link ($1->front);
693 $$->links = g_slist_prepend ($$->links, $1->front);
698 if (!$1->back->sink_name) {
699 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
700 gst_parse_free_link ($1->back);
702 $$->links = g_slist_prepend ($$->links, $1->back);
712 extern FILE *_gst_parse_yyin;
713 int _gst_parse_yylex (YYSTYPE *lvalp);
715 static int yylex (void *lvalp) {
716 return _gst_parse_yylex ((YYSTYPE*) lvalp);
720 yyerror (const char *s)
722 /* FIXME: This should go into the GError somehow, but how? */
723 GST_WARNING ("Error during parsing: %s", s);
727 struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
728 void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
730 _gst_parse_launch (const gchar *str, GError **error)
737 struct yy_buffer_state *buf;
739 g_return_val_if_fail (str != NULL, NULL);
745 #ifdef __GST_PARSE_TRACE
746 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
747 __strings = __chains = __links = 0;
748 #endif /* __GST_PARSE_TRACE */
750 dstr = g_strdup (str);
751 buf = _gst_parse_yy_scan_string (dstr);
757 if (yyparse (&g) != 0) {
758 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
759 "Unrecoverable syntax error while parsing pipeline %s", str);
761 _gst_parse_yy_delete_buffer (buf);
767 _gst_parse_yy_delete_buffer (buf);
769 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
770 g.chain ? g_slist_length (g.chain->elements) : 0,
771 g_slist_length (g.links));
775 } else if (!(((chain_t *) g.chain)->elements->next)) {
776 /* only one toplevel element */
777 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
778 g_slist_free (((chain_t *) g.chain)->elements);
779 if (GST_IS_BIN (ret))
781 gst_parse_chain_free (g.chain);
783 /* put all elements in our bin */
784 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
787 for (walk = g.chain->elements; walk; walk = walk->next) {
788 if (walk->data != NULL)
789 gst_bin_add (bin, GST_ELEMENT (walk->data));
792 g_slist_free (g.chain->elements);
793 ret = GST_ELEMENT (bin);
794 gst_parse_chain_free (g.chain);
798 for (walk = g.links; walk; walk = walk->next) {
799 link_t *l = (link_t *) walk->data;
803 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
805 gst_object_unref (l->src);
807 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
811 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
812 "No element named \"%s\" - omitting link", l->src_name);
813 gst_parse_free_link (l);
820 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
822 gst_object_unref (l->sink);
824 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
828 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
829 "No element named \"%s\" - omitting link", l->sink_name);
830 gst_parse_free_link (l);
834 gst_parse_perform_link (l, &g);
836 g_slist_free (g.links);
839 #ifdef __GST_PARSE_TRACE
840 GST_CAT_DEBUG (GST_CAT_PIPELINE,
841 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
843 if (__strings || __chains || __links) {
844 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
847 #endif /* __GST_PARSE_TRACE */
853 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
854 g_slist_free (g.chain->elements);
855 gst_parse_chain_free (g.chain);
858 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
859 g_slist_free (g.links);