cpplib: Remove _cpp_fake_include
Neil Booth
neilb@earthling.net
Wed Dec 6 13:07:00 GMT 2000
I can't for the life of me see what this routine achieves, apart from
rescuing a memory leak. Besides, it's getting in the way. I'm going
to remove it and see if anything breaks.
This is the first part of a tidy up to cpp_buffer handling both inside
and outside cpplib. There are too many assumptions being made, in
many cases incorrectly.
The eventual outcome should be a cure for Jason's #line problems (in
fact I believe this patch will already solve one of those), produce a
buffer stack in cpplib even when reading a preprocessed file, and
hopefully solve Robert's system header problem. It should also fix a
couple of not-yet-noticed bugs, and make #line handling robust.
Oh, and no-one had noticed that the definition of parse_in in
c-common.c has been wrong for weeks. Why doesn't the linker warn?
Neil.
* c-common.c (parse_in): Make a cpp_reader *.
* cppfiles.c (_cpp_fake_include): Remove.
* cpphash.h: Similarly.
* cpplib.c (do_line): Don't call _cpp_fake_include. A valid
#line always creates a callback; FC_RENAME if there are no
#line flags.
* fix-header.c (read_scan_file): cpp_push_buffer cannot fail.
The first EOF must be our get_char buffer.
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.202
diff -u -p -r1.202 c-common.c
--- c-common.c 2000/12/03 03:46:03 1.202
+++ c-common.c 2000/12/06 21:05:33
@@ -36,7 +36,7 @@ Boston, MA 02111-1307, USA. */
#include "diagnostic.h"
#include "obstack.h"
#include "cpplib.h"
-cpp_reader parse_in;
+cpp_reader *parse_in; /* Declared in c-lex.h. */
#undef WCHAR_TYPE_SIZE
#define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.88
diff -u -p -r1.88 cppfiles.c
--- cppfiles.c 2000/12/05 23:42:43 1.88
+++ cppfiles.c 2000/12/06 21:05:35
@@ -474,50 +474,6 @@ find_include_file (pfile, fname, search_
return 0;
}
-/* #line uses this to save artificial file names. We have to stat the
- file because an all_include_files entry is always either + or -,
- there's no 'I don't know' value. */
-const char *
-_cpp_fake_include (pfile, fname)
- cpp_reader *pfile;
- const char *fname;
-{
- splay_tree_node nd;
- struct include_file *file;
- char *name;
-
- file = find_include_file (pfile, fname, CPP_OPTION (pfile, quote_include));
- if (file)
- {
- if (file->fd > 0)
- {
- close (file->fd);
- file->fd = -1;
- }
- return file->name;
- }
-
- name = xstrdup (fname);
- _cpp_simplify_pathname (name);
-
- /* We cannot just blindly insert a node, because there's still the
- chance that the node already exists but isn't on the search path. */
- nd = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) name);
- if (nd)
- {
- free (name);
- return (const char *) nd->key;
- }
-
- file = xcnew (struct include_file);
- file->name = name;
- file->fd = -2;
- splay_tree_insert (pfile->all_include_files, (splay_tree_key) name,
- (splay_tree_value) file);
-
- return file->name;
-}
-
/* Not everyone who wants to set system-header-ness on a buffer can
see the details of struct include_file. This is an exported interface
because fix-header needs it. */
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.83
diff -u -p -r1.83 cpphash.h
--- cpphash.h 2000/12/04 07:32:04 1.83
+++ cpphash.h 2000/12/06 21:05:35
@@ -233,7 +233,6 @@ extern int _cpp_compare_file_date
extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
extern void _cpp_init_includes PARAMS ((cpp_reader *));
extern void _cpp_cleanup_includes PARAMS ((cpp_reader *));
-extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *));
/* In cppexp.c */
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.227
diff -u -p -r1.227 cpplib.c
--- cpplib.c 2000/12/05 23:42:43 1.227
+++ cpplib.c 2000/12/06 21:05:44
@@ -721,7 +721,7 @@ do_line (pfile)
cpp_buffer *buffer = pfile->buffer;
const char *filename = buffer->nominal_fname;
unsigned int lineno = buffer->lineno;
- enum cpp_fc_reason reason = (enum cpp_fc_reason) -1;
+ enum cpp_fc_reason reason = FC_RENAME;
unsigned long new_lineno;
unsigned int cap;
cpp_token token;
@@ -749,19 +749,14 @@ do_line (pfile)
unsigned int len;
int action_number = 0;
+ /* FIXME: memory leak. */
len = token.val.str.len;
- fname = alloca (len + 1);
+ fname = xmalloc (len + 1);
memcpy (fname, token.val.str.text, len);
fname[len] = '\0';
- if (strcmp (fname, buffer->nominal_fname))
- {
- reason = FC_RENAME;
- if (!strcmp (fname, buffer->inc->name))
- buffer->nominal_fname = buffer->inc->name;
- else
- buffer->nominal_fname = _cpp_fake_include (pfile, fname);
- }
+ _cpp_simplify_pathname (fname);
+ buffer->nominal_fname = fname;
if (read_line_number (pfile, &action_number) != 0)
{
@@ -803,8 +798,7 @@ do_line (pfile)
/* Our line number is incremented after the directive is processed. */
buffer->lineno = new_lineno - 1;
- if (reason != (enum cpp_fc_reason) -1)
- _cpp_do_file_change (pfile, reason, filename, lineno);
+ _cpp_do_file_change (pfile, reason, filename, lineno);
}
/* Arrange the file_change callback. The assumption is that the
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.55
diff -u -p -r1.55 fix-header.c
--- fix-header.c 2000/12/04 07:32:04 1.55
+++ fix-header.c 2000/12/06 21:05:48
@@ -649,26 +649,21 @@ read_scan_file (in_fname, argc, argv)
{
static const unsigned char getchar_call[] = "getchar();";
int seen_filbuf = 0;
- cpp_buffer *buf = CPP_BUFFER (scan_in);
- if (cpp_push_buffer (scan_in, getchar_call,
- sizeof(getchar_call) - 1) == NULL)
- return;
/* Scan the macro expansion of "getchar();". */
+ cpp_push_buffer (scan_in, getchar_call, sizeof(getchar_call) - 1);
for (;;)
{
cpp_token t;
cpp_get_token (scan_in, &t);
if (t.type == CPP_EOF)
- {
- cpp_pop_buffer (scan_in);
- if (CPP_BUFFER (scan_in) == buf)
- break;
- }
+ break;
else if (cpp_ideq (&t, "_filbuf"))
seen_filbuf++;
}
+ cpp_pop_buffer (scan_in);
+
if (seen_filbuf)
{
int need_filbuf = !SEEN (fn) && !REQUIRED (fn);
More information about the Gcc-patches
mailing list