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