Commit c89bd1fb authored by Geoff Simmons's avatar Geoff Simmons

VMOD blob: giving up on in-place decode, since it requires assigning

a STRING (const char *) to vmod_priv->priv (void *) (const qualifier).
parent 1adf4429
...@@ -42,7 +42,7 @@ struct vmod_blob_blob { ...@@ -42,7 +42,7 @@ struct vmod_blob_blob {
unsigned magic; unsigned magic;
#define VMOD_BLOB_MAGIC 0xfade4fa9 #define VMOD_BLOB_MAGIC 0xfade4fa9
struct vmod_priv blob; struct vmod_priv blob;
const char *encoding[__MAX_ENCODING]; char *encoding[__MAX_ENCODING];
pthread_mutex_t lock; pthread_mutex_t lock;
}; };
...@@ -263,25 +263,25 @@ vmod_blob_encode(VRT_CTX, struct vmod_blob_blob *b, VCL_ENUM encs) ...@@ -263,25 +263,25 @@ vmod_blob_encode(VRT_CTX, struct vmod_blob_blob *b, VCL_ENUM encs)
assert(len >= 0); assert(len >= 0);
if (len == 0) if (len == 0)
b->encoding[enc] = ""; b->encoding[enc] = empty;
else { else {
b->encoding[enc] = malloc(len); b->encoding[enc] = malloc(len);
if (b->encoding[enc] == NULL) if (b->encoding[enc] == NULL)
ERRNOMEM(ctx, "cannot encode"); ERRNOMEM(ctx, "cannot encode");
else { else {
const char *s = b->encoding[enc]; char *s = b->encoding[enc];
len = len =
func[enc].encode( func[enc].encode(
enc, (void *) s, len, enc, s, len,
b->blob.priv, b->blob.priv,
b->blob.len); b->blob.len);
assert(len >= 0); assert(len >= 0);
if (len == 0) { if (len == 0) {
free((void *) s); free(s);
b->encoding[enc] = ""; b->encoding[enc] = empty;
} }
else else
*((char *)s + len) = '\0'; s[len] = '\0';
} }
} }
} }
...@@ -323,7 +323,7 @@ find_nonempty_va(const char *restrict *p, va_list ap) ...@@ -323,7 +323,7 @@ find_nonempty_va(const char *restrict *p, va_list ap)
/* find first non-empty vararg */ /* find first non-empty vararg */
for (; *p == vrt_magic_string_end || *p == NULL || **p == '\0'; for (; *p == vrt_magic_string_end || *p == NULL || **p == '\0';
*p = va_arg(ap, const char *)) *p = va_arg(ap, char *))
if (*p == vrt_magic_string_end) if (*p == vrt_magic_string_end)
return (vrt_magic_string_end); return (vrt_magic_string_end);
...@@ -336,51 +336,10 @@ find_nonempty_va(const char *restrict *p, va_list ap) ...@@ -336,51 +336,10 @@ find_nonempty_va(const char *restrict *p, va_list ap)
return (q); return (q);
} }
/*
* special case: we can avoid copying for identity decode if we need to
* deal with a single vararg only - in which case we just have the blob
* point to the input string
*/
static VCL_BLOB
decode_id_inplace(struct vmod_priv *b, VCL_INT n, const char *restrict p,
va_list ap) {
const char *q;
int l;
if (n == 0)
return null_blob;
q = find_nonempty_va(&p, ap);
if (p == vrt_magic_string_end)
return null_blob;
if (q == vrt_magic_string_end) {
/* can use in-place decode */
l = strlen(p);
if (n > 0 && n < l)
l = n;
b->priv = (char *)p;
b->len = l;
b->free = NULL;
return (b);
}
if (n == -1)
return NULL;
l = strlen(p);
if (n > l)
return NULL;
b->priv = (char *)p;
b->len = n;
b->free = NULL;
return (b);
}
static VCL_BLOB static VCL_BLOB
decode(VRT_CTX, VCL_INT n, VCL_ENUM decs, decode(VRT_CTX, VCL_INT n, VCL_ENUM decs, const char *restrict const p,
const char *restrict const p, va_list ap) { va_list ap)
{
enum encoding dec = parse_encoding(decs); enum encoding dec = parse_encoding(decs);
struct wb_s wb; struct wb_s wb;
struct vmod_priv *b; struct vmod_priv *b;
...@@ -398,17 +357,6 @@ decode(VRT_CTX, VCL_INT n, VCL_ENUM decs, ...@@ -398,17 +357,6 @@ decode(VRT_CTX, VCL_INT n, VCL_ENUM decs,
return NULL; return NULL;
} }
if (dec == IDENTITY) {
va_list aq;
va_copy(aq, ap);
const struct vmod_priv *bb = decode_id_inplace(b, n, p, aq);
va_end(aq);
if (bb == null_blob)
WS_Reset(ctx->ws, snap);
if (bb == b)
return bb;
}
if (wb_create(ctx->ws, &wb) == NULL) { if (wb_create(ctx->ws, &wb) == NULL) {
WS_Reset(ctx->ws, snap); WS_Reset(ctx->ws, snap);
ERRNOMEM(ctx, "cannot decode"); ERRNOMEM(ctx, "cannot decode");
...@@ -521,16 +469,6 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs, ...@@ -521,16 +469,6 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
AENC(dec); AENC(dec);
AENC(enc); AENC(enc);
if (dec == IDENTITY) {
va_copy(aq, ap);
const struct vmod_priv *bb = decode_id_inplace(&b, n, p, aq);
va_end(aq);
if (bb != NULL) {
r = encode(ctx, enc, bb);
return (r);
}
}
/* /*
* Allocate space for the decoded blob on the stack * Allocate space for the decoded blob on the stack
* ignoring the limitation imposed by n * ignoring the limitation imposed by n
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment