Unified · Split
| @@ -277,16 +277,16 @@ ST_FUNC TokenSym *tok_alloc(const char *str, int len) · 276 unmodified lines | |||
| 277 | /* XXX: float tokens */ | 277 | /* XXX: float tokens */ |
| 278 | ST_FUNC const char *get_tok_str(int v, CValue *cv) | 278 | ST_FUNC const char *get_tok_str(int v, CValue *cv) |
| 279 | { | 279 | { |
| 280 | static char buf[STRING_MAX_SIZE + 1]; | ||
| 281 | static CString cstr_buf; | 280 | static CString cstr_buf; |
| 282 | char *p; | 281 | char *p; |
| 283 | int i, len; | 282 | int i, len; |
| 284 | 283 | ||
| 285 | /* NOTE: to go faster, we give a fixed buffer for small strings */ | 284 | /* first time preallocate static cstr_buf, next time only reset position to start */ |
| 286 | cstr_reset(&cstr_buf); | 285 | if (!cstr_buf.data_allocated) |
| 287 | cstr_buf.data = buf; | 286 | cstr_realloc(&cstr_buf, STRING_MAX_SIZE); |
| 288 | cstr_buf.size_allocated = sizeof(buf); | 287 | else |
| 289 | p = buf; | 288 | cstr_buf.size = 0; |
| 289 | p = cstr_buf.data; | ||
| 290 | 290 | ||
| 291 | switch(v) { | 291 | switch(v) { |
| 292 | case TOK_CINT: | 292 | case TOK_CINT: |
| @@ -333,17 +333,20 @@ ST_FUNC const char *get_tok_str(int v, CValue *cv) · 40 unmodified lines | |||
| 333 | 333 | ||
| 334 | case TOK_CFLOAT: | 334 | case TOK_CFLOAT: |
| 335 | cstr_cat(&cstr_buf, "<float>"); | 335 | cstr_cat(&cstr_buf, "<float>"); |
| 336 | cstr_ccat(&cstr_buf, '\0'); | ||
| 336 | break; | 337 | break; |
| 337 | case TOK_CDOUBLE: | 338 | case TOK_CDOUBLE: |
| 338 | cstr_cat(&cstr_buf, "<double>"); | 339 | cstr_cat(&cstr_buf, "<double>"); |
| 340 | cstr_ccat(&cstr_buf, '\0'); | ||
| 339 | break; | 341 | break; |
| 340 | case TOK_CLDOUBLE: | 342 | case TOK_CLDOUBLE: |
| 341 | cstr_cat(&cstr_buf, "<long double>"); | 343 | cstr_cat(&cstr_buf, "<long double>"); |
| 344 | cstr_ccat(&cstr_buf, '\0'); | ||
| 342 | break; | 345 | break; |
| 343 | case TOK_LINENUM: | 346 | case TOK_LINENUM: |
| 344 | cstr_cat(&cstr_buf, "<linenumber>"); | 347 | cstr_cat(&cstr_buf, "<linenumber>"); |
| 348 | cstr_ccat(&cstr_buf, '\0'); | ||
| 345 | break; | 349 | break; |
| 346 | //return NULL; /* should not happen */ | ||
| 347 | 350 | ||
| 348 | /* above tokens have value, the ones below don't */ | 351 | /* above tokens have value, the ones below don't */ |
| 349 | 352 | ||
| @@ -368,13 +371,13 @@ ST_FUNC const char *get_tok_str(int v, CValue *cv) · 18 unmodified lines | |||
| 368 | *p++ = q[0]; | 371 | *p++ = q[0]; |
| 369 | *p++ = q[1]; | 372 | *p++ = q[1]; |
| 370 | *p = '\0'; | 373 | *p = '\0'; |
| 371 | return buf; | 374 | return cstr_buf.data; |
| 372 | } | 375 | } |
| 373 | q += 3; | 376 | q += 3; |
| 374 | } | 377 | } |
| 375 | if (v >= 127) { | 378 | if (v >= 127) { |
| 376 | sprintf(buf, "<%02x>", v); | 379 | sprintf(cstr_buf.data, "<%02x>", v); |
| 377 | return buf; | 380 | return cstr_buf.data; |
| 378 | } | 381 | } |
| 379 | addv: | 382 | addv: |
| 380 | *p++ = v; | 383 | *p++ = v; |
| @@ -1048,14 +1051,20 @@ static int tok_last(const int *str0, const int *str1) · 667 unmodified lines | |||
| 1048 | 1051 | ||
| 1049 | static int macro_is_equal(const int *a, const int *b) | 1052 | static int macro_is_equal(const int *a, const int *b) |
| 1050 | { | 1053 | { |
| 1051 | char buf[STRING_MAX_SIZE + 1]; | 1054 | static CString cstr_buf; |
| 1052 | CValue cv; | 1055 | CValue cv; |
| 1053 | int t; | 1056 | int t; |
| 1054 | while (*a && *b) { | 1057 | while (*a && *b) { |
| 1058 | /* first time preallocate static cstr_buf, next time only reset position to start */ | ||
| 1059 | if (!cstr_buf.data_allocated) | ||
| 1060 | cstr_realloc(&cstr_buf, STRING_MAX_SIZE); | ||
| 1061 | else | ||
| 1062 | cstr_buf.size = 0; | ||
| 1055 | TOK_GET(&t, &a, &cv); | 1063 | TOK_GET(&t, &a, &cv); |
| 1056 | pstrcpy(buf, sizeof buf, get_tok_str(t, &cv)); | 1064 | cstr_cat(&cstr_buf, get_tok_str(t, &cv)); |
| 1065 | cstr_ccat(&cstr_buf, '\0'); | ||
| 1057 | TOK_GET(&t, &b, &cv); | 1066 | TOK_GET(&t, &b, &cv); |
| 1058 | if (strcmp(buf, get_tok_str(t, &cv))) | 1067 | if (strcmp(cstr_buf.data, get_tok_str(t, &cv))) |
| 1059 | return 0; | 1068 | return 0; |
| 1060 | } | 1069 | } |
| 1061 | return !(*a || *b); | 1070 | return !(*a || *b); |
| @@ -2785,7 +2794,7 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) · 1723 unmodified lines | |||
| 2785 | && 0 == check_space(t, &spc)) { | 2794 | && 0 == check_space(t, &spc)) { |
| 2786 | const char *s = get_tok_str(t, &cval); | 2795 | const char *s = get_tok_str(t, &cval); |
| 2787 | while (*s) { | 2796 | while (*s) { |
| 2788 | if (t == TOK_PPSTR && *s != '\'') | 2797 | if (/*t == TOK_PPSTR &&*/ *s != '\'') |
| 2789 | add_char(&cstr, *s); | 2798 | add_char(&cstr, *s); |
| 2790 | else | 2799 | else |
| 2791 | cstr_ccat(&cstr, *s); | 2800 | cstr_ccat(&cstr, *s); |