[core] replace array weakref with vector
From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3116 152afb58-edef-0310-8abb-c4023f1b3aa9svn/heads/lighttpd-1.4.x
parent
8455734f4a
commit
5c68caa6d7
1
NEWS
1
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)
|
||||
|
|
12
src/array.c
12
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;
|
||||
|
|
18
src/array.h
18
src/array.h
|
@ -7,6 +7,7 @@
|
|||
#endif
|
||||
|
||||
#include "buffer.h"
|
||||
#include "vector.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
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 == ((data_config *)du)->prev) {
|
||||
fprintf(stdout, "\n");
|
||||
array_print_indent(depth);
|
||||
du->print(du, depth);
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
/* 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;
|
||||
|
|
Loading…
Reference in New Issue