mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-24 08:08:22 +00:00
gst/parse/: push & pop the state of the lexer for reentrant use case
Original commit message from CVS: Patch by: Marc-Andre Lureau <marcandre.lureau@gmail.com> * gst/parse/Makefile.am: * gst/parse/grammar.y: * gst/parse/parse.l: push & pop the state of the lexer for reentrant use case Fixes #349180
This commit is contained in:
parent
8b97e07338
commit
48afa6dc3a
4 changed files with 45 additions and 30 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2006-07-30 Stefan Kost <ensonic@users.sf.net>
|
||||||
|
|
||||||
|
Patch by: Marc-Andre Lureau <marcandre.lureau@gmail.com>
|
||||||
|
|
||||||
|
* gst/parse/Makefile.am:
|
||||||
|
* gst/parse/grammar.y:
|
||||||
|
* gst/parse/parse.l:
|
||||||
|
push & pop the state of the lexer for reentrant use case
|
||||||
|
Fixes #349180
|
||||||
|
|
||||||
2006-07-29 Tim-Philipp Müller <tim at centricular dot net>
|
2006-07-29 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
* libs/gst/base/gstbasesrc.h:
|
* libs/gst/base/gstbasesrc.h:
|
||||||
|
|
|
@ -18,7 +18,7 @@ libgstparse_la_LIBADD = $(GST_ALL_LIBS)
|
||||||
noinst_HEADERS = grammar.tab.h
|
noinst_HEADERS = grammar.tab.h
|
||||||
|
|
||||||
grammar.tab.c grammar.tab.h: grammar.y
|
grammar.tab.c grammar.tab.h: grammar.y
|
||||||
$(BISON_PATH) -d -v -p_gst_parse__yy $(srcdir)/grammar.y -o grammar.tab.c && \
|
$(BISON_PATH) -d -v -p_gst_parse_yy $(srcdir)/grammar.y -o grammar.tab.c && \
|
||||||
mv grammar.tab.c grammar.tab_tmp.c && \
|
mv grammar.tab.c grammar.tab_tmp.c && \
|
||||||
echo '#ifdef HAVE_CONFIG_H' > grammar.tab_tmp2.c && \
|
echo '#ifdef HAVE_CONFIG_H' > grammar.tab_tmp2.c && \
|
||||||
echo '#include <config.h>' >> grammar.tab_tmp2.c && \
|
echo '#include <config.h>' >> grammar.tab_tmp2.c && \
|
||||||
|
|
|
@ -24,7 +24,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define YYERROR_VERBOSE 1
|
#define YYERROR_VERBOSE 1
|
||||||
#define YYPARSE_PARAM graph
|
#define YYLEX_PARAM scanner
|
||||||
|
|
||||||
|
typedef void* yyscan_t;
|
||||||
|
|
||||||
|
int _gst_parse_yylex (void * yylval_param , yyscan_t yyscanner);
|
||||||
|
int _gst_parse_yylex_init (yyscan_t scanner);
|
||||||
|
int _gst_parse_yylex_destroy (yyscan_t scanner);
|
||||||
|
struct yy_buffer_state * _gst_parse_yy_scan_string (char* , yyscan_t);
|
||||||
|
void _gst_parse_yypush_buffer_state (void * new_buffer ,yyscan_t yyscanner );
|
||||||
|
void _gst_parse_yypop_buffer_state (yyscan_t yyscanner );
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GST_PARSE_TRACE
|
#ifdef __GST_PARSE_TRACE
|
||||||
static guint __strings;
|
static guint __strings;
|
||||||
|
@ -533,8 +543,7 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int yylex (void *lvalp);
|
static int yyerror (graph_t *graph, const char *s);
|
||||||
static int yyerror (const char *s);
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
|
@ -565,7 +574,8 @@ static int yyerror (const char *s);
|
||||||
%right '.'
|
%right '.'
|
||||||
%left '!' '='
|
%left '!' '='
|
||||||
|
|
||||||
%pure_parser
|
%parse-param { void *scanner, graph_t *graph }
|
||||||
|
%pure-parser
|
||||||
|
|
||||||
%start graph
|
%start graph
|
||||||
%%
|
%%
|
||||||
|
@ -790,23 +800,16 @@ graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERRO
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
extern FILE *_gst_parse_yyin;
|
|
||||||
int _gst_parse_yylex (YYSTYPE *lvalp);
|
|
||||||
|
|
||||||
static int yylex (void *lvalp) {
|
|
||||||
return _gst_parse_yylex ((YYSTYPE*) lvalp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
yyerror (const char *s)
|
yyerror (graph_t *graph, const char *s)
|
||||||
{
|
{
|
||||||
/* FIXME: This should go into the GError somehow, but how? */
|
/* FIXME: This should go into the GError somehow, but how? */
|
||||||
GST_WARNING ("Error during parsing: %s", s);
|
GST_WARNING ("Error during parsing: %s", s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
|
|
||||||
void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
|
|
||||||
GstElement *
|
GstElement *
|
||||||
_gst_parse_launch (const gchar *str, GError **error)
|
_gst_parse_launch (const gchar *str, GError **error)
|
||||||
{
|
{
|
||||||
|
@ -815,8 +818,8 @@ _gst_parse_launch (const gchar *str, GError **error)
|
||||||
GSList *walk;
|
GSList *walk;
|
||||||
GstBin *bin = NULL;
|
GstBin *bin = NULL;
|
||||||
GstElement *ret;
|
GstElement *ret;
|
||||||
struct yy_buffer_state *buf;
|
yyscan_t scanner;
|
||||||
|
|
||||||
g_return_val_if_fail (str != NULL, NULL);
|
g_return_val_if_fail (str != NULL, NULL);
|
||||||
|
|
||||||
g.chain = NULL;
|
g.chain = NULL;
|
||||||
|
@ -829,21 +832,22 @@ _gst_parse_launch (const gchar *str, GError **error)
|
||||||
#endif /* __GST_PARSE_TRACE */
|
#endif /* __GST_PARSE_TRACE */
|
||||||
|
|
||||||
dstr = g_strdup (str);
|
dstr = g_strdup (str);
|
||||||
buf = _gst_parse_yy_scan_string (dstr);
|
_gst_parse_yylex_init( &scanner );
|
||||||
|
_gst_parse_yy_scan_string (dstr, scanner);
|
||||||
|
|
||||||
#ifndef YYDEBUG
|
#ifndef YYDEBUG
|
||||||
yydebug = 1;
|
yydebug = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (yyparse (&g) != 0) {
|
if (yyparse (scanner, &g) != 0) {
|
||||||
SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
|
SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
|
||||||
"Unrecoverable syntax error while parsing pipeline %s", str);
|
"Unrecoverable syntax error while parsing pipeline %s", str);
|
||||||
|
|
||||||
goto error1;
|
goto error1;
|
||||||
}
|
}
|
||||||
|
_gst_parse_yylex_destroy( scanner );
|
||||||
g_free (dstr);
|
g_free (dstr);
|
||||||
_gst_parse_yy_delete_buffer (buf);
|
|
||||||
|
|
||||||
GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
|
GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
|
||||||
g.chain ? g_slist_length (g.chain->elements) : 0,
|
g.chain ? g_slist_length (g.chain->elements) : 0,
|
||||||
g_slist_length (g.links));
|
g_slist_length (g.links));
|
||||||
|
|
|
@ -32,7 +32,6 @@ PRINT (const char *format, ...)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define YY_DECL int _gst_parse_yylex (YYSTYPE *lvalp)
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
_operator [(){}.!,;=]
|
_operator [(){}.!,;=]
|
||||||
|
@ -65,12 +64,14 @@ _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)
|
||||||
%x value
|
%x value
|
||||||
%option noyywrap
|
%option noyywrap
|
||||||
%option nounput
|
%option nounput
|
||||||
|
%option reentrant
|
||||||
|
%option bison-bridge
|
||||||
%%
|
%%
|
||||||
|
|
||||||
{_assignment} {
|
{_assignment} {
|
||||||
/* "=" */
|
/* "=" */
|
||||||
PRINT ("ASSIGNMENT: %s", yytext);
|
PRINT ("ASSIGNMENT: %s", yytext);
|
||||||
lvalp->s = gst_parse_strdup (yytext);
|
yylval->s = gst_parse_strdup (yytext);
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
return ASSIGNMENT;
|
return ASSIGNMENT;
|
||||||
}
|
}
|
||||||
|
@ -78,14 +79,14 @@ _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)
|
||||||
{_padref} {
|
{_padref} {
|
||||||
yytext++;
|
yytext++;
|
||||||
PRINT ("PADREF: %s", yytext);
|
PRINT ("PADREF: %s", yytext);
|
||||||
lvalp->s = gst_parse_strdup (yytext);
|
yylval->s = gst_parse_strdup (yytext);
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
return PADREF;
|
return PADREF;
|
||||||
}
|
}
|
||||||
|
|
||||||
{_ref} {
|
{_ref} {
|
||||||
PRINT ("REF: %s", yytext);
|
PRINT ("REF: %s", yytext);
|
||||||
lvalp->s = gst_parse_strdup (yytext);
|
yylval->s = gst_parse_strdup (yytext);
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
return REF;
|
return REF;
|
||||||
}
|
}
|
||||||
|
@ -95,14 +96,14 @@ _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)
|
||||||
while (!g_ascii_isspace (*pos) && (*pos != '.')) pos++;
|
while (!g_ascii_isspace (*pos) && (*pos != '.')) pos++;
|
||||||
*pos = '\0';
|
*pos = '\0';
|
||||||
PRINT ("BINREF: %s", yytext);
|
PRINT ("BINREF: %s", yytext);
|
||||||
lvalp->s = gst_parse_strdup (yytext);
|
yylval->s = gst_parse_strdup (yytext);
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
return BINREF;
|
return BINREF;
|
||||||
}
|
}
|
||||||
|
|
||||||
{_identifier} {
|
{_identifier} {
|
||||||
PRINT ("IDENTIFIER: %s", yytext);
|
PRINT ("IDENTIFIER: %s", yytext);
|
||||||
lvalp->s = gst_parse_strdup (yytext);
|
yylval->s = gst_parse_strdup (yytext);
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
return IDENTIFIER;
|
return IDENTIFIER;
|
||||||
}
|
}
|
||||||
|
@ -113,22 +114,22 @@ _link ("!"[[:space:]]*{_caps}([[:space:]]*(";"[[:space:]]*{_caps})*[[:space:]]*)
|
||||||
c++;
|
c++;
|
||||||
if (*c) {
|
if (*c) {
|
||||||
while (g_ascii_isspace (*c)) c++;
|
while (g_ascii_isspace (*c)) c++;
|
||||||
c = lvalp->s = gst_parse_strdup (c);
|
c = yylval->s = gst_parse_strdup (c);
|
||||||
while (*c) c++;
|
while (*c) c++;
|
||||||
if (*--c != '!')
|
if (*--c != '!')
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
while (g_ascii_isspace (*--c));
|
while (g_ascii_isspace (*--c));
|
||||||
*++c = '\0';
|
*++c = '\0';
|
||||||
} else {
|
} else {
|
||||||
lvalp->s = NULL;
|
yylval->s = NULL;
|
||||||
}
|
}
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
return LINK;
|
return LINK;
|
||||||
}
|
}
|
||||||
{_url} {
|
{_url} {
|
||||||
PRINT ("URL: %s", yytext);
|
PRINT ("URL: %s", yytext);
|
||||||
lvalp->s = g_strdup (yytext);
|
yylval->s = g_strdup (yytext);
|
||||||
gst_parse_unescape (lvalp->s);
|
gst_parse_unescape (yylval->s);
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
return PARSE_URL;
|
return PARSE_URL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue