From: Sascha Schumann Date: Tue, 26 Sep 2000 11:00:39 +0000 (+0000) Subject: Unify memory allocation in smart_str functions X-Git-Tag: php-4.0.3RC1~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7db874096eb3b0ab5219376b130432c65a96afa0;p=php Unify memory allocation in smart_str functions --- diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index 7d214e6967..592b57e27a 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.5 on Wed Sep 20 10:58:28 2000 */ +/* Generated by re2c 0.5 on Thu Sep 21 02:33:40 2000 */ #line 1 "/home/sas/src/php4/ext/standard/url_scanner_ex.re" /* +----------------------------------------------------------------------+ @@ -40,6 +40,13 @@ #define smart_str_0(x) ((x)->c[(x)->len] = '\0') +#define smart_str_alloc(d,n) {\ + if (n >= d->a) {\ + d->c = erealloc(d->c, n + 129); \ + d->a = n + 128; \ + }\ +} + static inline void smart_str_append(smart_str *dest, smart_str *src) { size_t newlen; @@ -48,24 +55,16 @@ static inline void smart_str_append(smart_str *dest, smart_str *src) dest->len = dest->a = 0; newlen = dest->len + src->len; - if (newlen >= dest->a) { - dest->c = erealloc(dest->c, newlen + 129); - dest->a = newlen + 128; - } + smart_str_alloc(dest, newlen); memcpy(dest->c + dest->len, src->c, src->len); dest->len = newlen; } static inline void smart_str_appendc(smart_str *dest, char c) { - size_t newlen; - - newlen = dest->len + 1; - if (newlen >= dest->a) { - dest->c = erealloc(dest->c, newlen + 129); - dest->a = newlen + 128; - } - dest->c[dest->len++] = c; + ++dest->len; + smart_str_alloc(dest, dest->len); + dest->c[dest->len - 1] = c; } static inline void smart_str_free(smart_str *s) @@ -79,9 +78,9 @@ static inline void smart_str_free(smart_str *s) static inline void smart_str_copyl(smart_str *dest, const char *src, size_t len) { - dest->c = erealloc(dest->c, len + 1); + smart_str_alloc(dest, len); memcpy(dest->c, src, len); - dest->a = dest->len = len; + dest->len = len; } static inline void smart_str_appendl(smart_str *dest, const char *src, size_t len) @@ -130,7 +129,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } } - if (bash) + if (bash) smart_str_appendl(dest, url->c, bash - url->c); else smart_str_append(dest, url); @@ -265,7 +264,7 @@ static inline void mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size YYCURSOR = ctx->buf.c; YYLIMIT = ctx->buf.c + ctx->buf.len; -#line 269 +#line 268 while(1) { @@ -285,14 +284,14 @@ yy0: if(yych != '<') goto yy4; yy2: yych = *++YYCURSOR; yy3: -#line 278 +#line 277 { PASSTHRU(); STATE = STATE_TAG; continue; } yy4: yych = *++YYCURSOR; yy5: -#line 279 +#line 278 { PASSTHRU(); continue; } } -#line 280 +#line 279 break; @@ -346,11 +345,11 @@ yy6: yy8: yych = *++YYCURSOR; goto yy13; yy9: -#line 285 +#line 284 { HANDLE_TAG() /* Sets STATE */; PASSTHRU(); continue; } yy10: yych = *++YYCURSOR; yy11: -#line 286 +#line 285 { PASSTHRU(); continue; } yy12: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -358,7 +357,7 @@ yy12: ++YYCURSOR; yy13: if(yybm[0+yych] & 128) goto yy12; goto yy9; } -#line 287 +#line 286 break; @@ -392,22 +391,22 @@ yy14: } yy16: yych = *++YYCURSOR; yy17: -#line 292 +#line 291 { PASSTHRU(); HANDLE_FORM(); STATE = STATE_PLAIN; continue; } yy18: yych = *++YYCURSOR; yy19: -#line 293 +#line 292 { PASSTHRU(); continue; } yy20: yych = *++YYCURSOR; yy21: -#line 294 +#line 293 { YYCURSOR--; STATE = STATE_ARG; continue; } yy22: yych = *++YYCURSOR; yy23: -#line 295 +#line 294 { PASSTHRU(); continue; } } -#line 296 +#line 295 break; @@ -461,11 +460,11 @@ yy24: yy26: yych = *++YYCURSOR; goto yy31; yy27: -#line 301 +#line 300 { PASSTHRU(); HANDLE_ARG(); STATE = STATE_BEFORE_VAL; continue; } yy28: yych = *++YYCURSOR; yy29: -#line 302 +#line 301 { PASSTHRU(); STATE = STATE_NEXT_ARG; continue; } yy30: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -473,7 +472,7 @@ yy30: ++YYCURSOR; yy31: if(yybm[0+yych] & 128) goto yy30; goto yy27; } -#line 303 +#line 302 case STATE_BEFORE_VAL: @@ -527,12 +526,12 @@ yy34: yyaccept = 0; if(yych == ' ') goto yy41; if(yych == '=') goto yy39; yy35: -#line 308 +#line 307 { YYCURSOR--; STATE = STATE_NEXT_ARG; continue; } yy36: yych = *++YYCURSOR; goto yy40; yy37: -#line 307 +#line 306 { PASSTHRU(); STATE = STATE_VAL; continue; } yy38: yych = *++YYCURSOR; goto yy35; @@ -551,7 +550,7 @@ yy43: YYCURSOR = YYMARKER; case 0: goto yy35; } } -#line 309 +#line 308 break; @@ -614,12 +613,12 @@ yy46: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if(yych != '>') goto yy54; yy47: -#line 316 +#line 315 { PASSTHRU(); STATE = STATE_NEXT_ARG; continue; } yy48: yych = *++YYCURSOR; goto yy52; yy49: -#line 315 +#line 314 { HANDLE_VAL(0); STATE = STATE_NEXT_ARG; continue; } yy50: yych = *++YYCURSOR; goto yy47; @@ -639,10 +638,10 @@ yy55: YYCURSOR = YYMARKER; } yy56: yych = *++YYCURSOR; yy57: -#line 314 +#line 313 { HANDLE_VAL(1); STATE = STATE_NEXT_ARG; continue; } } -#line 317 +#line 316 break; } diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index cb89b39bd4..4fe6d25124 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -38,6 +38,13 @@ #define smart_str_0(x) ((x)->c[(x)->len] = '\0') +#define smart_str_alloc(d,n) {\ + if (n >= d->a) {\ + d->c = erealloc(d->c, n + 129); \ + d->a = n + 128; \ + }\ +} + static inline void smart_str_append(smart_str *dest, smart_str *src) { size_t newlen; @@ -46,24 +53,16 @@ static inline void smart_str_append(smart_str *dest, smart_str *src) dest->len = dest->a = 0; newlen = dest->len + src->len; - if (newlen >= dest->a) { - dest->c = erealloc(dest->c, newlen + 129); - dest->a = newlen + 128; - } + smart_str_alloc(dest, newlen); memcpy(dest->c + dest->len, src->c, src->len); dest->len = newlen; } static inline void smart_str_appendc(smart_str *dest, char c) { - size_t newlen; - - newlen = dest->len + 1; - if (newlen >= dest->a) { - dest->c = erealloc(dest->c, newlen + 129); - dest->a = newlen + 128; - } - dest->c[dest->len++] = c; + ++dest->len; + smart_str_alloc(dest, dest->len); + dest->c[dest->len - 1] = c; } static inline void smart_str_free(smart_str *s) @@ -77,9 +76,9 @@ static inline void smart_str_free(smart_str *s) static inline void smart_str_copyl(smart_str *dest, const char *src, size_t len) { - dest->c = erealloc(dest->c, len + 1); + smart_str_alloc(dest, len); memcpy(dest->c, src, len); - dest->a = dest->len = len; + dest->len = len; } static inline void smart_str_appendl(smart_str *dest, const char *src, size_t len) @@ -128,7 +127,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } } - if (bash) + if (bash) smart_str_appendl(dest, url->c, bash - url->c); else smart_str_append(dest, url);