diff options
author | Paul Smith <psmith@gnu.org> | 2002-10-25 22:01:47 +0000 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2002-10-25 22:01:47 +0000 |
commit | d696707cb5009308baa345ff60c8378512b07edb (patch) | |
tree | 480e6f04e132649d7346adc8eb92d090f85aabde /read.c | |
parent | bd108cf45cca0a37cb82aca0f3f3516e593d638b (diff) | |
download | gunmake-d696707cb5009308baa345ff60c8378512b07edb.tar.gz |
Fix eval bugs 1516 and 1517.
Diffstat (limited to 'read.c')
-rw-r--r-- | read.c | 55 |
1 files changed, 38 insertions, 17 deletions
@@ -272,6 +272,34 @@ read_all_makefiles (char **makefiles) return read_makefiles; } +/* Install a new conditional and return the previous one. */ + +static struct conditionals * +install_conditionals (struct conditionals *new) +{ + struct conditionals *save = conditionals; + + bzero ((char *) new, sizeof (*new)); + conditionals = new; + + return save; +} + +/* Free the current conditionals and reinstate a saved one. */ + +static void +restore_conditionals (struct conditionals *saved) +{ + /* Free any space allocated by conditional_line. */ + if (conditionals->ignoring) + free (conditionals->ignoring); + if (conditionals->seen_else) + free (conditionals->seen_else); + + /* Restore state. */ + conditionals = saved; +} + static int eval_makefile (char *filename, int flags) { @@ -388,6 +416,8 @@ int eval_buffer (char *buffer) { struct ebuffer ebuf; + struct conditionals *saved; + struct conditionals new; const struct floc *curfile; int r; @@ -402,8 +432,12 @@ eval_buffer (char *buffer) curfile = reading_file; reading_file = &ebuf.floc; + saved = install_conditionals (&new); + r = eval (&ebuf, 1); + restore_conditionals (saved); + reading_file = curfile; return r; @@ -412,13 +446,8 @@ eval_buffer (char *buffer) /* Read file FILENAME as a makefile and add its contents to the data base. - SET_DEFAULT is true if we are allowed to set the default goal. - - FILENAME is added to the `read_makefiles' chain. + SET_DEFAULT is true if we are allowed to set the default goal. */ - Returns 0 if a file was not found or not read. - Returns 1 if FILENAME was found and read. - Returns 2 if FILENAME was read, and we kept a reference (don't free it). */ static int eval (struct ebuffer *ebuf, int set_default) @@ -782,9 +811,7 @@ eval (struct ebuffer *ebuf, int set_default) /* Save the state of conditionals and start the included makefile with a clean slate. */ - save = conditionals; - bzero ((char *) &new_conditionals, sizeof new_conditionals); - conditionals = &new_conditionals; + save = install_conditionals (&new_conditionals); /* Record the rules that are waiting so they will determine the default goal before those in the included makefile. */ @@ -810,14 +837,8 @@ eval (struct ebuffer *ebuf, int set_default) } } - /* Free any space allocated by conditional_line. */ - if (conditionals->ignoring) - free (conditionals->ignoring); - if (conditionals->seen_else) - free (conditionals->seen_else); - - /* Restore state. */ - conditionals = save; + /* Restore conditional state. */ + restore_conditionals (save); goto rule_complete; } |