From 5c68caa6d7b2d2a9ec899b034c8f553a997ce52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sat, 19 Mar 2016 15:27:38 +0000 Subject: [PATCH] [core] replace array weakref with vector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Stefan Bühler git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3116 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/array.c | 12 ++++-------- src/array.h | 18 ++++++++++-------- src/configfile-glue.c | 4 ++-- src/configfile.c | 7 +++---- src/configfile.h | 2 +- src/configparser.y | 8 ++++---- src/data_config.c | 27 ++++++++++++--------------- 8 files changed, 37 insertions(+), 42 deletions(-) diff --git a/NEWS b/NEWS index bbe3814c..97a4ed70 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,7 @@ NEWS * [core] truncate pidfile on exit (fixes #2695) * consistent inclusion of config.h at top of files (fixes #2073) * [core] add generic vector implementation + * [core] replace array weakref with vector - 1.4.39 - 2016-01-02 * [core] fix memset_s call (fixes #2698) diff --git a/src/array.c b/src/array.c index 189d54e3..21c3ba4a 100644 --- a/src/array.c +++ b/src/array.c @@ -49,10 +49,8 @@ void array_free(array *a) { size_t i; if (!a) return; - if (!a->is_weakref) { - for (i = 0; i < a->size; i++) { - if (a->data[i]) a->data[i]->free(a->data[i]); - } + for (i = 0; i < a->size; i++) { + if (a->data[i]) a->data[i]->free(a->data[i]); } if (a->data) free(a->data); @@ -65,10 +63,8 @@ void array_reset(array *a) { size_t i; if (!a) return; - if (!a->is_weakref) { - for (i = 0; i < a->used; i++) { - a->data[i]->reset(a->data[i]); - } + for (i = 0; i < a->used; i++) { + a->data[i]->reset(a->data[i]); } a->used = 0; diff --git a/src/array.h b/src/array.h index f6b3d0b1..88068224 100644 --- a/src/array.h +++ b/src/array.h @@ -7,6 +7,7 @@ #endif #include "buffer.h" +#include "vector.h" #include @@ -36,8 +37,6 @@ typedef struct { size_t size; size_t unique_ndx; - - int is_weakref; /* data is weakref, don't bother the data */ } array; typedef struct { @@ -101,7 +100,10 @@ typedef enum { * for compare: comp cond string/regex */ -typedef struct data_config { +typedef struct data_config data_config; +DEFINE_TYPED_VECTOR_NO_RELEASE(config_weak, data_config*); + +struct data_config { DATA_UNSET; array *value; @@ -113,19 +115,19 @@ typedef struct data_config { buffer *op; int context_ndx; /* more or less like an id */ - array *children; + vector_config_weak children; /* nested */ - struct data_config *parent; + data_config *parent; /* for chaining only */ - struct data_config *prev; - struct data_config *next; + data_config *prev; + data_config *next; buffer *string; #ifdef HAVE_PCRE_H pcre *regex; pcre_extra *regex_study; #endif -} data_config; +}; data_config *data_config_init(void); diff --git a/src/configfile-glue.c b/src/configfile-glue.c index ed4e1854..f89cfd6f 100644 --- a/src/configfile-glue.c +++ b/src/configfile-glue.c @@ -589,8 +589,8 @@ static void config_cond_clear_node(server *srv, connection *con, data_config *dc con->cond_cache[dc->context_ndx].comp_value = NULL; con->cond_cache[dc->context_ndx].result = COND_RESULT_UNSET; - for (i = 0; i < dc->children->used; ++i) { - data_config *dc_child = (data_config*) dc->children->data[i]; + for (i = 0; i < dc->children.used; ++i) { + data_config *dc_child = dc->children.data[i]; if (NULL == dc_child->prev) { /* only call for first node in if-else chain */ config_cond_clear_node(srv, con, dc_child); diff --git a/src/configfile.c b/src/configfile.c index d8ffafb9..170d5b6f 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -1102,13 +1102,12 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { static void context_init(server *srv, config_t *context) { context->srv = srv; context->ok = 1; - context->configs_stack = array_init(); - context->configs_stack->is_weakref = 1; + vector_config_weak_init(&context->configs_stack); context->basedir = buffer_init(); } static void context_free(config_t *context) { - array_free(context->configs_stack); + vector_config_weak_clear(&context->configs_stack); buffer_free(context->basedir); } @@ -1162,7 +1161,7 @@ int config_read(server *srv, const char *fn) { ret = config_parse_file(srv, &context, fn); /* remains nothing if parser is ok */ - force_assert(!(0 == ret && context.ok && 0 != context.configs_stack->used)); + force_assert(!(0 == ret && context.ok && 0 != context.configs_stack.used)); context_free(&context); if (0 != ret) { diff --git a/src/configfile.h b/src/configfile.h index 6c8d6b24..befb8402 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -10,7 +10,7 @@ typedef struct { server *srv; int ok; array *all_configs; - array *configs_stack; /* to parse nested block */ + vector_config_weak configs_stack; /* to parse nested block */ data_config *current; /* current started with { */ buffer *basedir; } config_t; diff --git a/src/configparser.y b/src/configparser.y index b5da5a9d..56a4bf9b 100644 --- a/src/configparser.y +++ b/src/configparser.y @@ -18,19 +18,19 @@ static void configparser_push(config_t *ctx, data_config *dc, int isnew) { force_assert(dc->context_ndx > ctx->current->context_ndx); array_insert_unique(ctx->all_configs, (data_unset *)dc); dc->parent = ctx->current; - array_insert_unique(dc->parent->children, (data_unset *)dc); + vector_config_weak_push(&dc->parent->children, dc); } - if (ctx->configs_stack->used > 0 && ctx->current->context_ndx == 0) { + if (ctx->configs_stack.used > 0 && ctx->current->context_ndx == 0) { fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n"); exit(-1); } - array_insert_unique(ctx->configs_stack, (data_unset *)ctx->current); + vector_config_weak_push(&ctx->configs_stack, ctx->current); ctx->current = dc; } static data_config *configparser_pop(config_t *ctx) { data_config *old = ctx->current; - ctx->current = (data_config *) array_pop(ctx->configs_stack); + ctx->current = vector_config_weak_pop(&ctx->configs_stack); return old; } diff --git a/src/data_config.c b/src/data_config.c index d8aafcef..ae7aa1dc 100644 --- a/src/data_config.c +++ b/src/data_config.c @@ -25,7 +25,7 @@ static void data_config_free(data_unset *d) { buffer_free(ds->comp_key); array_free(ds->value); - array_free(ds->children); + vector_config_weak_clear(&ds->children); if (ds->string) buffer_free(ds->string); #ifdef HAVE_PCRE_H @@ -86,18 +86,16 @@ static void data_config_print(const data_unset *d, int depth) { fprintf(stdout, "\n"); } - if (ds->children) { - fprintf(stdout, "\n"); - for (i = 0; i < ds->children->used; i ++) { - data_unset *du = ds->children->data[i]; - - /* only the 1st block of chaining */ - if (NULL == ((data_config *)du)->prev) { - fprintf(stdout, "\n"); - array_print_indent(depth); - du->print(du, depth); - fprintf(stdout, "\n"); - } + fprintf(stdout, "\n"); + for (i = 0; i < ds->children.used; i ++) { + data_config *dc = ds->children.data[i]; + + /* only the 1st block of chaining */ + if (NULL == dc->prev) { + fprintf(stdout, "\n"); + array_print_indent(depth); + dc->print((data_unset *) dc, depth); + fprintf(stdout, "\n"); } } @@ -126,8 +124,7 @@ data_config *data_config_init(void) { ds->op = buffer_init(); ds->comp_key = buffer_init(); ds->value = array_init(); - ds->children = array_init(); - ds->children->is_weakref = 1; + vector_config_weak_init(&ds->children); ds->copy = data_config_copy; ds->free = data_config_free;