From: David Gibson <david@gibson.dropbear.id.au>
To: Jon Loeliger <jdl@freescale.com>
Cc: linuxppc-dev@ozlabs.org
Subject: dtc: Remove ugly include stack abuse
Date: Thu, 6 Mar 2008 12:45:41 +1100 [thread overview]
Message-ID: <20080306014541.GB18315@localhost.localdomain> (raw)
Currently, dt_from_source() uses push_input_file() to set up the
initial input file for the lexer. That sounds sensible - put the
outermost input file at the bottom of the stack - until you realise
that what it *actually* does is pushes the current, uninitialized,
lexer input state onto the stack, then sets up the new lexer input.
That necessitates an extra check in pop_input_file(), rather than
signalling termination in the natural way when the include stack is
empty, it has to check when it pops the bogus uninitialized state off
the stack. Ick.
With that fixed, push_input_file(), pop_input_file() and
incl_file_stack itself become local to the lexer, so make them static.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
dtc-lexer.l | 12 ++++++------
srcpos.h | 3 ---
treesource.c | 3 ++-
3 files changed, 8 insertions(+), 10 deletions(-)
Index: dtc/treesource.c
===================================================================
--- dtc.orig/treesource.c 2008-03-05 16:14:54.000000000 +1100
+++ dtc/treesource.c 2008-03-06 12:24:49.000000000 +1100
@@ -32,7 +32,8 @@
the_boot_info = NULL;
treesource_error = 0;
- push_input_file(fname);
+ srcpos_file = dtc_open_file(fname, NULL);
+ yyin = srcpos_file->file;
if (yyparse() != 0)
return NULL;
Index: dtc/dtc-lexer.l
===================================================================
--- dtc.orig/dtc-lexer.l 2008-03-06 12:25:24.000000000 +1100
+++ dtc/dtc-lexer.l 2008-03-06 12:43:52.000000000 +1100
@@ -52,6 +52,9 @@
DPRINT("<V1>\n"); \
BEGIN(V1); \
}
+
+static void push_input_file(const char *filename);
+static int pop_input_file(void);
%}
%%
@@ -229,7 +232,7 @@
struct incl_file *prev;
};
-struct incl_file *incl_file_stack;
+static struct incl_file *incl_file_stack;
/*
@@ -240,7 +243,7 @@
static int incl_depth = 0;
-void push_input_file(const char *filename)
+static void push_input_file(const char *filename)
{
struct incl_file *incl_file;
struct dtc_file *newfile;
@@ -282,7 +285,7 @@
}
-int pop_input_file(void)
+static int pop_input_file(void)
{
struct incl_file *incl_file;
@@ -312,8 +315,5 @@
*/
free(incl_file);
- if (YY_CURRENT_BUFFER == 0)
- return 0;
-
return 1;
}
Index: dtc/srcpos.h
===================================================================
--- dtc.orig/srcpos.h 2008-03-06 12:43:23.000000000 +1100
+++ dtc/srcpos.h 2008-03-06 12:43:25.000000000 +1100
@@ -75,9 +75,6 @@
extern struct dtc_file *srcpos_file;
-extern void push_input_file(const char *filename);
-extern int pop_input_file(void);
-
struct search_path {
const char *dir; /* NULL for current directory */
struct search_path *prev, *next;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
reply other threads:[~2008-03-06 1:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080306014541.GB18315@localhost.localdomain \
--to=david@gibson.dropbear.id.au \
--cc=jdl@freescale.com \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).