mirror of
https://github.com/mirror/make.git
synced 2025-03-29 13:31:09 +08:00
* src/expand.c (swap_variable_buffer): Swap two variable buffers
Return the current buffer instead of freeing it. (variable_append): Use install/swap to handle variable buffers. (allocated_variable_expand_for_file): Ditto. * src/variable.c (shell_result): Ditto. * src/variable.h: Declare the new function.
This commit is contained in:
parent
a367c0640f
commit
f99d083418
99
src/expand.c
99
src/expand.c
@ -83,7 +83,7 @@ initialize_variable_output ()
|
|||||||
{
|
{
|
||||||
/* If we don't have a variable output buffer yet, get one. */
|
/* If we don't have a variable output buffer yet, get one. */
|
||||||
|
|
||||||
if (variable_buffer == 0)
|
if (variable_buffer == NULL)
|
||||||
{
|
{
|
||||||
variable_buffer_length = 200;
|
variable_buffer_length = 200;
|
||||||
variable_buffer = xmalloc (variable_buffer_length);
|
variable_buffer = xmalloc (variable_buffer_length);
|
||||||
@ -93,7 +93,48 @@ initialize_variable_output ()
|
|||||||
|
|
||||||
return variable_buffer;
|
return variable_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Install a new variable_buffer context, returning the current one for
|
||||||
|
safe-keeping. */
|
||||||
|
|
||||||
|
void
|
||||||
|
install_variable_buffer (char **bufp, size_t *lenp)
|
||||||
|
{
|
||||||
|
*bufp = variable_buffer;
|
||||||
|
*lenp = variable_buffer_length;
|
||||||
|
|
||||||
|
variable_buffer = NULL;
|
||||||
|
initialize_variable_output ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free the current variable_buffer and restore a previously-saved one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
restore_variable_buffer (char *buf, size_t len)
|
||||||
|
{
|
||||||
|
free (variable_buffer);
|
||||||
|
|
||||||
|
variable_buffer = buf;
|
||||||
|
variable_buffer_length = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Restore a previously-saved variable_buffer context, and return the
|
||||||
|
current one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *
|
||||||
|
swap_variable_buffer (char *buf, size_t len)
|
||||||
|
{
|
||||||
|
char *p = variable_buffer;
|
||||||
|
|
||||||
|
variable_buffer = buf;
|
||||||
|
variable_buffer_length = len;
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Recursively expand V. The returned string is malloc'd. */
|
/* Recursively expand V. The returned string is malloc'd. */
|
||||||
|
|
||||||
static char *allocated_variable_append (const struct variable *v);
|
static char *allocated_variable_append (const struct variable *v);
|
||||||
@ -555,23 +596,15 @@ variable_append (const char *name, size_t length,
|
|||||||
static char *
|
static char *
|
||||||
allocated_variable_append (const struct variable *v)
|
allocated_variable_append (const struct variable *v)
|
||||||
{
|
{
|
||||||
char *val;
|
|
||||||
|
|
||||||
/* Construct the appended variable value. */
|
/* Construct the appended variable value. */
|
||||||
|
char *obuf;
|
||||||
|
size_t olen;
|
||||||
|
|
||||||
char *obuf = variable_buffer;
|
install_variable_buffer (&obuf, &olen);
|
||||||
size_t olen = variable_buffer_length;
|
|
||||||
|
|
||||||
variable_buffer = 0;
|
|
||||||
|
|
||||||
variable_append (v->name, strlen (v->name), current_variable_set_list, 1);
|
variable_append (v->name, strlen (v->name), current_variable_set_list, 1);
|
||||||
|
|
||||||
val = variable_buffer;
|
return swap_variable_buffer (obuf, olen);
|
||||||
|
|
||||||
variable_buffer = obuf;
|
|
||||||
variable_buffer_length = olen;
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Like variable_expand_for_file, but the returned string is malloc'd.
|
/* Like variable_expand_for_file, but the returned string is malloc'd.
|
||||||
@ -580,42 +613,12 @@ allocated_variable_append (const struct variable *v)
|
|||||||
char *
|
char *
|
||||||
allocated_variable_expand_for_file (const char *line, struct file *file)
|
allocated_variable_expand_for_file (const char *line, struct file *file)
|
||||||
{
|
{
|
||||||
char *value;
|
char *obuf;
|
||||||
|
size_t olen;
|
||||||
|
|
||||||
char *obuf = variable_buffer;
|
install_variable_buffer (&obuf, &olen);
|
||||||
size_t olen = variable_buffer_length;
|
|
||||||
|
|
||||||
variable_buffer = 0;
|
variable_expand_for_file (line, file);
|
||||||
|
|
||||||
value = variable_expand_for_file (line, file);
|
return swap_variable_buffer (obuf, olen);
|
||||||
|
|
||||||
variable_buffer = obuf;
|
|
||||||
variable_buffer_length = olen;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Install a new variable_buffer context, returning the current one for
|
|
||||||
safe-keeping. */
|
|
||||||
|
|
||||||
void
|
|
||||||
install_variable_buffer (char **bufp, size_t *lenp)
|
|
||||||
{
|
|
||||||
*bufp = variable_buffer;
|
|
||||||
*lenp = variable_buffer_length;
|
|
||||||
|
|
||||||
variable_buffer = NULL;
|
|
||||||
initialize_variable_output ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Restore a previously-saved variable_buffer setting (free the current one).
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
|
||||||
restore_variable_buffer (char *buf, size_t len)
|
|
||||||
{
|
|
||||||
free (variable_buffer);
|
|
||||||
|
|
||||||
variable_buffer = buf;
|
|
||||||
variable_buffer_length = len;
|
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,10 @@ unsigned int get_path_max (void);
|
|||||||
# define USHRT_MAX 65535
|
# define USHRT_MAX 65535
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIZE_MAX
|
||||||
|
# define SIZE_MAX ((size_t)~(size_t)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Nonzero if the integer type T is signed.
|
/* Nonzero if the integer type T is signed.
|
||||||
Use <= to avoid GCC warnings about always-false expressions. */
|
Use <= to avoid GCC warnings about always-false expressions. */
|
||||||
#define INTEGER_TYPE_SIGNED(t) ((t) -1 <= 0)
|
#define INTEGER_TYPE_SIGNED(t) ((t) -1 <= 0)
|
||||||
|
@ -1272,17 +1272,14 @@ shell_result (const char *p)
|
|||||||
char *buf;
|
char *buf;
|
||||||
size_t len;
|
size_t len;
|
||||||
char *args[2];
|
char *args[2];
|
||||||
char *result;
|
|
||||||
|
|
||||||
install_variable_buffer (&buf, &len);
|
install_variable_buffer (&buf, &len);
|
||||||
|
|
||||||
args[0] = (char *) p;
|
args[0] = (char *) p;
|
||||||
args[1] = NULL;
|
args[1] = NULL;
|
||||||
func_shell_base (variable_buffer, args, 0);
|
func_shell_base (variable_buffer, args, 0);
|
||||||
result = strdup (variable_buffer);
|
|
||||||
|
|
||||||
restore_variable_buffer (buf, len);
|
return swap_variable_buffer (buf, len);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given a variable, a value, and a flavor, define the variable.
|
/* Given a variable, a value, and a flavor, define the variable.
|
||||||
|
@ -121,21 +121,21 @@ extern struct variable *default_goal_var;
|
|||||||
extern struct variable shell_var;
|
extern struct variable shell_var;
|
||||||
|
|
||||||
/* expand.c */
|
/* expand.c */
|
||||||
#ifndef SIZE_MAX
|
char *initialize_variable_output (void);
|
||||||
# define SIZE_MAX ((size_t)~(size_t)0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *variable_buffer_output (char *ptr, const char *string, size_t length);
|
char *variable_buffer_output (char *ptr, const char *string, size_t length);
|
||||||
|
void install_variable_buffer (char **bufp, size_t *lenp);
|
||||||
|
void restore_variable_buffer (char *buf, size_t len);
|
||||||
|
char *swap_variable_buffer (char *buf, size_t len);
|
||||||
|
|
||||||
|
char *variable_expand_string (char *line, const char *string, size_t length);
|
||||||
char *variable_expand (const char *line);
|
char *variable_expand (const char *line);
|
||||||
char *variable_expand_for_file (const char *line, struct file *file);
|
char *variable_expand_for_file (const char *line, struct file *file);
|
||||||
char *allocated_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) \
|
#define allocated_variable_expand(line) \
|
||||||
allocated_variable_expand_for_file (line, (struct file *) 0)
|
allocated_variable_expand_for_file (line, (struct file *) 0)
|
||||||
char *expand_argument (const char *str, const char *end);
|
char *expand_argument (const char *str, const char *end);
|
||||||
char *variable_expand_string (char *line, const char *string, size_t length);
|
char *recursively_expand_for_file (struct variable *v, struct file *file);
|
||||||
char *initialize_variable_output (void);
|
#define recursively_expand(v) recursively_expand_for_file (v, NULL)
|
||||||
void install_variable_buffer (char **bufp, size_t *lenp);
|
|
||||||
void restore_variable_buffer (char *buf, size_t len);
|
|
||||||
|
|
||||||
/* function.c */
|
/* function.c */
|
||||||
int handle_function (char **op, const char **stringp);
|
int handle_function (char **op, const char **stringp);
|
||||||
@ -150,10 +150,6 @@ char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
|
|||||||
char *func_shell_base (char *o, char **argv, int trim_newlines);
|
char *func_shell_base (char *o, char **argv, int trim_newlines);
|
||||||
void shell_completed (int exit_code, int exit_sig);
|
void shell_completed (int exit_code, int exit_sig);
|
||||||
|
|
||||||
/* expand.c */
|
|
||||||
char *recursively_expand_for_file (struct variable *v, struct file *file);
|
|
||||||
#define recursively_expand(v) recursively_expand_for_file (v, NULL)
|
|
||||||
|
|
||||||
/* variable.c */
|
/* variable.c */
|
||||||
struct variable_set_list *create_new_variable_set (void);
|
struct variable_set_list *create_new_variable_set (void);
|
||||||
void free_variable_set (struct variable_set_list *);
|
void free_variable_set (struct variable_set_list *);
|
||||||
|
Loading…
Reference in New Issue
Block a user