Mercurial > hg > index.cgi
annotate lwcc/cpp.h @ 577:e49d24f4a9a5
Correct bug in the object file output code leading to stack corruption
It turns out leaving a pointer to a stack allocated temporary in a
persistent data structure is not conducive to correct program operation.
Undo the export check setup in the object file output sequence so a
pointer to stack allocated memory is not left hanging when the function
returns. This seems to correct at least one mysterious crash bug, and
possibly others.
Thanks to Boisy Pitre for reporting the crash bug that led to this
discovery, as well as a previous crash bug that likely has the same
root cause.
Additional thanks to Ciaran Anscomb whose debugger wielding wizardry
revealed the exact location of this particular bit of unbrilliance.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sat, 03 Aug 2024 14:30:06 -0600 |
parents | 670ea8f90212 |
children |
rev | line source |
---|---|
295 | 1 /* |
2 lwcc/cpp.h | |
3 | |
4 Copyright © 2013 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #ifndef cpp_h_seen___ | |
23 #define cpp_h_seen___ | |
24 | |
25 #include <stdio.h> | |
26 | |
306
b08787e5b9f3
Add include search paths and command line macro definitions
William Astle <lost@l-w.ca>
parents:
304
diff
changeset
|
27 #include <lw_stringlist.h> |
b08787e5b9f3
Add include search paths and command line macro definitions
William Astle <lost@l-w.ca>
parents:
304
diff
changeset
|
28 |
296 | 29 //#include "symbol.h" |
295 | 30 #include "token.h" |
31 | |
32 #define TOKBUFSIZE 32 | |
33 | |
296 | 34 struct expand_e |
35 { | |
36 struct expand_e *next; | |
37 struct symtab_e *s; // symbol table entry of the expanding symbol | |
38 }; | |
39 | |
295 | 40 struct preproc_info |
41 { | |
42 const char *fn; | |
43 FILE *fp; | |
44 struct token *tokqueue; | |
296 | 45 struct token *curtok; |
295 | 46 void (*errorcb)(const char *); |
47 void (*warningcb)(const char *); | |
296 | 48 int eolstate; // internal for use in handling newlines |
49 int lineno; // the current input line number | |
50 int column; // the current input column | |
51 int trigraphs; // nonzero if we're going to handle trigraphs | |
295 | 52 int ra; |
53 int qseen; | |
54 int ungetbufl; | |
55 int ungetbufs; | |
56 int *ungetbuf; | |
57 int unget; | |
58 int eolseen; | |
59 int nlseen; | |
296 | 60 int ppeolseen; // nonzero if we've seen only whitespace (or nothing) since a newline |
61 int skip_level; // nonzero if we're in a false conditional | |
62 int found_level; // nonzero if we're in a true conditional | |
63 int else_level; // for counting #else directives | |
64 int else_skip_level; // ditto | |
65 struct symtab_e *sh; // the preprocessor's symbol table | |
66 struct token *sourcelist; // for expanding a list of tokens | |
67 struct expand_e *expand_list; // record of which macros are currently being expanded | |
298
6112c67728ba
Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
68 char *lexstr; // for lexing a string (token pasting) |
6112c67728ba
Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
69 int lexstrloc; // ditto |
300 | 70 struct preproc_info *n; // next in file stack |
71 struct preproc_info *filestack; // stack of saved files during include | |
308
670ea8f90212
Converted preproc logic to library and moved some utility stuff to lwlib
William Astle <lost@l-w.ca>
parents:
306
diff
changeset
|
72 struct lw_strpool *strpool; |
306
b08787e5b9f3
Add include search paths and command line macro definitions
William Astle <lost@l-w.ca>
parents:
304
diff
changeset
|
73 lw_stringlist_t quotelist; |
b08787e5b9f3
Add include search paths and command line macro definitions
William Astle <lost@l-w.ca>
parents:
304
diff
changeset
|
74 lw_stringlist_t inclist; |
295 | 75 }; |
76 | |
77 extern struct preproc_info *preproc_init(const char *); | |
78 extern struct token *preproc_next_token(struct preproc_info *); | |
296 | 79 extern struct token *preproc_next_processed_token(struct preproc_info *); |
295 | 80 extern void preproc_finish(struct preproc_info *); |
81 extern void preproc_register_error_callback(struct preproc_info *, void (*)(const char *)); | |
82 extern void preproc_register_warning_callback(struct preproc_info *, void (*)(const char *)); | |
83 extern void preproc_throw_error(struct preproc_info *, const char *, ...); | |
84 extern void preproc_throw_warning(struct preproc_info *, const char *, ...); | |
296 | 85 extern void preproc_unget_token(struct preproc_info *, struct token *); |
306
b08787e5b9f3
Add include search paths and command line macro definitions
William Astle <lost@l-w.ca>
parents:
304
diff
changeset
|
86 extern void preproc_add_include(struct preproc_info *, char *, int); |
b08787e5b9f3
Add include search paths and command line macro definitions
William Astle <lost@l-w.ca>
parents:
304
diff
changeset
|
87 extern void preproc_add_macro(struct preproc_info *, char *); |
304
d85d173ba120
Checkpoint lwcc development - preprocessor is runnable but nonfunctional
William Astle <lost@l-w.ca>
parents:
300
diff
changeset
|
88 extern struct token *preproc_next(struct preproc_info *); |
296 | 89 |
295 | 90 #endif // cpp_h_seen___ |