cvs: php4 /ext/standard url_scanner_ex.c url_scanner_ex.re
| From: | Sascha Schumann | Date: | Wed, 20 Sep 2000 08:40:34 +0000 |
| Subject: | cvs: php4 /ext/standard url_scanner_ex.c url_scanner_ex.re | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1814@lists.php.net to get a copy of this message | ||
sas Wed Sep 20 01:40:34 2000 EDT
Modified files:
/php4/ext/standard url_scanner_ex.re url_scanner_ex.c
Log:
Use emalloc and friends. Since we reuse all buffers, this does not affect
the speed.
The smart_str_* functions don't NUL terminate strings anymore. We can
rely on the length of the strings completely.
Index: php4/ext/standard/url_scanner_ex.re
diff -u php4/ext/standard/url_scanner_ex.re:1.11 php4/ext/standard/url_scanner_ex.re:1.12
--- php4/ext/standard/url_scanner_ex.re:1.11 Wed Sep 20 01:13:45 2000
+++ php4/ext/standard/url_scanner_ex.re Wed Sep 20 01:40:33 2000
@@ -36,6 +36,8 @@
#define url_adapt_ext url_adapt_ext_ex
#define url_scanner url_scanner_ex
+#define smart_str_0(x) ((x)->c[(x)->len] = '\0')
+
static inline void smart_str_append(smart_str *dest, smart_str *src)
{
size_t newlen;
@@ -45,11 +47,11 @@
newlen = dest->len + src->len;
if (newlen >= dest->a) {
- dest->c = realloc(dest->c, newlen + 129);
+ dest->c = erealloc(dest->c, newlen + 129);
dest->a = newlen + 128;
}
memcpy(dest->c + dest->len, src->c, src->len);
- dest->c[dest->len = newlen] = '\0';
+ dest->len = newlen;
}
static inline void smart_str_appendc(smart_str *dest, char c)
@@ -58,17 +60,16 @@
newlen = dest->len + 1;
if (newlen >= dest->a) {
- dest->c = realloc(dest->c, newlen + 129);
+ dest->c = erealloc(dest->c, newlen + 129);
dest->a = newlen + 128;
}
dest->c[dest->len++] = c;
- dest->c[dest->len] = '\0';
}
static inline void smart_str_free(smart_str *s)
{
if (s->c) {
- free(s->c);
+ efree(s->c);
s->c = NULL;
}
s->a = s->len = 0;
@@ -76,9 +77,8 @@
static inline void smart_str_copyl(smart_str *dest, const char *src, size_t len)
{
- dest->c = realloc(dest->c, len + 1);
+ dest->c = erealloc(dest->c, len + 1);
memcpy(dest->c, src, len);
- dest->c[len] = '\0';
dest->a = dest->len = len;
}
@@ -110,7 +110,7 @@
{
register const char *p, *q;
const char *bash = NULL;
- char sep = "?";
+ char sep = '?';
q = url->c + url->len;
@@ -327,7 +327,6 @@
ctx->buf.len = rest;
}
-
char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t
*newlen)
{
char *ret;
@@ -345,9 +344,11 @@
if (ctx->result.len == 0) {
return strdup("");
}
- ret = ctx->result.c;
- ctx->result.c = NULL;
- ctx->result.len = ctx->result.a = 0;
+ smart_str_0(&ctx->result);
+ ret = malloc(ctx->result.len + 1);
+ memcpy(ret, ctx->result.c, ctx->result.len + 1);
+
+ ctx->result.len = 0;
return ret;
}
Index: php4/ext/standard/url_scanner_ex.c
diff -u php4/ext/standard/url_scanner_ex.c:1.11 php4/ext/standard/url_scanner_ex.c:1.12
--- php4/ext/standard/url_scanner_ex.c:1.11 Wed Sep 20 01:13:45 2000
+++ php4/ext/standard/url_scanner_ex.c Wed Sep 20 01:40:33 2000
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.5 on Wed Sep 20 10:08:57 2000 */
+/* Generated by re2c 0.5 on Wed Sep 20 10:36:10 2000 */
#line 1 "/home/sas/src/php4/ext/standard/url_scanner_ex.re"
/*
+----------------------------------------------------------------------+
@@ -38,6 +38,8 @@
#define url_adapt_ext url_adapt_ext_ex
#define url_scanner url_scanner_ex
+#define smart_str_0(x) ((x)->c[(x)->len] = '\0')
+
static inline void smart_str_append(smart_str *dest, smart_str *src)
{
size_t newlen;
@@ -47,11 +49,11 @@
newlen = dest->len + src->len;
if (newlen >= dest->a) {
- dest->c = realloc(dest->c, newlen + 129);
+ dest->c = erealloc(dest->c, newlen + 129);
dest->a = newlen + 128;
}
memcpy(dest->c + dest->len, src->c, src->len);
- dest->c[dest->len = newlen] = '\0';
+ dest->len = newlen;
}
static inline void smart_str_appendc(smart_str *dest, char c)
@@ -60,17 +62,16 @@
newlen = dest->len + 1;
if (newlen >= dest->a) {
- dest->c = realloc(dest->c, newlen + 129);
+ dest->c = erealloc(dest->c, newlen + 129);
dest->a = newlen + 128;
}
dest->c[dest->len++] = c;
- dest->c[dest->len] = '\0';
}
static inline void smart_str_free(smart_str *s)
{
if (s->c) {
- free(s->c);
+ efree(s->c);
s->c = NULL;
}
s->a = s->len = 0;
@@ -78,9 +79,8 @@
static inline void smart_str_copyl(smart_str *dest, const char *src, size_t len)
{
- dest->c = realloc(dest->c, len + 1);
+ dest->c = erealloc(dest->c, len + 1);
memcpy(dest->c, src, len);
- dest->c[len] = '\0';
dest->a = dest->len = len;
}
@@ -112,7 +112,7 @@
{
register const char *p, *q;
const char *bash = NULL;
- char sep = "?";
+ char sep = '?';
q = url->c + url->len;
@@ -656,7 +656,6 @@
ctx->buf.len = rest;
}
-
char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t
*newlen)
{
char *ret;
@@ -674,9 +673,11 @@
if (ctx->result.len == 0) {
return strdup("");
}
- ret = ctx->result.c;
- ctx->result.c = NULL;
- ctx->result.len = ctx->result.a = 0;
+ smart_str_0(&ctx->result);
+ ret = malloc(ctx->result.len + 1);
+ memcpy(ret, ctx->result.c, ctx->result.len + 1);
+
+ ctx->result.len = 0;
return ret;
}