> > - If you specify an include file using "-include" option,
> sparse opens it in
> > handle_switch_i()  but does not close it cleanly so for the
> next time the
> > read does not return anything but EOF. I think we should close the fd in
> > sparse_file once the tokenize is done. So here is the diff that I am
> > suggesting.
>
> Looks good, will do.
>

There was a bug in the prev fix as the open() was not called again for
subsequent sparse_file after the close() so I moved the open and close
inside sparse_file() and changed handle_switch_i to cache the name only.
Here is the new diff:

diff --git a/lib.c b/lib.c
--- a/lib.c
+++ b/lib.c
@@ -172,8 +172,7 @@ int Wundefined_preprocessor = 0;
 int Wptr_subtraction_blows = 0;
 int Wtransparent_union = 1;
 int preprocess_only;
-char *include;
-int include_fd = -1;
+char *include=NULL;

 void add_pre_buffer(const char *fmt, ...)
 {
@@ -245,13 +244,7 @@ static char **handle_switch_I(char *arg,
 static char **handle_switch_i(char *arg, char **next)
 {
        if (*next && !strcmp(arg, "include")) {
-               char *name = *++next;
-               int fd = open(name, O_RDONLY);
-
-               include_fd = fd;
-               include = name;
-               if (fd < 0)
-                       perror(name);
+               include = *++next;
        }
        else if (*next && !strcmp(arg, "isystem")) {
                char *path = *++next;
@@ -463,8 +456,13 @@ struct symbol_list *sparse_file(const ch
        close(fd);

        // Prepend any "include" file to the stream.
-       if (include_fd >= 0)
+       if (include) {
+               int include_fd = open(include, O_RDONLY);
+               if (include_fd < 0)
+                       perror(include);
                token = tokenize(include, include_fd, token, includepath);
+               close(include_fd);
+       }

        // Prepend the initial built-in stream
        token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
@@ -543,6 +541,7 @@ struct symbol_list *sparse(int argc, cha
                start_file_scope();
                res = sparse_file(filename);
                end_file_scope();
+
        }
        return res;
 }
diff --git a/lib.h b/lib.h
--- a/lib.h
+++ b/lib.h
@@ -73,7 +73,6 @@ extern void add_pre_buffer(const char *f

 extern unsigned int pre_buffer_size;
 extern unsigned char pre_buffer[8192];
-extern int include_fd;
 extern char *include;
 extern int preprocess_only;
 extern int Wptr_subtraction_blows;




-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to