]> granicus.if.org Git - php/commitdiff
Add persistent memory handling to smart_str API
authorSascha Schumann <sas@php.net>
Tue, 14 Nov 2000 15:36:18 +0000 (15:36 +0000)
committerSascha Schumann <sas@php.net>
Tue, 14 Nov 2000 15:36:18 +0000 (15:36 +0000)
ext/standard/php_smart_str.h

index 107acc8c8641ee18df14e493f1c69f155e49f140..9626abd9829d9a89bb5b0cc3d1af9bd3e4cc3cf8 100644 (file)
 
 #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)