History

tccpp: cleanup

- "utf8 in identifiers" from 936819a1b90f2618bb3f86730189cf2895948ba0 - CValue: remove member str.data_allocated - make tiny allocator private to tccpp - allocate macro_stack objects on heap because otherwise it could crash after error/setjmp in preprocess_delete():end_macro() - mov "TinyAlloc" defs to tccpp.c - define_push: take int* str again

grischka committed 10 years ago

Commit 766ba361 parent eacdc425 files · +169 −184Browse files

Unified · Split

5 files
  1. libtcc.c +0 −2
  2. tcc.h +48 −93
  3. tccasm.c +7 −7
  4. tccgen.c +13 −13
  5. tccpp.c +101 −69
libtcc.c+0−2
@@ -2199,8 +2199,6 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 2198 unmodified lines
21992199 s->dflag = 3;
22002200 else if (*optarg == 'M')
22012201 s->dflag = 7;
2202− else if (*optarg == 'b')
2203− s->dflag = 8;
22042202 else
22052203 goto unsupported_option;
22062204 break;
tcc.h+48−93
@@ -36,13 +36,6 @@ · 35 unmodified lines
3636 #include <time.h>
3737 #include <sys/stat.h> /* stat() */
3838
39−#ifdef CONFIG_TCCASSERT
40−#include <assert.h>
41−#define TCC_ASSERT(ex) assert(ex)
42−#else
43−#define TCC_ASSERT(ex)
44−#endif
45−
4639 #ifndef _WIN32
4740 # include <unistd.h>
4841 # include <sys/time.h>
@@ -138,51 +131,6 @@ · 89 unmodified lines
138131 #include "stab.h"
139132 #include "libtcc.h"
140133
141−static inline uint16_t read16le(unsigned char *p)
142−{
143− return p[0] | (uint16_t)p[1] << 8;
144−}
145−
146−static inline void write16le(unsigned char *p, uint16_t x)
147−{
148− p[0] = x & 255;
149− p[1] = x >> 8 & 255;
150−}
151−
152−static inline uint32_t read32le(unsigned char *p)
153−{
154− return (p[0] | (uint32_t)p[1] << 8 |
155− (uint32_t)p[2] << 16 | (uint32_t)p[3] << 24);
156−}
157−
158−static inline void write32le(unsigned char *p, uint32_t x)
159−{
160− p[0] = x & 255;
161− p[1] = x >> 8 & 255;
162− p[2] = x >> 16 & 255;
163− p[3] = x >> 24 & 255;
164−}
165−
166−static inline uint64_t read64le(unsigned char *p)
167−{
168− return (p[0] | (uint64_t)p[1] << 8 |
169− (uint64_t)p[2] << 16 | (uint64_t)p[3] << 24 |
170− (uint64_t)p[4] << 32 | (uint64_t)p[5] << 40 |
171− (uint64_t)p[6] << 48 | (uint64_t)p[7] << 56);
172−}
173−
174−static inline void write64le(unsigned char *p, uint64_t x)
175−{
176− p[0] = x & 255;
177− p[1] = x >> 8 & 255;
178− p[2] = x >> 16 & 255;
179− p[3] = x >> 24 & 255;
180− p[4] = x >> 32 & 255;
181− p[5] = x >> 40 & 255;
182− p[6] = x >> 48 & 255;
183− p[7] = x >> 56 & 255;
184−}
185−
186134 /* parser debug */
187135 /* #define PARSE_DEBUG */
188136 /* preprocessor debug */
@@ -399,7 +347,6 @@ typedef struct CString { · 210 unmodified lines
399347 int size; /* size in bytes */
400348 void *data; /* either 'char *' or 'nwchar_t *' */
401349 int size_allocated;
402− void *data_allocated; /* if non NULL, data has been malloced */
403350 } CString;
404351
405352 /* type definition */
@@ -417,7 +364,6 @@ typedef union CValue { · 11 unmodified lines
417364 struct {
418365 int size;
419366 const void *data;
420− void *data_allocated;
421367 } str;
422368 int tab[LDOUBLE_SIZE/4];
423369 } CValue;
@@ -638,43 +584,6 @@ struct sym_attr { · 214 unmodified lines
638584 #endif
639585 };
640586
641−#if !defined(MEM_DEBUG)
642−#define tal_free(al, p) tal_free_impl(al, p)
643−#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size)
644−#define TAL_DEBUG_PARAMS
645−#else
646−#define TAL_DEBUG 1
647−#define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__)
648−#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__)
649−#define TAL_DEBUG_PARAMS , const char *file, int line
650−#define TAL_DEBUG_FILE_LEN 15
651−#endif
652−//#define TAL_INFO 1 /* collect and dump allocators stats */
653−
654−typedef struct TinyAlloc {
655− size_t limit;
656− size_t size;
657− uint8_t *buffer;
658− uint8_t *p;
659− size_t nb_allocs;
660− struct TinyAlloc *next, *top;
661−#ifdef TAL_INFO
662− size_t nb_peak;
663− size_t nb_total;
664− size_t nb_missed;
665− uint8_t *peak_p;
666−#endif
667−} TinyAlloc;
668−
669−typedef struct tal_header_t {
670− size_t size;
671−#ifdef TAL_DEBUG
672− int line_num; /* negative line_num used for double free check */
673− char file_name[TAL_DEBUG_FILE_LEN + 1];
674−#endif
675−} tal_header_t;
676−
677−
678587 struct TCCState {
679588
680589 int verbose; /* if true, display some information during compilation */
@@ -1204,7 +1113,7 @@ PUB_FUNC void tcc_warning(const char *fmt, ...); · 523 unmodified lines
12041113 /* other utilities */
12051114 ST_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data);
12061115 ST_FUNC void dynarray_reset(void *pp, int *n);
1207−ST_FUNC void cstr_ccat(CString *cstr, int ch);
1116+ST_INLN void cstr_ccat(CString *cstr, int ch);
12081117 ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
12091118 ST_FUNC void cstr_wccat(CString *cstr, int ch);
12101119 ST_FUNC void cstr_new(CString *cstr);
@@ -1287,10 +1196,11 @@ ST_FUNC void end_macro(void); · 76 unmodified lines
12871196 ST_FUNC void save_parse_state(ParseState *s);
12881197 ST_FUNC void restore_parse_state(ParseState *s);
12891198 ST_INLN void tok_str_new(TokenString *s);
1199+ST_FUNC TokenString *tok_str_alloc(void);
12901200 ST_FUNC void tok_str_free(int *str);
12911201 ST_FUNC void tok_str_add(TokenString *s, int t);
12921202 ST_FUNC void tok_str_add_tok(TokenString *s);
1293−ST_INLN void define_push(int v, int macro_type, TokenString *str, Sym *first_arg);
1203+ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
12941204 ST_FUNC void define_undef(Sym *s);
12951205 ST_INLN Sym *define_find(int v);
12961206 ST_FUNC void free_defines(Sym *b);
@@ -1489,6 +1399,51 @@ ST_FUNC void gen_vla_sp_save(int addr); · 192 unmodified lines
14891399 ST_FUNC void gen_vla_sp_restore(int addr);
14901400 ST_FUNC void gen_vla_alloc(CType *type, int align);
14911401
1402+static inline uint16_t read16le(unsigned char *p)
1403+{
1404+ return p[0] | (uint16_t)p[1] << 8;
1405+}
1406+
1407+static inline void write16le(unsigned char *p, uint16_t x)
1408+{
1409+ p[0] = x & 255;
1410+ p[1] = x >> 8 & 255;
1411+}
1412+
1413+static inline uint32_t read32le(unsigned char *p)
1414+{
1415+ return (p[0] | (uint32_t)p[1] << 8 |
1416+ (uint32_t)p[2] << 16 | (uint32_t)p[3] << 24);
1417+}
1418+
1419+static inline void write32le(unsigned char *p, uint32_t x)
1420+{
1421+ p[0] = x & 255;
1422+ p[1] = x >> 8 & 255;
1423+ p[2] = x >> 16 & 255;
1424+ p[3] = x >> 24 & 255;
1425+}
1426+
1427+static inline uint64_t read64le(unsigned char *p)
1428+{
1429+ return (p[0] | (uint64_t)p[1] << 8 |
1430+ (uint64_t)p[2] << 16 | (uint64_t)p[3] << 24 |
1431+ (uint64_t)p[4] << 32 | (uint64_t)p[5] << 40 |
1432+ (uint64_t)p[6] << 48 | (uint64_t)p[7] << 56);
1433+}
1434+
1435+static inline void write64le(unsigned char *p, uint64_t x)
1436+{
1437+ p[0] = x & 255;
1438+ p[1] = x >> 8 & 255;
1439+ p[2] = x >> 16 & 255;
1440+ p[3] = x >> 24 & 255;
1441+ p[4] = x >> 32 & 255;
1442+ p[5] = x >> 40 & 255;
1443+ p[6] = x >> 48 & 255;
1444+ p[7] = x >> 56 & 255;
1445+}
1446+
14921447 /* ------------ i386-gen.c ------------ */
14931448 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
14941449 ST_FUNC void g(int c);
tccasm.c+7−7
@@ -488,25 +488,25 @@ static void asm_parse_directive(TCCState *s1) · 487 unmodified lines
488488 case TOK_ASMDIR_rept:
489489 {
490490 int repeat;
491− TokenString init_str;
491+ TokenString *init_str;
492492 ParseState saved_parse_state = {0};
493493 next();
494494 repeat = asm_int_expr(s1);
495− tok_str_new(&init_str);
495+ init_str = tok_str_alloc();
496496 next();
497497 while ((tok != TOK_ASMDIR_endr) && (tok != CH_EOF)) {
498− tok_str_add_tok(&init_str);
498+ tok_str_add_tok(init_str);
499499 next();
500500 }
501501 if (tok == CH_EOF) tcc_error("we at end of file, .endr not found");
502502 next();
503− tok_str_add(&init_str, -1);
504− tok_str_add(&init_str, 0);
503+ tok_str_add(init_str, -1);
504+ tok_str_add(init_str, 0);
505505 save_parse_state(&saved_parse_state);
506− begin_macro(&init_str, 0);
506+ begin_macro(init_str, 1);
507507 while (repeat-- > 0) {
508508 tcc_assemble_internal(s1, (parse_flags & PARSE_FLAG_PREPROCESS));
509− macro_ptr = init_str.str;
509+ macro_ptr = init_str->str;
510510 }
511511 end_macro();
512512 restore_parse_state(&saved_parse_state);
tccgen.c+13−13
@@ -5857,7 +5857,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 5856 unmodified lines
58575857 int size, align, addr, data_offset;
58585858 int level;
58595859 ParseState saved_parse_state = {0};
5860− TokenString init_str;
5860+ TokenString *init_str = NULL;
58615861 Section *sec;
58625862 Sym *flexible_array;
58635863
@@ -5879,15 +5879,15 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 15 unmodified lines
58795879 (e.g. string pointers or ISOC99 compound
58805880 literals). It also simplifies local
58815881 initializers handling */
5882− tok_str_new(&init_str);
58835882 if (size < 0 || (flexible_array && has_init)) {
58845883 if (!has_init)
58855884 tcc_error("unknown type size");
58865885 /* get all init string */
5886+ init_str = tok_str_alloc();
58875887 if (has_init == 2) {
58885888 /* only get strings */
58895889 while (tok == TOK_STR || tok == TOK_LSTR) {
5890− tok_str_add_tok(&init_str);
5890+ tok_str_add_tok(init_str);
58915891 next();
58925892 }
58935893 } else {
@@ -5895,7 +5895,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 1 unmodified line
58955895 while (level > 0 || (tok != ',' && tok != ';')) {
58965896 if (tok < 0)
58975897 tcc_error("unexpected end of file in initializer");
5898− tok_str_add_tok(&init_str);
5898+ tok_str_add_tok(init_str);
58995899 if (tok == '{')
59005900 level++;
59015901 else if (tok == '}') {
@@ -5908,17 +5908,17 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 6 unmodified lines
59085908 next();
59095909 }
59105910 }
5911− tok_str_add(&init_str, -1);
5912− tok_str_add(&init_str, 0);
5911+ tok_str_add(init_str, -1);
5912+ tok_str_add(init_str, 0);
59135913
59145914 /* compute size */
59155915 save_parse_state(&saved_parse_state);
59165916
5917− begin_macro(&init_str, 0);
5917+ begin_macro(init_str, 1);
59185918 next();
59195919 decl_initializer(type, NULL, 0, 1, 1);
59205920 /* prepare second initializer parsing */
5921− macro_ptr = init_str.str;
5921+ macro_ptr = init_str->str;
59225922 next();
59235923
59245924 /* if still unknown size, error */
@@ -6076,17 +6076,17 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 151 unmodified lines
60766076 }
60776077 if (has_init || (type->t & VT_VLA)) {
60786078 decl_initializer(type, sec, addr, 1, 0);
6079− /* restore parse state if needed */
6080− if (init_str.str) {
6081− end_macro();
6082− restore_parse_state(&saved_parse_state);
6083− }
60846079 /* patch flexible array member size back to -1, */
60856080 /* for possible subsequent similar declarations */
60866081 if (flexible_array)
60876082 flexible_array->type.ref->c = -1;
60886083 }
60896084 no_alloc: ;
6085+ /* restore parse state if needed */
6086+ if (init_str) {
6087+ end_macro();
6088+ restore_parse_state(&saved_parse_state);
6089+ }
60906090 }
60916091
60926092 static void put_func_debug(Sym *sym)
tccpp.c+101−69
@@ -38,10 +38,6 @@ ST_DATA int total_bytes; · 37 unmodified lines
3838 ST_DATA int tok_ident;
3939 ST_DATA TokenSym **table_ident;
4040
41−ST_DATA TinyAlloc *toksym_alloc;
42−ST_DATA TinyAlloc *tokstr_alloc;
43−ST_DATA TinyAlloc *cstr_alloc;
44−
4541 /* ------------------------------------------------------------------------- */
4642
4743 static TokenSym *hash_ident[TOK_HASH_SIZE];
@@ -53,6 +49,10 @@ static int pp_debug_tok, pp_debug_symv; · 5 unmodified lines
5349 static int pp_once;
5450 static void tok_print(const char *msg, const int *str);
5551
52+static struct TinyAlloc *toksym_alloc;
53+static struct TinyAlloc *tokstr_alloc;
54+static struct TinyAlloc *cstr_alloc;
55+
5656 /* isidnum_table flags: */
5757 #define IS_SPC 1
5858 #define IS_ID 2
@@ -110,31 +110,54 @@ ST_FUNC void expect(const char *msg) · 51 unmodified lines
110110 tcc_error("%s expected", msg);
111111 }
112112
113−ST_FUNC void begin_macro(TokenString *str, int alloc)
114−{
115− str->alloc = alloc;
116− str->prev = macro_stack;
117− str->prev_ptr = macro_ptr;
118− macro_ptr = str->str;
119− macro_stack = str;
120−}
113+/* ------------------------------------------------------------------------- */
114+/* Custom allocator for tiny objects */
121115
122−ST_FUNC void end_macro(void)
123−{
124− TokenString *str = macro_stack;
125− macro_stack = str->prev;
126− macro_ptr = str->prev_ptr;
127− if (str->alloc == 2) {
128− str->alloc = 3; /* just mark as finished */
129− } else {
130− tok_str_free(str->str);
131− if (str->alloc == 1)
132− tcc_free(str);
133− }
134−}
116+#define USE_TAL
117+
118+#ifndef USE_TAL
119+#define tal_free(al, p) tcc_free(p)
120+#define tal_realloc(al, p, size) tcc_realloc(p, size)
121+#define tal_new(a,b,c)
122+#define tal_delete(a)
123+#else
124+#if !defined(MEM_DEBUG)
125+#define tal_free(al, p) tal_free_impl(al, p)
126+#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size)
127+#define TAL_DEBUG_PARAMS
128+#else
129+#define TAL_DEBUG 1
130+#define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__)
131+#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__)
132+#define TAL_DEBUG_PARAMS , const char *file, int line
133+#define TAL_DEBUG_FILE_LEN 15
134+#endif
135+//#define TAL_INFO 1 /* collect and dump allocators stats */
136+
137+typedef struct TinyAlloc {
138+ size_t limit;
139+ size_t size;
140+ uint8_t *buffer;
141+ uint8_t *p;
142+ size_t nb_allocs;
143+ struct TinyAlloc *next, *top;
144+#ifdef TAL_INFO
145+ size_t nb_peak;
146+ size_t nb_total;
147+ size_t nb_missed;
148+ uint8_t *peak_p;
149+#endif
150+} TinyAlloc;
151+
152+typedef struct tal_header_t {
153+ size_t size;
154+#ifdef TAL_DEBUG
155+ int line_num; /* negative line_num used for double free check */
156+ char file_name[TAL_DEBUG_FILE_LEN + 1];
157+#endif
158+} tal_header_t;
135159
136160 /* ------------------------------------------------------------------------- */
137−/* Custom allocator for tiny objects */
138161
139162 ST_FUNC TinyAlloc *tal_new(TinyAlloc **pal, size_t limit, size_t size)
140163 {
@@ -160,9 +183,10 @@ tail_call: · 19 unmodified lines
160183 #endif
161184 #ifdef TAL_DEBUG
162185 if (al->nb_allocs > 0) {
186+ uint8_t *p;
163187 fprintf(stderr, "TAL_DEBUG: mem leak %d chunks (limit= %d)\n",
164188 al->nb_allocs, al->limit);
165− uint8_t *p = al->buffer;
189+ p = al->buffer;
166190 while (p < al->p) {
167191 tal_header_t *header = (tal_header_t *)p;
168192 if (header->line_num > 0) {
@@ -222,10 +246,10 @@ tail_call: · 53 unmodified lines
222246 header = (tal_header_t *)al->p;
223247 header->size = adj_size;
224248 #ifdef TAL_DEBUG
225− int ofs = strlen(file) - TAL_DEBUG_FILE_LEN;
249+ { int ofs = strlen(file) - TAL_DEBUG_FILE_LEN;
226250 strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), TAL_DEBUG_FILE_LEN);
227251 header->file_name[TAL_DEBUG_FILE_LEN] = 0;
228− header->line_num = line;
252+ header->line_num = line; }
229253 #endif
230254 ret = al->p + sizeof(tal_header_t);
231255 al->p += adj_size + sizeof(tal_header_t);
@@ -286,26 +310,25 @@ tail_call: · 54 unmodified lines
286310 return ret;
287311 }
288312
313+#endif /* USE_TAL */
314+
289315 /* ------------------------------------------------------------------------- */
290316 /* CString handling */
291317 static void cstr_realloc(CString *cstr, int new_size)
292318 {
293319 int size;
294− void *data;
295320
296321 size = cstr->size_allocated;
297322 if (size < 8)
298323 size = 8; /* no need to allocate a too small first string */
299324 while (size < new_size)
300325 size = size * 2;
301− data = tal_realloc(cstr_alloc, cstr->data_allocated, size);
302− cstr->data_allocated = data;
326+ cstr->data = tal_realloc(cstr_alloc, cstr->data, size);
303327 cstr->size_allocated = size;
304− cstr->data = data;
305328 }
306329
307330 /* add a byte */
308−ST_FUNC void cstr_ccat(CString *cstr, int ch)
331+ST_INLN void cstr_ccat(CString *cstr, int ch)
309332 {
310333 int size;
311334 size = cstr->size + 1;
@@ -346,7 +369,7 @@ ST_FUNC void cstr_new(CString *cstr) · 34 unmodified lines
346369 /* free string and reset it to NULL */
347370 ST_FUNC void cstr_free(CString *cstr)
348371 {
349− tal_free(cstr_alloc, cstr->data_allocated);
372+ tal_free(cstr_alloc, cstr->data);
350373 cstr_new(cstr);
351374 }
352375
@@ -1026,6 +1049,13 @@ ST_INLN void tok_str_new(TokenString *s) · 673 unmodified lines
10261049 s->last_line_num = -1;
10271050 }
10281051
1052+ST_FUNC TokenString *tok_str_alloc(void)
1053+{
1054+ TokenString *str = tal_realloc(tokstr_alloc, 0, sizeof *str);
1055+ tok_str_new(str);
1056+ return str;
1057+}
1058+
10291059 ST_FUNC int *tok_str_dup(TokenString *s)
10301060 {
10311061 int *str;
@@ -1049,7 +1079,6 @@ ST_FUNC int *tok_str_realloc(TokenString *s, int new_size) · 17 unmodified lines
10491079 size = 16;
10501080 while (size < new_size)
10511081 size = size * 2;
1052− TCC_ASSERT((size & (size -1)) == 0);
10531082 if (size > s->allocated_len) {
10541083 str = tal_realloc(tokstr_alloc, s->str, size * sizeof(int));
10551084 s->allocated_len = size;
@@ -1070,6 +1099,29 @@ ST_FUNC void tok_str_add(TokenString *s, int t) · 14 unmodified lines
10701099 s->len = len;
10711100 }
10721101
1102+ST_FUNC void begin_macro(TokenString *str, int alloc)
1103+{
1104+ str->alloc = alloc;
1105+ str->prev = macro_stack;
1106+ str->prev_ptr = macro_ptr;
1107+ macro_ptr = str->str;
1108+ macro_stack = str;
1109+}
1110+
1111+ST_FUNC void end_macro(void)
1112+{
1113+ TokenString *str = macro_stack;
1114+ macro_stack = str->prev;
1115+ macro_ptr = str->prev_ptr;
1116+ if (str->alloc == 2) {
1117+ str->alloc = 3; /* just mark as finished */
1118+ } else {
1119+ tok_str_free(str->str);
1120+ if (str->alloc == 1)
1121+ tal_free(tokstr_alloc, str);
1122+ }
1123+}
1124+
10731125 static void tok_str_add2(TokenString *s, int t, CValue *cv)
10741126 {
10751127 int len, *str;
@@ -1172,7 +1224,6 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv) · 96 unmodified lines
11721224 case TOK_PPSTR:
11731225 cv->str.size = *p++;
11741226 cv->str.data = p;
1175− cv->str.data_allocated = 0;
11761227 p += (cv->str.size + sizeof(int) - 1) / sizeof(int);
11771228 break;
11781229 case TOK_CDOUBLE:
@@ -1235,13 +1286,13 @@ static int macro_is_equal(const int *a, const int *b) · 56 unmodified lines
12351286 }
12361287
12371288 /* defines handling */
1238−ST_INLN void define_push(int v, int macro_type, TokenString *str, Sym *first_arg)
1289+ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
12391290 {
12401291 Sym *s, *o;
12411292
12421293 o = define_find(v);
12431294 s = sym_push2(&define_stack, v, macro_type, 0);
1244− s->d = str ? tok_str_dup(str) : NULL;
1295+ s->d = str;
12451296 s->next = first_arg;
12461297 table_ident[v - TOK_IDENT]->sym_define = s;
12471298
@@ -1344,9 +1395,9 @@ ST_FUNC void label_pop(Sym **ptop, Sym *slast) · 96 unmodified lines
13441395 static int expr_preprocess(void)
13451396 {
13461397 int c, t;
1347− TokenString str;
1398+ TokenString *str;
13481399
1349− tok_str_new(&str);
1400+ str = tok_str_alloc();
13501401 while (tok != TOK_LINEFEED && tok != TOK_EOF) {
13511402 next(); /* do macro subst */
13521403 if (tok == TOK_DEFINED) {
@@ -1364,12 +1415,12 @@ static int expr_preprocess(void) · 11 unmodified lines
13641415 tok = TOK_CINT;
13651416 tokc.i = 0;
13661417 }
1367− tok_str_add_tok(&str);
1418+ tok_str_add_tok(str);
13681419 }
1369− tok_str_add(&str, -1); /* simulate end of file */
1370− tok_str_add(&str, 0);
1420+ tok_str_add(str, -1); /* simulate end of file */
1421+ tok_str_add(str, 0);
13711422 /* now evaluate C constant expression */
1372− begin_macro(&str, 0);
1423+ begin_macro(str, 1);
13731424 next();
13741425 c = expr_const();
13751426 end_macro();
@@ -1457,7 +1508,7 @@ ST_FUNC void parse_define(void) · 81 unmodified lines
14571508 if (3 == spc)
14581509 bad_twosharp:
14591510 tcc_error("'##' cannot appear at either end of macro");
1460− define_push(v, t, &tokstr_buf, first);
1511+ define_push(v, t, tok_str_dup(&tokstr_buf), first);
14611512 }
14621513
14631514 static CachedInclude *search_cached_include(TCCState *s1, const char *filename, int add)
@@ -2061,7 +2112,6 @@ static void parse_string(const char *s, int len) · 597 unmodified lines
20612112 } else {
20622113 tokc.str.size = tokcstr.size;
20632114 tokc.str.data = tokcstr.data;
2064− tokc.str.data_allocated = tokcstr.data_allocated;
20652115 if (!is_long)
20662116 tok = TOK_STR;
20672117 else
@@ -2403,11 +2453,6 @@ static inline void next_nomacro1(void) · 335 unmodified lines
24032453 p = file->buf_ptr;
24042454 redo_no_start:
24052455 c = *p;
2406−#if (__TINYC__ || __GNUC__)
2407−#else
2408− if (c & 0x80)
2409− goto parse_ident_fast;
2410−#endif
24112456 switch(c) {
24122457 case ' ':
24132458 case '\t':
@@ -2513,13 +2558,6 @@ maybe_newline: · 99 unmodified lines
25132558 || (parse_flags & PARSE_FLAG_ASM_FILE))
25142559 goto parse_simple;
25152560
2516−#if (__TINYC__ || __GNUC__)
2517− case 'a' ... 'z':
2518− case 'A' ... 'K':
2519− case 'M' ... 'Z':
2520− case '_':
2521− case 0x80 ... 0xFF:
2522−#else
25232561 case 'a': case 'b': case 'c': case 'd':
25242562 case 'e': case 'f': case 'g': case 'h':
25252563 case 'i': case 'j': case 'k': case 'l':
@@ -2535,7 +2573,6 @@ maybe_newline: · 9 unmodified lines
25352573 case 'U': case 'V': case 'W': case 'X':
25362574 case 'Y': case 'Z':
25372575 case '_':
2538−#endif
25392576 parse_ident_fast:
25402577 p1 = p;
25412578 h = TOK_HASH_INIT;
@@ -2617,7 +2654,6 @@ maybe_newline: · 75 unmodified lines
26172654 cstr_ccat(&tokcstr, '\0');
26182655 tokc.str.size = tokcstr.size;
26192656 tokc.str.data = tokcstr.data;
2620− tokc.str.data_allocated = tokcstr.data_allocated;
26212657 tok = TOK_PPNUM;
26222658 break;
26232659
@@ -2658,7 +2694,6 @@ maybe_newline: · 34 unmodified lines
26582694 cstr_ccat(&tokcstr, '\0');
26592695 tokc.str.size = tokcstr.size;
26602696 tokc.str.data = tokcstr.data;
2661− tokc.str.data_allocated = tokcstr.data_allocated;
26622697 tok = TOK_PPSTR;
26632698 break;
26642699
@@ -2796,6 +2831,8 @@ maybe_newline: · 131 unmodified lines
27962831 p++;
27972832 break;
27982833 default:
2834+ if (c >= 0x80 && c <= 0xFF) /* utf8 identifiers */
2835+ goto parse_ident_fast;
27992836 if (parse_flags & PARSE_FLAG_ASM_FILE)
28002837 goto parse_simple;
28012838 tcc_error("unrecognized character \\x%02x", c);
@@ -2895,7 +2932,6 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) · 93 unmodified lines
28952932 /* add string */
28962933 cval.str.size = cstr.size;
28972934 cval.str.data = cstr.data;
2898− cval.str.data_allocated = cstr.data_allocated;
28992935 tok_str_add2(&str, TOK_PPSTR, &cval);
29002936 cstr_free(&cstr);
29012937 } else {
@@ -3062,7 +3098,6 @@ static int macro_subst_tok( · 160 unmodified lines
30623098 cstr_cat(&cstr, cstrval, 0);
30633099 cval.str.size = cstr.size;
30643100 cval.str.data = cstr.data;
3065− cval.str.data_allocated = cstr.data_allocated;
30663101 tok_str_add2(tok_str, t1, &cval);
30673102 cstr_free(&cstr);
30683103 } else {
@@ -3381,7 +3416,6 @@ ST_FUNC void next(void) · 312 unmodified lines
33813416 if (s) {
33823417 Sym *nested_list = NULL;
33833418 tokstr_buf.len = 0;
3384− nested_list = NULL;
33853419 macro_subst_tok(&tokstr_buf, &nested_list, s, 1);
33863420 tok_str_add(&tokstr_buf, 0);
33873421 begin_macro(&tokstr_buf, 2);
@@ -3402,8 +3436,8 @@ ST_FUNC void next(void) · 14 unmodified lines
34023436 identifier case handled for labels. */
34033437 ST_INLN void unget_tok(int last_tok)
34043438 {
3405− TokenString *str = tcc_malloc(sizeof *str);
3406− tok_str_new(str);
3439+
3440+ TokenString *str = tok_str_alloc();
34073441 tok_str_add2(str, tok, &tokc);
34083442 tok_str_add(str, 0);
34093443 begin_macro(str, 1);
@@ -3529,10 +3563,8 @@ static void tok_print(const char *msg, const int *str) · 119 unmodified lines
35293563 static void pp_line(TCCState *s1, BufferedFile *f, int level)
35303564 {
35313565 int d = f->line_num - f->line_ref;
3532−
35333566 if (s1->dflag & 4)
35343567 return;
3535−
35363568 if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) {
35373569 if (level == 0 && f->line_ref && d) {
35383570 d = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t