summaryrefslogtreecommitdiff
path: root/remake.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2007-03-20 03:02:26 +0000
committerPaul Smith <psmith@gnu.org>2007-03-20 03:02:26 +0000
commit6ccf33cdbdfda2aea5d51e4d4991881c74d853d1 (patch)
treece963770c6d0dc0428a6bce65d96da4b710e2831 /remake.c
parente4da30858037b431880263676e8f90b1f8412a38 (diff)
downloadgunmake-6ccf33cdbdfda2aea5d51e4d4991881c74d853d1.tar.gz
This is a major update, which switches virtually every allocated-but-not-freed
string into the strcache. As a side-effect, many more structure members and function arguments can/should be declared const. As mentioned in the changelog, unfortunately measurement shows that this change does not yet reduce memory. The problem is with secondary expansion: because of this we store all the prerequisites in the string cache twice. First we store the prerequisite string after initial expansion but before secondary expansion, then we store each individual file after secondary expansion and expand_deps(). I plan to change expand_deps() to be callable in either context (eval or snap_deps) then have non-second-expansion targets call expand_deps() during eval, so that we only need to store that dependency list once.
Diffstat (limited to 'remake.c')
-rw-r--r--remake.c67
1 files changed, 25 insertions, 42 deletions
diff --git a/remake.c b/remake.c
index ea6e555..ee8acf3 100644
--- a/remake.c
+++ b/remake.c
@@ -66,8 +66,8 @@ static int check_dep (struct file *file, unsigned int depth,
FILE_TIMESTAMP this_mtime, int *must_make_ptr);
static int touch_file (struct file *file);
static void remake_file (struct file *file);
-static FILE_TIMESTAMP name_mtime (char *name);
-static int library_search (char **lib, FILE_TIMESTAMP *mtime_ptr);
+static FILE_TIMESTAMP name_mtime (const char *name);
+static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
/* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
@@ -913,7 +913,7 @@ notice_finished_file (struct file *file)
We do this instead of just invalidating the cached time
so that a vpath_search can happen. Otherwise, it would
never be done because the target is already updated. */
- (void) f_mtime (d->file, 0);
+ f_mtime (d->file, 0);
}
else if (file->update_status == -1)
/* Nothing was done for FILE, but it needed nothing done.
@@ -1152,7 +1152,6 @@ f_mtime (struct file *file, int search)
char *arname, *memname;
struct file *arfile;
- int arname_used = 0;
time_t member_date;
/* Find the archive's name. */
@@ -1162,10 +1161,7 @@ f_mtime (struct file *file, int search)
Also allow for its name to be changed via VPATH search. */
arfile = lookup_file (arname);
if (arfile == 0)
- {
- arfile = enter_file (arname);
- arname_used = 1;
- }
+ arfile = enter_file (strcache_add (arname));
mtime = f_mtime (arfile, search);
check_renamed (arfile);
if (search && strcmp (arfile->hname, arname))
@@ -1176,20 +1172,11 @@ f_mtime (struct file *file, int search)
char *name;
unsigned int arlen, memlen;
- if (!arname_used)
- {
- free (arname);
- arname_used = 1;
- }
-
- arname = arfile->hname;
- arlen = strlen (arname);
+ arlen = strlen (arfile->hname);
memlen = strlen (memname);
- /* free (file->name); */
-
name = xmalloc (arlen + 1 + memlen + 2);
- memcpy (name, arname, arlen);
+ memcpy (name, arfile->hname, arlen);
name[arlen] = '(';
memcpy (name + arlen + 1, memname, memlen);
name[arlen + 1 + memlen] = ')';
@@ -1204,9 +1191,7 @@ f_mtime (struct file *file, int search)
check_renamed (file);
}
- if (!arname_used)
- free (arname);
- free (memname);
+ free (arname);
file->low_resolution_time = 1;
@@ -1227,11 +1212,11 @@ f_mtime (struct file *file, int search)
if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
{
/* If name_mtime failed, search VPATH. */
- char *name = file->name;
- if (vpath_search (&name, &mtime)
+ const char *name = vpath_search (file->name, &mtime);
+ if (name
/* Last resort, is it a library (-lxxx)? */
- || (name[0] == '-' && name[1] == 'l'
- && library_search (&name, &mtime)))
+ || (file->name[0] == '-' && file->name[1] == 'l'
+ && (name = library_search (file->name, &mtime)) != 0))
{
if (mtime != UNKNOWN_MTIME)
/* vpath_search and library_search store UNKNOWN_MTIME
@@ -1350,7 +1335,7 @@ f_mtime (struct file *file, int search)
much cleaner. */
static FILE_TIMESTAMP
-name_mtime (char *name)
+name_mtime (const char *name)
{
FILE_TIMESTAMP mtime;
struct stat st;
@@ -1444,8 +1429,8 @@ name_mtime (char *name)
suitable library file in the system library directories and the VPATH
directories. */
-static int
-library_search (char **lib, FILE_TIMESTAMP *mtime_ptr)
+static const char *
+library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
{
static char *dirs[] =
{
@@ -1466,14 +1451,15 @@ library_search (char **lib, FILE_TIMESTAMP *mtime_ptr)
static char *libpatterns = NULL;
- char *libname = &(*lib)[2]; /* Name without the `-l'. */
+ const char *libname = lib+2; /* Name without the '-l'. */
FILE_TIMESTAMP mtime;
/* Loop variables for the libpatterns value. */
- char *p, *p2;
+ char *p;
+ const char *p2;
unsigned int len;
- char *file, **dp;
+ char **dp;
/* If we don't have libpatterns, get it. */
if (!libpatterns)
@@ -1522,20 +1508,18 @@ library_search (char **lib, FILE_TIMESTAMP *mtime_ptr)
mtime = name_mtime (libbuf);
if (mtime != NONEXISTENT_MTIME)
{
- *lib = xstrdup (libbuf);
if (mtime_ptr != 0)
*mtime_ptr = mtime;
- return 1;
+ return strcache_add (libbuf);
}
/* Now try VPATH search on that. */
- file = libbuf;
- if (vpath_search (&file, mtime_ptr))
- {
- *lib = file;
- return 1;
- }
+ {
+ const char *file = vpath_search (libbuf, mtime_ptr);
+ if (file)
+ return file;
+ }
/* Now try the standard set of directories. */
@@ -1562,10 +1546,9 @@ library_search (char **lib, FILE_TIMESTAMP *mtime_ptr)
mtime = name_mtime (buf);
if (mtime != NONEXISTENT_MTIME)
{
- *lib = xstrdup (buf);
if (mtime_ptr != 0)
*mtime_ptr = mtime;
- return 1;
+ return strcache_add (buf);
}
}
}