From c509dc6dc760532226b4382bbe5c2d538e299613 Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Tue, 14 Nov 2000 15:36:18 +0000 Subject: [PATCH] Add persistent memory handling to smart_str API --- ext/standard/php_smart_str.h | 39 ++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h index 107acc8c86..9626abd982 100644 --- a/ext/standard/php_smart_str.h +++ b/ext/standard/php_smart_str.h @@ -23,45 +23,54 @@ #define smart_str_0(x) ((x)->c[(x)->len] = '\0') -#define smart_str_alloc(d,n) {\ - /* if (!d->c) d->len = d->a = 0; */ \ - if (n >= d->a) {\ - d->c = erealloc(d->c, n + 129); \ +#define smart_str_alloc(d,n,what) {\ + if (!d->c) d->len = d->a = 0; \ + newlen = d->len + n; \ + if (newlen >= d->a) {\ + d->c = perealloc(d->c, n + 129, what); \ d->a = n + 128; \ }\ } -#define smart_str_appends(dest, src) smart_str_appendl(dest, src, sizeof(src)-1) +#define smart_str_appends_ex(dest, src, what) smart_str_appendl_ex(dest, src, strlen(src), what) +#define smart_str_appends(dest, src) smart_str_appendl(dest, src, strlen(src)) -static inline void smart_str_appendc(smart_str *dest, char c) +#define smart_str_appendc(dest, c) smart_str_appendc_ex(dest, c, 0) +#define smart_str_free(s) smart_str_free_ex(s, 0) +#define smart_str_appendl(dest,src,len) smart_str_appendl_ex(dest,src,len,0) +#define smart_str_append(dest, src) smart_str_append_ex(dest,src,0) + +static inline void smart_str_appendc_ex(smart_str *dest, char c, int what) { - ++dest->len; - smart_str_alloc(dest, dest->len); + size_t newlen; + + smart_str_alloc(dest, 1, what); + dest->len = newlen; dest->c[dest->len - 1] = c; } -static inline void smart_str_free(smart_str *s) + +static inline void smart_str_free_ex(smart_str *s, int what) { if (s->c) { - efree(s->c); + pefree(s->c, what); s->c = NULL; } s->a = s->len = 0; } -static inline void smart_str_appendl(smart_str *dest, const char *src, size_t len) +static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t len, int what) { size_t newlen; - newlen = dest->len + len; - smart_str_alloc(dest, newlen); + smart_str_alloc(dest, len, what); memcpy(dest->c + dest->len, src, len); dest->len = newlen; } -static inline void smart_str_append(smart_str *dest, smart_str *src) +static inline void smart_str_append_ex(smart_str *dest, smart_str *src, int what) { - smart_str_appendl(dest, src->c, src->len); + smart_str_appendl_ex(dest, src->c, src->len, what); } static inline void smart_str_setl(smart_str *dest, const char *src, size_t len) -- 2.40.0