summaryrefslogtreecommitdiff
path: root/ext/standard/php_smart_str.h
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2000-11-14 15:36:18 +0000
committerSascha Schumann <sas@php.net>2000-11-14 15:36:18 +0000
commitc509dc6dc760532226b4382bbe5c2d538e299613 (patch)
tree785a4431514146fa001084da95f835fe74415e5d /ext/standard/php_smart_str.h
parentdba76125e447da91d83e5b09c48087d193a44d49 (diff)
downloadphp-git-c509dc6dc760532226b4382bbe5c2d538e299613.tar.gz
Add persistent memory handling to smart_str API
Diffstat (limited to 'ext/standard/php_smart_str.h')
-rw-r--r--ext/standard/php_smart_str.h39
1 files 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)