aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-12-09 10:21:45 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:05:45 -0700
commitfd46a87b9e1d032863c41f54009e5e6386862f8b (patch)
treed9eb25525e6fa4f8fe4f0e7b9ed6a83c8572b23f
parentMake "last_reg" be entry-point global rather than bb-global. (diff)
downloadsparse-fd46a87b9e1d032863c41f54009e5e6386862f8b.tar.gz
sparse-fd46a87b9e1d032863c41f54009e5e6386862f8b.tar.bz2
sparse-fd46a87b9e1d032863c41f54009e5e6386862f8b.zip
Remove stat-based file identity tests.
Replace it with a simple pathname comparison instead. The pathname check is not only portable (no need for any compatibility helper functions), but we can do it much earlier, and thus make the check much cheaper by avoiding three extra system calls when it triggers (open/fstat/close). And the pathname test seems to match all the cases anyway.
-rw-r--r--Makefile4
-rw-r--r--compat-cygwin.c7
-rw-r--r--compat-linux.c1
-rw-r--r--compat-mingw.c26
-rw-r--r--compat-solaris.c2
-rw-r--r--compat.h3
-rw-r--r--compat/id-files-stat.c7
-rw-r--r--lib.c1
-rw-r--r--pre-process.c19
-rw-r--r--token.h2
-rw-r--r--tokenize.c16
11 files changed, 23 insertions, 65 deletions
diff --git a/Makefile b/Makefile
index b6150ae..687d027 100644
--- a/Makefile
+++ b/Makefile
@@ -99,9 +99,9 @@ obfuscate.o: $(LIB_H)
example.o: $(LIB_H)
storage.o: $(LIB_H) storage.h
-compat-linux.o: compat/strtold.c compat/id-files-stat.c compat/mmap-blob.c \
+compat-linux.o: compat/strtold.c compat/mmap-blob.c \
$(LIB_H)
-compat-solaris.o: compat/id-files-stat.c compat/mmap-blob.c $(LIB_H)
+compat-solaris.o: compat/mmap-blob.c $(LIB_H)
compat-mingw.o: $(LIB_H)
compat-cygwin.o: $(LIB_H)
diff --git a/compat-cygwin.c b/compat-cygwin.c
index 7545703..e65b538 100644
--- a/compat-cygwin.c
+++ b/compat-cygwin.c
@@ -37,9 +37,4 @@ void blob_free(void *addr, unsigned long size)
long double string_to_ld(const char *nptr, char **endptr)
{
return strtod(nptr, endptr);
-}
-
-int identical_files(struct stream* s, struct stat *st, const char * name)
-{
- return (s->dev == st->st_dev && s->ino == st->st_ino);
-}
+}
diff --git a/compat-linux.c b/compat-linux.c
index da24ab8..a7a6140 100644
--- a/compat-linux.c
+++ b/compat-linux.c
@@ -3,6 +3,5 @@
#include "lib.h"
#include "allocate.h"
-#include "compat/id-files-stat.c"
#include "compat/mmap-blob.c"
#include "compat/strtold.c"
diff --git a/compat-mingw.c b/compat-mingw.c
index 66456c7..21ca51a 100644
--- a/compat-mingw.c
+++ b/compat-mingw.c
@@ -34,28 +34,4 @@ void blob_free(void *addr, unsigned long size)
long double string_to_ld(const char *nptr, char **endptr)
{
return strtod(nptr, endptr);
-}
-
-int identical_files(struct stream* s, struct stat *st, const char * name)
-{
- HANDLE file1 =CreateFile(s->name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
- if(file1==INVALID_HANDLE_VALUE)
- return 0;
- HANDLE file2=CreateFile(name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
- if(file2==INVALID_HANDLE_VALUE) {
- CloseHandle(file1);
- return 0;
- }
- BY_HANDLE_FILE_INFORMATION info1;
- BY_HANDLE_FILE_INFORMATION info2;
- int same=0;
- if(GetFileInformationByHandle(file1,&info1) && GetFileInformationByHandle(file2,&info2)){
- if(info1.nFileIndexLow==info2.nFileIndexLow &&
- info1.nFileIndexHigh==info2.nFileIndexHigh &&
- info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber)
- same=1;
- }
- CloseHandle(file1);
- CloseHandle(file2);
- return same;
-}
+}
diff --git a/compat-solaris.c b/compat-solaris.c
index 62a7714..7253a89 100644
--- a/compat-solaris.c
+++ b/compat-solaris.c
@@ -1,10 +1,8 @@
#include "lib.h"
#include "allocate.h"
-#include "compat/id-files-stat.c"
#include "compat/mmap-blob.c"
-
#include <floatingpoint.h>
#include <limits.h>
#include <errno.h>
diff --git a/compat.h b/compat.h
index fecfcb1..5713088 100644
--- a/compat.h
+++ b/compat.h
@@ -9,8 +9,6 @@
* Missing in mingw
* - "string to long double" (C99 strtold())
* Missing in Solaris and mingw
- * - checking for file identity (POSIX st_dev && st_ino comparison)
- * mingw needs to check the name (st_dev/st_ino are zero)
*/
struct stream;
struct stat;
@@ -26,6 +24,5 @@ struct stat;
void *blob_alloc(unsigned long size);
void blob_free(void *addr, unsigned long size);
long double string_to_ld(const char *nptr, char **endptr);
-int identical_files(struct stream* s, struct stat *st, const char * name);
#endif
diff --git a/compat/id-files-stat.c b/compat/id-files-stat.c
deleted file mode 100644
index 62f0f57..0000000
--- a/compat/id-files-stat.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "../token.h"
-#include <sys/stat.h>
-
-int identical_files(struct stream* s, struct stat *st, const char * name)
-{
- return s->dev == st->st_dev && s->ino == st->st_ino;
-}
diff --git a/lib.c b/lib.c
index 812e208..55153aa 100644
--- a/lib.c
+++ b/lib.c
@@ -17,7 +17,6 @@
#include <assert.h>
#include <sys/types.h>
-#include <sys/stat.h>
#include "lib.h"
#include "allocate.h"
diff --git a/pre-process.c b/pre-process.c
index 950aea3..0a24f56 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -596,6 +596,23 @@ static const char *token_name_sequence(struct token *token, int endop, struct to
return buffer;
}
+static int already_tokenized(const char *path)
+{
+ int i;
+ struct stream *s = input_streams;
+
+ for (i = input_stream_nr-1; i >= 0; i--, s++) {
+ if (s->constant != CONSTANT_FILE_YES)
+ continue;
+ if (strcmp(path, s->name))
+ continue;
+ if (!lookup_symbol(s->protect, NS_MACRO))
+ continue;
+ return 1;
+ }
+ return 0;
+}
+
static int try_include(const char *path, int plen, const char *filename, int flen, struct token **where, const char **next_path)
{
int fd;
@@ -607,6 +624,8 @@ static int try_include(const char *path, int plen, const char *filename, int fle
plen++;
}
memcpy(fullname+plen, filename, flen);
+ if (already_tokenized(fullname))
+ return 1;
fd = open(fullname, O_RDONLY);
if (fd >= 0) {
char * streamname = __alloc_bytes(plen + flen);
diff --git a/token.h b/token.h
index 3db6bea..2798311 100644
--- a/token.h
+++ b/token.h
@@ -41,8 +41,6 @@ struct stream {
enum constantfile constant;
int nesting;
struct ident *protect;
- dev_t dev;
- ino_t ino;
};
extern int input_stream_nr;
diff --git a/tokenize.c b/tokenize.c
index 98ea9c5..25c79e3 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -14,7 +14,6 @@
#include <string.h>
#include <ctype.h>
#include <unistd.h>
-#include <sys/stat.h>
#include "lib.h"
#include "allocate.h"
@@ -166,7 +165,6 @@ int init_stream(const char *name, int fd, const char **next_path)
{
int stream = input_stream_nr;
struct stream *current;
- struct stat st;
if (stream >= input_streams_allocated) {
int newalloc = stream * 4 / 3 + 10;
@@ -181,20 +179,6 @@ int init_stream(const char *name, int fd, const char **next_path)
current->fd = fd;
current->next_path = next_path;
current->constant = CONSTANT_FILE_MAYBE;
- if (fd >= 0 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
- int i;
-
- for (i = 0; i < stream; i++) {
- struct stream *s = input_streams + i;
- if (s->constant == CONSTANT_FILE_YES &&
- identical_files(s, &st, name) &&
- lookup_symbol(s->protect, NS_MACRO))
- return -1;
- }
-
- current->dev = st.st_dev;
- current->ino = st.st_ino;
- }
input_stream_nr = stream+1;
return stream;
}