kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit b8c6cddc3d6f8143cfa1a9f5d0d9449bedd6643b
parent 0ea911140e0e0f02543af76a94b53c216830969c
Author: Joris Vink <joris@coders.se>
Date:   Tue,  7 Feb 2017 22:44:20 +0100

Revert "TAILQ_FOREACH_SAFE() exists so use it."

Because some asshole distributions claim to have a sane queue.h
implementation while they do not.

Diffstat:
src/cli.c | 6++++--
src/connection.c | 13+++++++++----
src/http.c | 26+++++++++++++++++++-------
src/module.c | 6++++--
src/pgsql.c | 9++++++---
5 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/src/cli.c b/src/cli.c @@ -1433,7 +1433,8 @@ cli_buildopt_cleanup(void) struct buildopt *bopt, *next; struct mime_type *mime, *mnext; - TAILQ_FOREACH_SAFE(bopt, &build_options, list, next) { + for (bopt = TAILQ_FIRST(&build_options); bopt != NULL; bopt = next) { + next = TAILQ_NEXT(bopt, list); TAILQ_REMOVE(&build_options, bopt, list); if (bopt->cflags != NULL) @@ -1449,7 +1450,8 @@ cli_buildopt_cleanup(void) kore_free(bopt); } - TAILQ_FOREACH_SAFE(mime, &mime_types, list, mnext) { + for (mime = TAILQ_FIRST(&mime_types); mime != NULL; mime = mnext) { + mnext = TAILQ_NEXT(mime, list); TAILQ_REMOVE(&mime_types, mime, list); kore_free(mime->type); kore_free(mime->ext); diff --git a/src/connection.c b/src/connection.c @@ -171,13 +171,15 @@ kore_connection_prune(int all) struct connection *c, *cnext; if (all) { - TAILQ_FOREACH_SAFE(c, &connections, list, cnext) { + for (c = TAILQ_FIRST(&connections); c != NULL; c = cnext) { + cnext = TAILQ_NEXT(c, list); net_send_flush(c); kore_connection_disconnect(c); } } - TAILQ_FOREACH_SAFE(c, &disconnected, list, cnext) { + for (c = TAILQ_FIRST(&disconnected); c != NULL; c = cnext) { + cnext = TAILQ_NEXT(c, list); TAILQ_REMOVE(&disconnected, c, list); kore_connection_remove(c); } @@ -333,7 +335,9 @@ kore_connection_remove(struct connection *c) kore_free(c->hdlr_extra); #if !defined(KORE_NO_HTTP) - TAILQ_FOREACH_SAFE(req, &(c->http_requests), olist, rnext) { + for (req = TAILQ_FIRST(&(c->http_requests)); + req != NULL; req = rnext) { + rnext = TAILQ_NEXT(req, olist); TAILQ_REMOVE(&(c->http_requests), req, olist); req->owner = NULL; req->flags |= HTTP_REQUEST_DELETE; @@ -345,7 +349,8 @@ kore_connection_remove(struct connection *c) kore_free(c->ws_disconnect); #endif - TAILQ_FOREACH_SAFE(nb, &(c->send_queue), list, next) { + for (nb = TAILQ_FIRST(&(c->send_queue)); nb != NULL; nb = next) { + next = TAILQ_NEXT(nb, list); TAILQ_REMOVE(&(c->send_queue), nb, list); if (!(nb->flags & NETBUF_IS_STREAM)) { kore_free(nb->buf); diff --git a/src/http.c b/src/http.c @@ -320,7 +320,7 @@ http_process(void) struct http_request *req, *next; count = 0; - TAILQ_FOREACH_SAFE(req, &http_requests, list, next) { + for (req = TAILQ_FIRST(&http_requests); req != NULL; req = next) { if (count >= http_request_limit) break; @@ -470,21 +470,27 @@ http_request_free(struct http_request *req) if (req->owner != NULL) TAILQ_REMOVE(&(req->owner->http_requests), req, olist); - TAILQ_FOREACH_SAFE(hdr, &(req->resp_headers), list, next) { + for (hdr = TAILQ_FIRST(&(req->resp_headers)); hdr != NULL; hdr = next) { + next = TAILQ_NEXT(hdr, list); + TAILQ_REMOVE(&(req->resp_headers), hdr, list); kore_free(hdr->header); kore_free(hdr->value); kore_pool_put(&http_header_pool, hdr); } - TAILQ_FOREACH_SAFE(hdr, &(req->req_headers), list, next) { + for (hdr = TAILQ_FIRST(&(req->req_headers)); hdr != NULL; hdr = next) { + next = TAILQ_NEXT(hdr, list); + TAILQ_REMOVE(&(req->req_headers), hdr, list); kore_free(hdr->header); kore_free(hdr->value); kore_pool_put(&http_header_pool, hdr); } - TAILQ_FOREACH_SAFE(ck, &(req->resp_cookies), list, cknext) { + for (ck = TAILQ_FIRST(&(req->resp_cookies)); ck != NULL; ck = cknext) { + cknext = TAILQ_NEXT(ck, list); + TAILQ_REMOVE(&(req->resp_cookies), ck, list); kore_free(ck->name); kore_free(ck->value); @@ -493,22 +499,28 @@ http_request_free(struct http_request *req) kore_pool_put(&http_cookie_pool, ck); } - TAILQ_FOREACH_SAFE(ck, &(req->req_cookies), list, cknext) { + for (ck = TAILQ_FIRST(&(req->req_cookies)); ck != NULL; ck = cknext) { + cknext = TAILQ_NEXT(ck, list); + TAILQ_REMOVE(&(req->req_cookies), ck, list); kore_free(ck->name); kore_free(ck->value); kore_pool_put(&http_cookie_pool, ck); } - TAILQ_FOREACH_SAFE(q, &(req->arguments), list, qnext) { + for (q = TAILQ_FIRST(&(req->arguments)); q != NULL; q = qnext) { + qnext = TAILQ_NEXT(q, list); + TAILQ_REMOVE(&(req->arguments), q, list); kore_free(q->name); kore_free(q->s_value); kore_free(q); } - TAILQ_FOREACH_SAFE(f, &(req->files), list, fnext) { + for (f = TAILQ_FIRST(&(req->files)); f != NULL; f = fnext) { + fnext = TAILQ_NEXT(f, list); TAILQ_REMOVE(&(req->files), f, list); + kore_free(f->filename); kore_free(f->name); kore_free(f); diff --git a/src/module.c b/src/module.c @@ -53,7 +53,8 @@ kore_module_cleanup(void) { struct kore_module *module, *next; - TAILQ_FOREACH_SAFE(module, &modules, list, next) { + for (module = TAILQ_FIRST(&modules); module != NULL; module = next) { + next = TAILQ_NEXT(module, list); TAILQ_REMOVE(&modules, module, list); module->fun->free(module); } @@ -275,7 +276,8 @@ kore_module_handler_free(struct kore_module_handle *hdlr) /* Drop all validators associated with this handler */ while ((param = TAILQ_FIRST(&(hdlr->params))) != NULL) { TAILQ_REMOVE(&(hdlr->params), param, list); - kore_free(param->name); + if (param->name != NULL) + kore_free(param->name); kore_free(param); } diff --git a/src/pgsql.c b/src/pgsql.c @@ -85,7 +85,8 @@ kore_pgsql_sys_cleanup(void) kore_pool_cleanup(&pgsql_job_pool); kore_pool_cleanup(&pgsql_wait_pool); - TAILQ_FOREACH_SAFE(conn, &pgsql_conn_free, list, next) { + for (conn = TAILQ_FIRST(&pgsql_conn_free); conn != NULL; conn = next) { + next = TAILQ_NEXT(conn, list); pgsql_conn_cleanup(conn); } } @@ -389,7 +390,8 @@ kore_pgsql_queue_remove(struct http_request *req) { struct pgsql_wait *pgw, *next; - TAILQ_FOREACH_SAFE(pgw, &pgsql_wait_queue, list, next) { + for (pgw = TAILQ_FIRST(&pgsql_wait_queue); pgw != NULL; pgw = next) { + next = TAILQ_NEXT(pgw, list); if (pgw->req != req) continue; @@ -479,7 +481,8 @@ pgsql_queue_wakeup(void) { struct pgsql_wait *pgw, *next; - TAILQ_FOREACH_SAFE(pgw, &pgsql_wait_queue, list, next) { + for (pgw = TAILQ_FIRST(&pgsql_wait_queue); pgw != NULL; pgw = next) { + next = TAILQ_NEXT(pgw, list); if (pgw->req->flags & HTTP_REQUEST_DELETE) continue;