Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P make
- Index: expand.c
- ===================================================================
- RCS file: /sources/make/make/expand.c,v
- retrieving revision 1.62
- diff -u -r1.62 expand.c
- --- expand.c 5 Mar 2012 14:10:43 -0000 1.62
- +++ expand.c 7 Mar 2012 14:33:25 -0000
- @@ -137,7 +137,14 @@
- if (v->append)
- value = allocated_variable_append (v);
- else
- - value = allocated_variable_expand (v->value);
- + {
- + /* We need a copy of STRING: due to eval, it's possible that it will get
- + freed as we process it (it might be the value of a variable that's
- + reset for example). */
- + char *saved_value = xstrdup (v->value);
- + value = allocated_variable_expand (saved_value);
- + free(saved_value);
- + }
- v->expanding = 0;
- if (set_reading)
- @@ -191,14 +198,17 @@
- NULL.
- */
- char *
- -variable_expand_string (char *line, const char *string, long length)
- +variable_expand_string (char *line, const char *str, long length)
- {
- struct variable *v;
- const char *p, *p1;
- - char *save;
- +// char *save;
- + char end_ch = 0;
- char *o;
- unsigned int line_offset;
- + char *string = (char *) str;
- +
- if (!line)
- line = initialize_variable_output();
- o = line;
- @@ -213,8 +223,12 @@
- /* We need a copy of STRING: due to eval, it's possible that it will get
- freed as we process it (it might be the value of a variable that's reset
- for example). Also having a nil-terminated string is handy. */
- - save = length < 0 ? xstrdup (string) : xstrndup (string, length);
- - p = save;
- + if (length > 0)
- + {
- + end_ch = string[length];
- + string[length] = '\0';
- + }
- + p = string;
- while (1)
- {
- @@ -404,7 +418,8 @@
- ++p;
- }
- - free (save);
- + if (length > 0)
- + string[length] = end_ch;
- variable_buffer_output (o, "", 1);
- return (variable_buffer + line_offset);
- @@ -414,12 +429,6 @@
- Build in 'variable_buffer' the result of expanding the references and calls.
- Return the address of the resulting string, which is null-terminated
- and is valid only until the next time this function is called. */
- -
- -char *
- -variable_expand (const char *line)
- -{
- - return variable_expand_string(NULL, line, (long)-1);
- -}
- /* Expand an argument for an expansion function.
- The text starting at STR and ending at END is variable-expanded
- @@ -430,27 +439,39 @@
- char *
- expand_argument (const char *str, const char *end)
- {
- - char *tmp, *alloc = NULL;
- +// char *tmp, *alloc = NULL;
- char *r;
- + char *strend = (char *) end;
- + char end_ch = 0;
- +
- if (str == end)
- return xstrdup("");
- - if (!end || *end == '\0')
- - return allocated_variable_expand (str);
- +// if (!end || *end == '\0')
- +// return allocated_variable_expand (str);
- +//
- +// if (end - str + 1 > 1000)
- +// tmp = alloc = xmalloc (end - str + 1);
- +// else
- +// tmp = alloca (end - str + 1);
- +//
- +// memcpy (tmp, str, end - str);
- +// tmp[end - str] = '\0';
- - if (end - str + 1 > 1000)
- - tmp = alloc = xmalloc (end - str + 1);
- - else
- - tmp = alloca (end - str + 1);
- + if (strend)
- + {
- + end_ch = *strend;
- + *strend = '\0';
- + }
- - memcpy (tmp, str, end - str);
- - tmp[end - str] = '\0';
- + r = allocated_variable_expand (str);
- - r = allocated_variable_expand (tmp);
- + if (strend)
- + *strend = end_ch;
- - if (alloc)
- - free (alloc);
- +// if (alloc)
- +// free (alloc);
- return r;
- }
- Index: function.c
- ===================================================================
- RCS file: /sources/make/make/function.c,v
- retrieving revision 1.133
- diff -u -r1.133 function.c
- --- function.c 5 Mar 2012 14:10:43 -0000 1.133
- +++ function.c 7 Mar 2012 14:33:26 -0000
- @@ -828,38 +828,42 @@
- /* expand only the first two. */
- char *varname = expand_argument (argv[0], NULL);
- char *list = expand_argument (argv[1], NULL);
- - const char *body = argv[2];
- + char *body = argv[2];
- - int doneany = 0;
- const char *list_iterator = list;
- - const char *p;
- + char *p;
- + char *saved_value;
- unsigned int len;
- struct variable *var;
- - push_new_variable_scope ();
- + struct variable_scope scope;
- +
- + push_variable_scope (&scope);
- +
- var = define_variable (varname, strlen (varname), "", o_automatic, 0);
- + saved_value = var->value;
- /* loop through LIST, put the value in VAR and expand BODY */
- while ((p = find_next_token (&list_iterator, &len)) != 0)
- {
- - char *result = 0;
- -
- - free (var->value);
- - var->value = xstrndup (p, len);
- + char end_ch = p[len];
- + p[len] = '\0';
- - result = allocated_variable_expand (body);
- + var->value = p;
- + o = variable_expand_string (o, body, (long) -1);
- + o = variable_buffer_output (o + strlen (o), " ", 1);
- - o = variable_buffer_output (o, result, strlen (result));
- - o = variable_buffer_output (o, " ", 1);
- - doneany = 1;
- - free (result);
- + p[len] = end_ch;
- }
- - if (doneany)
- + if (var->value != saved_value)
- /* Kill the last space. */
- --o;
- + var->value = saved_value;
- +
- pop_variable_scope ();
- +
- free (varname);
- free (list);
- @@ -2391,20 +2395,22 @@
- static int max_args = 0;
- char *fname;
- char *cp;
- - char *body;
- int flen;
- int i;
- int saved_args;
- const struct function_table_entry *entry_p;
- struct variable *v;
- + struct variable_scope scope;
- /* There is no way to define a variable with a space in the name, so strip
- - leading and trailing whitespace as a favor to the user. */
- + trailing whitespace as a favor to the user. */
- fname = argv[0];
- while (*fname != '\0' && isspace ((unsigned char)*fname))
- ++fname;
- - cp = fname + strlen (fname) - 1;
- + flen = strlen (fname);
- +
- + cp = fname + flen - 1;
- while (cp > fname && isspace ((unsigned char)*cp))
- --cp;
- cp[1] = '\0';
- @@ -2413,6 +2419,9 @@
- if (*fname == '\0')
- return o;
- + /* Fix up the length after stripping a trailing whitespace. */
- + flen = cp - fname + 1;
- +
- /* Are we invoking a builtin function? */
- entry_p = lookup_function (fname);
- @@ -2426,7 +2435,6 @@
- /* Not a builtin, so the first argument is the name of a variable to be
- expanded and interpreted as a function. Find it. */
- - flen = strlen (fname);
- v = lookup_variable (fname, flen);
- @@ -2436,16 +2444,9 @@
- if (v == 0 || *v->value == '\0')
- return o;
- - body = alloca (flen + 4);
- - body[0] = '$';
- - body[1] = '(';
- - memcpy (body + 2, fname, flen);
- - body[flen+2] = ')';
- - body[flen+3] = '\0';
- -
- /* Set up arguments $(1) .. $(N). $(0) is the function name. */
- - push_new_variable_scope ();
- + push_variable_scope (&scope);
- for (i=0; *argv; ++i, ++argv)
- {
- @@ -2468,21 +2469,30 @@
- define_variable (num, strlen (num), "", o_automatic, 0);
- }
- - /* Expand the body in the context of the arguments, adding the result to
- + /* Expand the variable in the context of the arguments, adding the result to
- the variable buffer. */
- v->exp_count = EXP_COUNT_MAX;
- saved_args = max_args;
- max_args = i;
- - o = variable_expand_string (o, body, flen+3);
- +
- + {
- + char *value = (v->recursive ? recursively_expand (v) : v->value);
- +
- + o = variable_buffer_output (o, value, strlen (value));
- +
- + if (v->recursive)
- + free (value);
- + }
- +
- max_args = saved_args;
- v->exp_count = 0;
- pop_variable_scope ();
- - return o + strlen (o);
- + return o;
- }
- void
- Index: variable.c
- ===================================================================
- RCS file: /sources/make/make/variable.c,v
- retrieving revision 1.112
- diff -u -r1.112 variable.c
- --- variable.c 5 Mar 2012 14:10:45 -0000 1.112
- +++ variable.c 7 Mar 2012 14:33:26 -0000
- @@ -666,23 +666,33 @@
- directly to the global_setlist so we need to replace that with the new one.
- */
- -struct variable_set_list *
- -push_new_variable_scope (void)
- +void
- +push_variable_scope (struct variable_scope *scope)
- {
- - current_variable_set_list = create_new_variable_set();
- - if (current_variable_set_list->next == &global_setlist)
- + register struct variable_set_list *setlist = &scope->list;
- + register struct variable_set *set = &scope->set;
- +
- + hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
- + variable_hash_1, variable_hash_2, variable_hash_cmp);
- +
- + setlist->set = set;
- + setlist->next = current_variable_set_list;
- + setlist->next_is_parent = 0;
- +
- + if (setlist->next != &global_setlist)
- + current_variable_set_list = setlist;
- + else
- {
- /* It was the global, so instead of new -> &global we want to replace
- &global with the new one and have &global -> new, with current still
- pointing to &global */
- - struct variable_set *set = current_variable_set_list->set;
- - current_variable_set_list->set = global_setlist.set;
- + setlist->set = global_setlist.set;
- global_setlist.set = set;
- - current_variable_set_list->next = global_setlist.next;
- - global_setlist.next = current_variable_set_list;
- + setlist->next = global_setlist.next;
- + global_setlist.next = setlist;
- +
- current_variable_set_list = &global_setlist;
- }
- - return (current_variable_set_list);
- }
- void
- @@ -713,11 +723,8 @@
- global_setlist.next_is_parent = setlist->next_is_parent;
- }
- - /* Free the one we no longer need. */
- - free (setlist);
- hash_map (&set->table, free_variable_name_and_value);
- hash_free (&set->table, 1);
- - free (set);
- }
- /* Merge FROM_SET into TO_SET, freeing unused storage in FROM_SET. */
- Index: variable.h
- ===================================================================
- RCS file: /sources/make/make/variable.h,v
- retrieving revision 1.51
- diff -u -r1.51 variable.h
- --- variable.h 5 Mar 2012 14:10:45 -0000 1.51
- +++ variable.h 7 Mar 2012 14:33:26 -0000
- @@ -96,6 +96,15 @@
- int next_is_parent; /* True if next is a parent target. */
- };
- +/* Structure for pushing (popping) it into (from) a variable set stack.
- + * It is also suitable for allocating it on the stack. */
- +
- +struct variable_scope
- + {
- + struct variable_set_list list;
- + struct variable_set set;
- + };
- +
- /* Structure used for pattern-specific variables. */
- struct pattern_var
- @@ -113,7 +122,8 @@
- /* expand.c */
- char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
- -char *variable_expand (const char *line);
- +#define variable_expand(line) \
- + variable_expand_string(NULL, line, (long)-1)
- char *variable_expand_for_file (const char *line, struct file *file);
- char *allocated_variable_expand_for_file (const char *line, struct file *file);
- #define allocated_variable_expand(line) \
- @@ -143,7 +153,7 @@
- /* variable.c */
- struct variable_set_list *create_new_variable_set (void);
- void free_variable_set (struct variable_set_list *);
- -struct variable_set_list *push_new_variable_scope (void);
- +void push_variable_scope (struct variable_scope *);
- void pop_variable_scope (void);
- void define_automatic_variables (void);
- void initialize_file_variables (struct file *file, int reading);
- Index: vpath.c
- ===================================================================
- RCS file: /sources/make/make/vpath.c,v
- retrieving revision 1.56
- diff -u -r1.56 vpath.c
- --- vpath.c 5 Mar 2012 14:10:46 -0000 1.56
- +++ vpath.c 7 Mar 2012 14:33:26 -0000
- @@ -73,13 +73,15 @@
- calling lookup_variable so that it will be recursively expanded. */
- {
- + char *str = xstrdup("$(strip $(VPATH))");
- /* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
- int save = warn_undefined_variables_flag;
- warn_undefined_variables_flag = 0;
- - p = variable_expand ("$(strip $(VPATH))");
- + p = variable_expand (str);
- warn_undefined_variables_flag = save;
- + free(str);
- }
- if (*p != '\0')
- @@ -106,13 +108,15 @@
- calling lookup_variable so that it will be recursively expanded. */
- {
- + char *str = xstrdup("$(strip $(GPATH))");
- /* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
- int save = warn_undefined_variables_flag;
- warn_undefined_variables_flag = 0;
- - p = variable_expand ("$(strip $(GPATH))");
- + p = variable_expand (str);
- warn_undefined_variables_flag = save;
- + free(str);
- }
- if (*p != '\0')
Advertisement
Add Comment
Please, Sign In to add comment