diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-15 14:20:42 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-15 14:20:42 +0200 |
commit | 746f6355a4595cc4bbcffc89a3e42a082d757759 (patch) | |
tree | 8530127396a94f3d70bdef83a0aaffddb1b80469 | |
parent | 5fc59f5271d5ca06374782848bcd53adecfffcf1 (diff) | |
download | vmod-variable-746f6355a4595cc4bbcffc89a3e42a082d757759.tar.gz vmod-variable-746f6355a4595cc4bbcffc89a3e42a082d757759.tar.bz2 |
Revert "Store per-session symtabs in private storage."
This reverts commit 5fc59f5271d5ca06374782848bcd53adecfffcf1, which
in fact pertains to 4.1 branch.
-rw-r--r-- | NEWS | 11 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | src/variable.c | 89 | ||||
-rw-r--r-- | src/variable.vcc | 32 |
4 files changed, 68 insertions, 68 deletions
@@ -1,15 +1,10 @@ | |||
1 | vmod-variable -- history of user-visible changes. 2016-01-15 | 1 | vmod-variable -- history of user-visible changes. 2015-02-16 |
2 | Copyright (C) 2015-2016 Sergey Poznyakoff | 2 | Copyright (C) 2015 Sergey Poznyakoff |
3 | See the end of file for copying conditions. | 3 | See the end of file for copying conditions. |
4 | 4 | ||
5 | Please send vmod-variable bug reports to <gray@gnu.org> | 5 | Please send vmod-variable bug reports to <gray@gnu.org> |
6 | 6 | ||
7 | 7 | ||
8 | Version 1.0.90, (Git) | ||
9 | |||
10 | Fix coredumps. | ||
11 | |||
12 | |||
13 | Version 1.0, 2015-02-16 | 8 | Version 1.0, 2015-02-16 |
14 | 9 | ||
15 | Initial release | 10 | Initial release |
@@ -17,7 +12,7 @@ Initial release | |||
17 | ========================================================================= | 12 | ========================================================================= |
18 | Copyright information: | 13 | Copyright information: |
19 | 14 | ||
20 | Copyright (C) 2015-2016 Sergey Poznyakoff | 15 | Copyright (C) 2015 Sergey Poznyakoff |
21 | 16 | ||
22 | Permission is granted to anyone to make or distribute verbatim copies | 17 | Permission is granted to anyone to make or distribute verbatim copies |
23 | of this document as received, in any medium, provided that the | 18 | of this document as received, in any medium, provided that the |
diff --git a/configure.ac b/configure.ac index f2adcb9..9a69658 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,5 +1,5 @@ | |||
1 | # This file is part of vmod-variable -*- autoconf -*- | 1 | # This file is part of vmod-variable -*- autoconf -*- |
2 | # Copyright (C) 2015-2016 Sergey Poznyakoff | 2 | # Copyright (C) 2015 Sergey Poznyakoff |
3 | # | 3 | # |
4 | # Vmod-variable is free software; you can redistribute it and/or modify | 4 | # Vmod-variable is free software; you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published by | 5 | # it under the terms of the GNU General Public License as published by |
@@ -14,7 +14,7 @@ | |||
14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
15 | # along with vmod-variable. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with vmod-variable. If not, see <http://www.gnu.org/licenses/>. |
16 | AC_PREREQ(2.69) | 16 | AC_PREREQ(2.69) |
17 | AC_INIT([vmod-variable], [1.0.90], [gray@gnu.org]) | 17 | AC_INIT([vmod-variable], [1.0], [gray@gnu.org]) |
18 | AC_CONFIG_AUX_DIR([build-aux]) | 18 | AC_CONFIG_AUX_DIR([build-aux]) |
19 | AC_CONFIG_MACRO_DIR([m4]) | 19 | AC_CONFIG_MACRO_DIR([m4]) |
20 | AC_CONFIG_SRCDIR(src/variable.vcc) | 20 | AC_CONFIG_SRCDIR(src/variable.vcc) |
diff --git a/src/variable.c b/src/variable.c index acdc6f6..bd79c3b 100644 --- a/src/variable.c +++ b/src/variable.c | |||
@@ -310,6 +310,10 @@ symtab_free(struct symtab *st) | |||
310 | } | 310 | } |
311 | 311 | ||
312 | 312 | ||
313 | static struct symtab **symtabv; | ||
314 | static size_t symtabc; | ||
315 | static pthread_mutex_t symtab_mtx = PTHREAD_MUTEX_INITIALIZER; | ||
316 | |||
313 | static struct symtab *global_symtab; | 317 | static struct symtab *global_symtab; |
314 | static pthread_mutex_t global_mtx = PTHREAD_MUTEX_INITIALIZER; | 318 | static pthread_mutex_t global_mtx = PTHREAD_MUTEX_INITIALIZER; |
315 | 319 | ||
@@ -377,20 +381,26 @@ vmod_global_unset(VARIABLE_CTX ctx, VCL_STRING name) | |||
377 | AZ(pthread_mutex_unlock(&global_mtx)); | 381 | AZ(pthread_mutex_unlock(&global_mtx)); |
378 | } | 382 | } |
379 | 383 | ||
380 | static void | ||
381 | priv_symtab_free(void *p) | ||
382 | { | ||
383 | symtab_free(p); | ||
384 | } | ||
385 | |||
386 | static struct symtab * | 384 | static struct symtab * |
387 | get_symtab(struct vmod_priv *priv) | 385 | get_symtab(VARIABLE_CTX ctx) |
388 | { | 386 | { |
389 | if (!priv->priv) { | 387 | struct symtab *st; |
390 | priv->priv = symtab_create(); | 388 | int fd = ctx->req->sp->fd; |
391 | priv->free = priv_symtab_free; | 389 | AZ(pthread_mutex_lock(&symtab_mtx)); |
390 | if (symtabc <= fd) { | ||
391 | size_t n = fd + 1; | ||
392 | symtabv = realloc(symtabv, n * sizeof(symtabv[0])); | ||
393 | while (symtabc < n) | ||
394 | symtabv[symtabc++] = NULL; | ||
392 | } | 395 | } |
393 | return priv->priv; | 396 | if (!symtabv[fd]) |
397 | symtabv[fd] = symtab_create(); | ||
398 | st = symtabv[fd]; | ||
399 | if (st->vxid != ctx->req->sp->vxid) | ||
400 | symtab_clear(st); | ||
401 | st->vxid = ctx->req->sp->vxid; | ||
402 | AZ(pthread_mutex_unlock(&symtab_mtx)); | ||
403 | return st; | ||
394 | } | 404 | } |
395 | 405 | ||
396 | #define getvar(vt, name) symtab_lookup_or_install(vt, name, NULL) | 406 | #define getvar(vt, name) symtab_lookup_or_install(vt, name, NULL) |
@@ -412,25 +422,24 @@ defvar(struct symtab *vt, const char *name, enum variable_type t, | |||
412 | } | 422 | } |
413 | 423 | ||
414 | VCL_VOID | 424 | VCL_VOID |
415 | vmod_clear(VARIABLE_CTX ctx, struct vmod_priv *priv) | 425 | vmod_clear(VARIABLE_CTX ctx) |
416 | { | 426 | { |
417 | symtab_clear(get_symtab(priv)); | 427 | symtab_clear(get_symtab(ctx)); |
418 | } | 428 | } |
419 | 429 | ||
420 | VCL_STRING | 430 | VCL_STRING |
421 | vmod_get_string(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) | 431 | vmod_get_string(VARIABLE_CTX ctx, VCL_STRING name) |
422 | { | 432 | { |
423 | struct variable *var = getvar(get_symtab(priv), name); | 433 | struct variable *var = getvar(get_symtab(ctx), name); |
424 | if (var && var->type == variable_string) | 434 | if (var && var->type == variable_string) |
425 | return var->v.s; | 435 | return var->v.s; |
426 | return NULL; | 436 | return NULL; |
427 | } | 437 | } |
428 | 438 | ||
429 | VCL_VOID | 439 | VCL_VOID |
430 | vmod_set_string(VARIABLE_CTX ctx, struct vmod_priv *priv, | 440 | vmod_set_string(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value) |
431 | VCL_STRING name, VCL_STRING value) | ||
432 | { | 441 | { |
433 | struct symtab *vt = get_symtab(priv); | 442 | struct symtab *vt = get_symtab(ctx); |
434 | struct variable *var = defvar(vt, name, variable_unset, NULL); | 443 | struct variable *var = defvar(vt, name, variable_unset, NULL); |
435 | var->type = variable_string; | 444 | var->type = variable_string; |
436 | var->v.s = strdup(value ? value : ""); | 445 | var->v.s = strdup(value ? value : ""); |
@@ -438,25 +447,23 @@ vmod_set_string(VARIABLE_CTX ctx, struct vmod_priv *priv, | |||
438 | } | 447 | } |
439 | 448 | ||
440 | VCL_STRING | 449 | VCL_STRING |
441 | vmod_get(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) | 450 | vmod_get(VARIABLE_CTX ctx, VCL_STRING name) |
442 | { | 451 | { |
443 | return vmod_get_string(ctx, priv, name); | 452 | return vmod_get_string(ctx, name); |
444 | } | 453 | } |
445 | 454 | ||
446 | VCL_VOID | 455 | VCL_VOID |
447 | vmod_set(VARIABLE_CTX ctx, struct vmod_priv *priv, | 456 | vmod_set(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value) |
448 | VCL_STRING name, VCL_STRING value) | ||
449 | { | 457 | { |
450 | vmod_set_string(ctx, priv, name, value); | 458 | vmod_set_string(ctx, name, value); |
451 | } | 459 | } |
452 | 460 | ||
453 | #define __cat__(a,b) a ## b | 461 | #define __cat__(a,b) a ## b |
454 | #define DEFGET(r_type, vcl_type, memb) \ | 462 | #define DEFGET(r_type, vcl_type, memb) \ |
455 | vcl_type \ | 463 | vcl_type \ |
456 | __cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \ | 464 | __cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, VCL_STRING name) \ |
457 | VCL_STRING name) \ | ||
458 | { \ | 465 | { \ |
459 | struct variable *var = getvar(get_symtab(priv), name); \ | 466 | struct variable *var = getvar(get_symtab(ctx), name); \ |
460 | if (var && var->type == __cat__(variable_,r_type)) \ | 467 | if (var && var->type == __cat__(variable_,r_type)) \ |
461 | return var->v.memb; \ | 468 | return var->v.memb; \ |
462 | return 0; \ | 469 | return 0; \ |
@@ -464,11 +471,10 @@ __cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \ | |||
464 | 471 | ||
465 | #define DEFSET(r_type, vcl_type, memb) \ | 472 | #define DEFSET(r_type, vcl_type, memb) \ |
466 | VCL_VOID \ | 473 | VCL_VOID \ |
467 | __cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \ | 474 | __cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, VCL_STRING name, \ |
468 | VCL_STRING name, \ | ||
469 | vcl_type value) \ | 475 | vcl_type value) \ |
470 | { \ | 476 | { \ |
471 | struct symtab *vt = get_symtab(priv); \ | 477 | struct symtab *vt = get_symtab(ctx); \ |
472 | struct variable *var = defvar(vt, name, variable_unset, NULL); \ | 478 | struct variable *var = defvar(vt, name, variable_unset, NULL); \ |
473 | var->type = __cat__(variable_,r_type); \ | 479 | var->type = __cat__(variable_,r_type); \ |
474 | var->v.memb = value; \ | 480 | var->v.memb = value; \ |
@@ -483,22 +489,22 @@ DEF(real, VCL_REAL, r) | |||
483 | DEF(duration, VCL_DURATION, d) | 489 | DEF(duration, VCL_DURATION, d) |
484 | 490 | ||
485 | VCL_BOOL | 491 | VCL_BOOL |
486 | vmod_defined(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) | 492 | vmod_defined(VARIABLE_CTX ctx, VCL_STRING name) |
487 | { | 493 | { |
488 | return !!getvar(get_symtab(priv), name); | 494 | return !!getvar(get_symtab(ctx), name); |
489 | } | 495 | } |
490 | 496 | ||
491 | VCL_STRING | 497 | VCL_STRING |
492 | vmod_type_of(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name) | 498 | vmod_type_of(VARIABLE_CTX ctx, VCL_STRING name) |
493 | { | 499 | { |
494 | struct variable *var = getvar(get_symtab(priv), name); | 500 | struct variable *var = getvar(get_symtab(ctx), name); |
495 | return typestr[var ? var->type : variable_unset]; | 501 | return typestr[var ? var->type : variable_unset]; |
496 | } |