summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-14 22:24:59 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-01-14 22:32:06 (GMT)
commit5fc59f5271d5ca06374782848bcd53adecfffcf1 (patch) (side-by-side diff)
tree6f5b70bd494bfaa34d4ae0152f183ef3962ecd58
parent2273858bd6af516b0d282aff155c5a6a794f6609 (diff)
downloadvmod-variable-5fc59f5271d5ca06374782848bcd53adecfffcf1.tar.gz
vmod-variable-5fc59f5271d5ca06374782848bcd53adecfffcf1.tar.bz2
Store per-session symtabs in private storage.
* src/variable.c (symtabv, symtabc) (symtab_mtx): Remove globals. (get_symtab): Save symtab in private data pointer. (vmod_clear, vmod_get_string) (vmod_set_string, vmod_get, vmod_set) (DEFGET, DEFSET) (vmod_defined, vmod_type_of) (vmod_unset, vmod_regset) (vmod_queryset): Expect struct vmod_priv * as 2nd argument. * src/variable.vcc: Change prototypes. * NEWS: Version 1.0.90 * configure.ac: Update.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS11
-rw-r--r--configure.ac4
-rw-r--r--src/variable.c89
-rw-r--r--src/variable.vcc32
4 files changed, 68 insertions, 68 deletions
diff --git a/NEWS b/NEWS
index 1c3e867..c0d662a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,15 @@
-vmod-variable -- history of user-visible changes. 2015-02-16
-Copyright (C) 2015 Sergey Poznyakoff
+vmod-variable -- history of user-visible changes. 2016-01-15
+Copyright (C) 2015-2016 Sergey Poznyakoff
See the end of file for copying conditions.
Please send vmod-variable bug reports to <gray@gnu.org>
+Version 1.0.90, (Git)
+
+Fix coredumps.
+
+
Version 1.0, 2015-02-16
Initial release
@@ -12,7 +17,7 @@ Initial release
=========================================================================
Copyright information:
-Copyright (C) 2015 Sergey Poznyakoff
+Copyright (C) 2015-2016 Sergey Poznyakoff
Permission is granted to anyone to make or distribute verbatim copies
of this document as received, in any medium, provided that the
diff --git a/configure.ac b/configure.ac
index 9a69658..f2adcb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
# This file is part of vmod-variable -*- autoconf -*-
-# Copyright (C) 2015 Sergey Poznyakoff
+# Copyright (C) 2015-2016 Sergey Poznyakoff
#
# Vmod-variable is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with vmod-variable. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ(2.69)
-AC_INIT([vmod-variable], [1.0], [gray@gnu.org])
+AC_INIT([vmod-variable], [1.0.90], [gray@gnu.org])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/variable.vcc)
diff --git a/src/variable.c b/src/variable.c
index bd79c3b..acdc6f6 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -310,10 +310,6 @@ symtab_free(struct symtab *st)
}
-static struct symtab **symtabv;
-static size_t symtabc;
-static pthread_mutex_t symtab_mtx = PTHREAD_MUTEX_INITIALIZER;
-
static struct symtab *global_symtab;
static pthread_mutex_t global_mtx = PTHREAD_MUTEX_INITIALIZER;
@@ -381,26 +377,20 @@ vmod_global_unset(VARIABLE_CTX ctx, VCL_STRING name)
AZ(pthread_mutex_unlock(&global_mtx));
}
+static void
+priv_symtab_free(void *p)
+{
+ symtab_free(p);
+}
+
static struct symtab *
-get_symtab(VARIABLE_CTX ctx)
-{
- struct symtab *st;
- int fd = ctx->req->sp->fd;
- AZ(pthread_mutex_lock(&symtab_mtx));
- if (symtabc <= fd) {
- size_t n = fd + 1;
- symtabv = realloc(symtabv, n * sizeof(symtabv[0]));
- while (symtabc < n)
- symtabv[symtabc++] = NULL;
+get_symtab(struct vmod_priv *priv)
+{
+ if (!priv->priv) {
+ priv->priv = symtab_create();
+ priv->free = priv_symtab_free;
}
- if (!symtabv[fd])
- symtabv[fd] = symtab_create();
- st = symtabv[fd];
- if (st->vxid != ctx->req->sp->vxid)
- symtab_clear(st);
- st->vxid = ctx->req->sp->vxid;
- AZ(pthread_mutex_unlock(&symtab_mtx));
- return st;
+ return priv->priv;
}
#define getvar(vt, name) symtab_lookup_or_install(vt, name, NULL)
@@ -422,24 +412,25 @@ defvar(struct symtab *vt, const char *name, enum variable_type t,
}
VCL_VOID
-vmod_clear(VARIABLE_CTX ctx)
+vmod_clear(VARIABLE_CTX ctx, struct vmod_priv *priv)
{
- symtab_clear(get_symtab(ctx));
+ symtab_clear(get_symtab(priv));
}
VCL_STRING
-vmod_get_string(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_get_string(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- struct variable *var = getvar(get_symtab(ctx), name);
+ struct variable *var = getvar(get_symtab(priv), name);
if (var && var->type == variable_string)
return var->v.s;
return NULL;
}
VCL_VOID
-vmod_set_string(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
+vmod_set_string(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING name, VCL_STRING value)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct variable *var = defvar(vt, name, variable_unset, NULL);
var->type = variable_string;
var->v.s = strdup(value ? value : "");
@@ -447,23 +438,25 @@ vmod_set_string(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
}
VCL_STRING
-vmod_get(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_get(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- return vmod_get_string(ctx, name);
+ return vmod_get_string(ctx, priv, name);
}
VCL_VOID
-vmod_set(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
+vmod_set(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING name, VCL_STRING value)
{
- vmod_set_string(ctx, name, value);
+ vmod_set_string(ctx, priv, name, value);
}
#define __cat__(a,b) a ## b
#define DEFGET(r_type, vcl_type, memb) \
vcl_type \
-__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, VCL_STRING name) \
+__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \
+ VCL_STRING name) \
{ \
- struct variable *var = getvar(get_symtab(ctx), name); \
+ struct variable *var = getvar(get_symtab(priv), name); \
if (var && var->type == __cat__(variable_,r_type)) \
return var->v.memb; \
return 0; \
@@ -471,10 +464,11 @@ __cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, VCL_STRING name) \
#define DEFSET(r_type, vcl_type, memb) \
VCL_VOID \
-__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, VCL_STRING name, \
+__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \
+ VCL_STRING name, \
vcl_type value) \
{ \
- struct symtab *vt = get_symtab(ctx); \
+ struct symtab *vt = get_symtab(priv); \
struct variable *var = defvar(vt, name, variable_unset, NULL); \
var->type = __cat__(variable_,r_type); \
var->v.memb = value; \
@@ -489,22 +483,22 @@ DEF(real, VCL_REAL, r)
DEF(duration, VCL_DURATION, d)
VCL_BOOL
-vmod_defined(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_defined(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- return !!getvar(get_symtab(ctx), name);
+ return !!getvar(get_symtab(priv), name);
}
VCL_STRING
-vmod_type_of(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_type_of(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- struct variable *var = getvar(get_symtab(ctx), name);
+ struct variable *var = getvar(get_symtab(priv), name);
return typestr[var ? var->type : variable_unset];
}
VCL_VOID
-vmod_unset(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_unset(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- symtab_remove(get_symtab(ctx), name);
+ symtab_remove(get_symtab(priv), name);
}
static void
@@ -716,10 +710,10 @@ setval(union value *val, const char *s, enum variable_type type, char **err)
}
VCL_VOID
-vmod_regset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING rxs,
- VCL_STRING input)
+vmod_regset(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING vars, VCL_STRING rxs, VCL_STRING input)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct vardef *head = NULL, *tail = NULL, *def;
size_t count = 0;
size_t n;
@@ -893,9 +887,10 @@ define_param(struct symtab *vt, struct vardef *def,
}
VCL_VOID
-vmod_queryset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING query)
+vmod_queryset(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING vars, VCL_STRING query)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct vardef *head = NULL, *tail = NULL, *def;
size_t count = 0;
size_t n;
diff --git a/src/variable.vcc b/src/variable.vcc
index 3745a8d..ad80fe0 100644
--- a/src/variable.vcc
+++ b/src/variable.vcc
@@ -22,26 +22,26 @@ Due to limitations of the vmodtool.py utility, this document contains
only prototypes of the functions provided by the **vmod-variable** module.
For a detailed documentation, please see vmod-variable(3) manual page.
-$Function VOID set(STRING, STRING)
-$Function STRING get(STRING)
+$Function VOID set(PRIV_VCL, STRING, STRING)
+$Function STRING get(PRIV_VCL, STRING)
$Function VOID global_set(STRING, STRING)
$Function STRING global_get(STRING)
-$Function VOID set_int(STRING, INT)
-$Function INT get_int(STRING)
-$Function VOID set_string(STRING, STRING)
-$Function STRING get_string(STRING)
-$Function VOID set_real(STRING, REAL)
-$Function REAL get_real(STRING)
-$Function VOID set_duration(STRING, DURATION)
-$Function DURATION get_duration(STRING)
-$Function VOID clear()
+$Function VOID set_int(PRIV_VCL, STRING, INT)
+$Function INT get_int(PRIV_VCL, STRING)
+$Function VOID set_string(PRIV_VCL, STRING, STRING)
+$Function STRING get_string(PRIV_VCL, STRING)
+$Function VOID set_real(PRIV_VCL, STRING, REAL)
+$Function REAL get_real(PRIV_VCL, STRING)
+$Function VOID set_duration(PRIV_VCL, STRING, DURATION)
+$Function DURATION get_duration(PRIV_VCL, STRING)
+$Function VOID clear(PRIV_VCL)
$Function VOID global_clear()
$Function BOOL global_defined(STRING)
$Function VOID global_unset(STRING)
-$Function BOOL defined(STRING)
-$Function STRING type_of(STRING)
-$Function VOID unset(STRING)
-$Function VOID regset(STRING, STRING, STRING)
-$Function VOID queryset(STRING, STRING)
+$Function BOOL defined(PRIV_VCL, STRING)
+$Function STRING type_of(PRIV_VCL, STRING)
+$Function VOID unset(PRIV_VCL, STRING)
+$Function VOID regset(PRIV_VCL, STRING, STRING, STRING)
+$Function VOID queryset(PRIV_VCL, STRING, STRING)

Return to:

Send suggestions and report system problems to the System administrator.