diff options
author | borutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423> | 2009-04-28 17:29:31 +0000 |
---|---|---|
committer | borutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423> | 2009-04-28 17:29:31 +0000 |
commit | 2ec965f8b4ec0c6e9fa87fad32ffcd775d0995bf (patch) | |
tree | 15f912b340aebe3c12e678283015112ee0fddde5 /support/cpp/libcpp/files.c | |
parent | fdbef79070d96a1d526e490132b6a33a3046d974 (diff) |
* support/cpp/output.h, support/cpp/opts-common.c,
support/cpp/c-ppoutput.c, support/cpp/cppdefault.c,
support/cpp/system.h, support/cpp/cppdefault.h,
support/cpp/prefix.c, support/cpp/except.h, support/cpp/hwint.h,
support/cpp/prefix.h, support/cpp/libiberty/safe-ctype.h,
support/cpp/libiberty/filenames.h, support/cpp/libiberty/xstrdup.c,
support/cpp/libiberty/md5.c, support/cpp/libiberty/obstack.h,
support/cpp/sdcpp.c, support/cpp/intl.h, support/cpp/sdcpp.h
support/cpp/libcpp/symtab.c, support/cpp/libcpp/directives.c,
support/cpp/libcpp/macro.c, support/cpp/libcpp/include/cpplib.h,
support/cpp/libcpp/include/symtab.h,
support/cpp/libcpp/include/line-map.h,
support/cpp/libcpp/include/cpp-id-data.h,
support/cpp/libcpp/include/mkdeps.h, support/cpp/libcpp/files.c,
support/cpp/libcpp/line-map.c, support/cpp/libcpp/init.c,
support/cpp/libcpp/identifiers.c, support/cpp/libcpp/ucnid.h,
support/cpp/libcpp/traditional.c, support/cpp/libcpp/errors.c,
support/cpp/libcpp/expr.c, support/cpp/libcpp/internal.h,
support/cpp/libcpp/mkdeps.c, support/cpp/libcpp/lex.c,
support/cpp/libcpp/system.h, support/cpp/libcpp/charset.c,
support/cpp/opts.h, support/cpp/sdcpp-opts.c:
SDCPP synchronized with GCC CPP release version 4.4.0
git-svn-id: https://svn.code.sourceforge.net/p/sdcc/code/trunk/sdcc@5444 4a8a32a2-be11-0410-ad9d-d568d2c75423
Diffstat (limited to 'support/cpp/libcpp/files.c')
-rw-r--r-- | support/cpp/libcpp/files.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/support/cpp/libcpp/files.c b/support/cpp/libcpp/files.c index 469a73af0..615b6ab29 100644 --- a/support/cpp/libcpp/files.c +++ b/support/cpp/libcpp/files.c @@ -1,6 +1,6 @@ /* Part of CPP library. File handling. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 @@ -10,7 +10,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -19,8 +19,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ #include "config.h" #include "system.h" @@ -74,6 +74,10 @@ struct _cpp_file /* The contents of NAME after calling read_file(). */ const uchar *buffer; + /* Pointer to the real start of BUFFER. read_file() might increment + BUFFER; when freeing, this this pointer must be used instead. */ + const uchar *buffer_start; + /* The macro, if any, preventing re-inclusion. */ const cpp_hashnode *cmacro; @@ -106,9 +110,6 @@ struct _cpp_file /* If BUFFER above contains the true contents of the file. */ bool buffer_valid; - - /* File is a PCH (on return from find_include_file). */ - bool pch; }; /* A singly-linked list for all searches for a given file name, with @@ -322,9 +323,7 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch) } closedir (pchdir); } - if (valid) - file->pch = true; - else + if (!valid) *invalid_pch = true; } @@ -602,7 +601,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) type. Use INTTYPE_MAXIMUM unconditionally to ensure this does not bite us. */ #ifndef __BORLANDC__ - if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t)) + if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t)) { cpp_error (pfile, CPP_DL_ERROR, "%s is too large", file->path); return false; @@ -651,8 +650,11 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) "%s is shorter than expected", file->path); #endif - file->buffer = _cpp_convert_input (pfile, CPP_OPTION (pfile, input_charset), - buf, size, total, &file->st.st_size); + file->buffer = _cpp_convert_input (pfile, + CPP_OPTION (pfile, input_charset), + buf, size, total, + &file->buffer_start, + &file->st.st_size); file->buffer_valid = true; return true; @@ -714,11 +716,12 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import) return false; /* Handle PCH files immediately; don't stack them. */ - if (file->pch) + if (file->pchname) { pfile->cb.read_pch (pfile, file->pchname, file->fd, file->path); - close (file->fd); file->fd = -1; + free ((void *) file->pchname); + file->pchname = NULL; return false; } @@ -927,10 +930,10 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we found a PCH file (in which case linemap_add is not called) or we were included from the command-line. */ - if (! file->pch && file->err_no == 0 && type != IT_CMDLINE) + if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE) pfile->line_table->highest_location--; - return _cpp_stack_file (pfile, file, type == IT_IMPORT); + return _cpp_stack_file (pfile, file, (bool)(type == IT_IMPORT)); } /* Could not open FILE. The complication is dependency output. */ @@ -984,8 +987,8 @@ make_cpp_file (cpp_reader *pfile, cpp_dir *dir, const char *fname) static void destroy_cpp_file (_cpp_file *file) { - if (file->buffer) - free ((void *) file->buffer); + if (file->buffer_start) + free ((void *) file->buffer_start); free ((void *) file->name); free (file); } @@ -1350,9 +1353,10 @@ _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file) /* Invalidate control macros in the #including file. */ pfile->mi_valid = false; - if (file->buffer) + if (file->buffer_start) { - free ((void *) file->buffer); + free ((void *) file->buffer_start); + file->buffer_start = NULL; file->buffer = NULL; file->buffer_valid = false; } |