mirror of
https://github.com/openresty/openresty
synced 2024-11-14 08:45:50 +01:00
607 lines
14 KiB
Diff
607 lines
14 KiB
Diff
diff -upr nginx-1.5.9/src/core/nginx.h nginx-1.5.9-patched/src/core/nginx.h
|
|
--- nginx-1.5.9/src/core/nginx.h 2013-05-06 03:26:50.000000000 -0700
|
|
+++ nginx-1.5.9-patched/src/core/nginx.h 2013-06-10 16:12:23.691136795 -0700
|
|
@@ -10,7 +10,7 @@
|
|
|
|
|
|
#define nginx_version 1005009
|
|
#define NGINX_VERSION "1.5.9"
|
|
-#define NGINX_VER "openresty/" NGINX_VERSION ".unknown"
|
|
+#define NGINX_VER "openresty/" NGINX_VERSION ".unknown (no pool)"
|
|
|
|
#define NGINX_VAR "NGINX"
|
|
diff -urp nginx-1.5.9/src/core/ngx_array.c nginx-1.5.9-patched/src/core/ngx_array.c
|
|
--- nginx-1.5.9/src/core/ngx_array.c 2014-01-22 05:43:00.000000000 -0800
|
|
+++ nginx-1.5.9-patched/src/core/ngx_array.c 2014-01-27 21:25:14.887049509 -0800
|
|
@@ -30,26 +30,30 @@ ngx_array_create(ngx_pool_t *p, ngx_uint
|
|
void
|
|
ngx_array_destroy(ngx_array_t *a)
|
|
{
|
|
- ngx_pool_t *p;
|
|
+ ngx_pool_t *p;
|
|
+ ngx_array_link_t *link;
|
|
|
|
p = a->pool;
|
|
|
|
- if ((u_char *) a->elts + a->size * a->nalloc == p->d.last) {
|
|
- p->d.last -= a->size * a->nalloc;
|
|
+ if (a->elts) {
|
|
+ ngx_pfree(p, a->elts);
|
|
}
|
|
|
|
- if ((u_char *) a + sizeof(ngx_array_t) == p->d.last) {
|
|
- p->d.last = (u_char *) a;
|
|
+ for (link = a->old_elts; link; link = link->next) {
|
|
+ ngx_pfree(p, link->elts);
|
|
}
|
|
+
|
|
+ ngx_pfree(p, a);
|
|
}
|
|
|
|
|
|
void *
|
|
ngx_array_push(ngx_array_t *a)
|
|
{
|
|
- void *elt, *new;
|
|
- size_t size;
|
|
- ngx_pool_t *p;
|
|
+ void *elt, *new;
|
|
+ size_t size;
|
|
+ ngx_pool_t *p;
|
|
+ ngx_array_link_t *link;
|
|
|
|
if (a->nelts == a->nalloc) {
|
|
|
|
@@ -59,29 +63,27 @@ ngx_array_push(ngx_array_t *a)
|
|
|
|
p = a->pool;
|
|
|
|
- if ((u_char *) a->elts + size == p->d.last
|
|
- && p->d.last + a->size <= p->d.end)
|
|
- {
|
|
- /*
|
|
- * the array allocation is the last in the pool
|
|
- * and there is space for new allocation
|
|
- */
|
|
-
|
|
- p->d.last += a->size;
|
|
- a->nalloc++;
|
|
-
|
|
- } else {
|
|
- /* allocate a new array */
|
|
-
|
|
- new = ngx_palloc(p, 2 * size);
|
|
- if (new == NULL) {
|
|
- return NULL;
|
|
- }
|
|
-
|
|
- ngx_memcpy(new, a->elts, size);
|
|
- a->elts = new;
|
|
- a->nalloc *= 2;
|
|
+ /* allocate a new array */
|
|
+
|
|
+ new = ngx_palloc(p, 2 * size);
|
|
+ if (new == NULL) {
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ ngx_memcpy(new, a->elts, size);
|
|
+
|
|
+ link = ngx_palloc(p, sizeof(ngx_array_link_t));
|
|
+ if (link == NULL) {
|
|
+ ngx_pfree(p, new);
|
|
+ return NULL;
|
|
}
|
|
+
|
|
+ link->next = a->old_elts;
|
|
+ link->elts = a->elts;
|
|
+ a->old_elts = link;
|
|
+
|
|
+ a->elts = new;
|
|
+ a->nalloc *= 2;
|
|
}
|
|
|
|
elt = (u_char *) a->elts + a->size * a->nelts;
|
|
@@ -95,11 +97,10 @@ void *
|
|
ngx_array_push_n(ngx_array_t *a, ngx_uint_t n)
|
|
{
|
|
void *elt, *new;
|
|
- size_t size;
|
|
ngx_uint_t nalloc;
|
|
ngx_pool_t *p;
|
|
|
|
- size = n * a->size;
|
|
+ ngx_array_link_t *link;
|
|
|
|
if (a->nelts + n > a->nalloc) {
|
|
|
|
@@ -107,31 +108,27 @@ ngx_array_push_n(ngx_array_t *a, ngx_uin
|
|
|
|
p = a->pool;
|
|
|
|
- if ((u_char *) a->elts + a->size * a->nalloc == p->d.last
|
|
- && p->d.last + size <= p->d.end)
|
|
- {
|
|
- /*
|
|
- * the array allocation is the last in the pool
|
|
- * and there is space for new allocation
|
|
- */
|
|
-
|
|
- p->d.last += size;
|
|
- a->nalloc += n;
|
|
-
|
|
- } else {
|
|
- /* allocate a new array */
|
|
-
|
|
- nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
|
|
-
|
|
- new = ngx_palloc(p, nalloc * a->size);
|
|
- if (new == NULL) {
|
|
- return NULL;
|
|
- }
|
|
-
|
|
- ngx_memcpy(new, a->elts, a->nelts * a->size);
|
|
- a->elts = new;
|
|
- a->nalloc = nalloc;
|
|
+ nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
|
|
+
|
|
+ new = ngx_palloc(p, nalloc * a->size);
|
|
+ if (new == NULL) {
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ ngx_memcpy(new, a->elts, a->nelts * a->size);
|
|
+
|
|
+ link = ngx_palloc(p, sizeof(ngx_array_link_t));
|
|
+ if (link == NULL) {
|
|
+ ngx_pfree(p, new);
|
|
+ return NULL;
|
|
}
|
|
+
|
|
+ link->next = a->old_elts;
|
|
+ link->elts = a->elts;
|
|
+ a->old_elts = link;
|
|
+
|
|
+ a->elts = new;
|
|
+ a->nalloc = nalloc;
|
|
}
|
|
|
|
elt = (u_char *) a->elts + a->size * a->nelts;
|
|
diff -urp nginx-1.5.9/src/core/ngx_array.h nginx-1.5.9-patched/src/core/ngx_array.h
|
|
--- nginx-1.5.9/src/core/ngx_array.h 2014-01-22 05:43:00.000000000 -0800
|
|
+++ nginx-1.5.9-patched/src/core/ngx_array.h 2014-01-27 21:25:14.888049518 -0800
|
|
@@ -13,12 +13,23 @@
|
|
#include <ngx_core.h>
|
|
|
|
|
|
+typedef struct ngx_array_link_s ngx_array_link_t;
|
|
+
|
|
+
|
|
+struct ngx_array_link_s {
|
|
+ void *elts;
|
|
+ ngx_array_link_t *next;
|
|
+};
|
|
+
|
|
+
|
|
typedef struct {
|
|
void *elts;
|
|
ngx_uint_t nelts;
|
|
size_t size;
|
|
ngx_uint_t nalloc;
|
|
ngx_pool_t *pool;
|
|
+
|
|
+ ngx_array_link_t *old_elts;
|
|
} ngx_array_t;
|
|
|
|
|
|
@@ -40,6 +51,7 @@ ngx_array_init(ngx_array_t *array, ngx_p
|
|
array->size = size;
|
|
array->nalloc = n;
|
|
array->pool = pool;
|
|
+ array->old_elts = NULL;
|
|
|
|
array->elts = ngx_palloc(pool, n * size);
|
|
if (array->elts == NULL) {
|
|
diff -urp nginx-1.5.9/src/core/ngx_palloc.c nginx-1.5.9-patched/src/core/ngx_palloc.c
|
|
--- nginx-1.5.9/src/core/ngx_palloc.c 2014-01-22 05:43:00.000000000 -0800
|
|
+++ nginx-1.5.9-patched/src/core/ngx_palloc.c 2014-01-27 21:42:30.905552064 -0800
|
|
@@ -9,32 +9,23 @@
|
|
#include <ngx_core.h>
|
|
|
|
|
|
-static void *ngx_palloc_block(ngx_pool_t *pool, size_t size);
|
|
-static void *ngx_palloc_large(ngx_pool_t *pool, size_t size);
|
|
-
|
|
-
|
|
ngx_pool_t *
|
|
ngx_create_pool(size_t size, ngx_log_t *log)
|
|
{
|
|
- ngx_pool_t *p;
|
|
+ ngx_pool_t *p;
|
|
|
|
- p = ngx_memalign(NGX_POOL_ALIGNMENT, size, log);
|
|
+ size = sizeof(ngx_pool_t);
|
|
+ p = ngx_alloc(size, log);
|
|
if (p == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
- p->d.last = (u_char *) p + sizeof(ngx_pool_t);
|
|
- p->d.end = (u_char *) p + size;
|
|
- p->d.next = NULL;
|
|
- p->d.failed = 0;
|
|
+ ngx_memzero(p, size);
|
|
|
|
size = size - sizeof(ngx_pool_t);
|
|
p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL;
|
|
|
|
p->current = p;
|
|
- p->chain = NULL;
|
|
- p->large = NULL;
|
|
- p->cleanup = NULL;
|
|
p->log = log;
|
|
|
|
return p;
|
|
@@ -44,8 +35,7 @@ ngx_create_pool(size_t size, ngx_log_t *
|
|
void
|
|
ngx_destroy_pool(ngx_pool_t *pool)
|
|
{
|
|
- ngx_pool_t *p, *n;
|
|
- ngx_pool_large_t *l;
|
|
+ ngx_pool_data_t *d, *n;
|
|
ngx_pool_cleanup_t *c;
|
|
|
|
for (c = pool->cleanup; c; c = c->next) {
|
|
@@ -56,13 +46,9 @@ ngx_destroy_pool(ngx_pool_t *pool)
|
|
}
|
|
}
|
|
|
|
- for (l = pool->large; l; l = l->next) {
|
|
-
|
|
- ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc);
|
|
-
|
|
- if (l->alloc) {
|
|
- ngx_free(l->alloc);
|
|
- }
|
|
+ if (pool->d == NULL) {
|
|
+ ngx_free(pool);
|
|
+ return;
|
|
}
|
|
|
|
#if (NGX_DEBUG)
|
|
@@ -72,9 +58,9 @@ ngx_destroy_pool(ngx_pool_t *pool)
|
|
* so we cannot use this log while free()ing the pool
|
|
*/
|
|
|
|
- for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) {
|
|
+ for (d = pool->d, n = d->next; ; d = n, n = n->next) {
|
|
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
|
|
- "free: %p, unused: %uz", p, p->d.end - p->d.last);
|
|
+ "free: %p, unused: %d", d, 0);
|
|
|
|
if (n == NULL) {
|
|
break;
|
|
@@ -83,175 +69,84 @@ ngx_destroy_pool(ngx_pool_t *pool)
|
|
|
|
#endif
|
|
|
|
- for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) {
|
|
- ngx_free(p);
|
|
+ for (d = pool->d, n = d->next; ; d = n, n = n->next) {
|
|
+ ngx_free(d->alloc);
|
|
+ ngx_free(d);
|
|
|
|
if (n == NULL) {
|
|
break;
|
|
}
|
|
}
|
|
-}
|
|
|
|
+ pool->d = NULL;
|
|
|
|
-void
|
|
-ngx_reset_pool(ngx_pool_t *pool)
|
|
-{
|
|
- ngx_pool_t *p;
|
|
- ngx_pool_large_t *l;
|
|
-
|
|
- for (l = pool->large; l; l = l->next) {
|
|
- if (l->alloc) {
|
|
- ngx_free(l->alloc);
|
|
- }
|
|
- }
|
|
-
|
|
- for (p = pool; p; p = p->d.next) {
|
|
- p->d.last = (u_char *) p + sizeof(ngx_pool_t);
|
|
- p->d.failed = 0;
|
|
- }
|
|
-
|
|
- pool->current = pool;
|
|
- pool->chain = NULL;
|
|
- pool->large = NULL;
|
|
+ ngx_free(pool);
|
|
}
|
|
|
|
|
|
-void *
|
|
-ngx_palloc(ngx_pool_t *pool, size_t size)
|
|
+void
|
|
+ngx_reset_pool(ngx_pool_t *pool)
|
|
{
|
|
- u_char *m;
|
|
- ngx_pool_t *p;
|
|
-
|
|
- if (size <= pool->max) {
|
|
+ ngx_pool_data_t *d, *n;
|
|
+ ngx_pool_data_t *saved = NULL;
|
|
|
|
- p = pool->current;
|
|
-
|
|
- do {
|
|
- m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT);
|
|
-
|
|
- if ((size_t) (p->d.end - m) >= size) {
|
|
- p->d.last = m + size;
|
|
-
|
|
- return m;
|
|
+ if (pool->d) {
|
|
+ for (d = pool->d, n = d->next; ; d = n, n = n->next) {
|
|
+ if (d->alloc == pool->log) {
|
|
+ saved = d;
|
|
+ continue;
|
|
}
|
|
|
|
- p = p->d.next;
|
|
-
|
|
- } while (p);
|
|
-
|
|
- return ngx_palloc_block(pool, size);
|
|
- }
|
|
-
|
|
- return ngx_palloc_large(pool, size);
|
|
-}
|
|
-
|
|
-
|
|
-void *
|
|
-ngx_pnalloc(ngx_pool_t *pool, size_t size)
|
|
-{
|
|
- u_char *m;
|
|
- ngx_pool_t *p;
|
|
-
|
|
- if (size <= pool->max) {
|
|
-
|
|
- p = pool->current;
|
|
-
|
|
- do {
|
|
- m = p->d.last;
|
|
-
|
|
- if ((size_t) (p->d.end - m) >= size) {
|
|
- p->d.last = m + size;
|
|
+ ngx_free(d->alloc);
|
|
+ ngx_free(d);
|
|
|
|
- return m;
|
|
+ if (n == NULL) {
|
|
+ break;
|
|
}
|
|
+ }
|
|
|
|
- p = p->d.next;
|
|
-
|
|
- } while (p);
|
|
-
|
|
- return ngx_palloc_block(pool, size);
|
|
+ pool->d = saved;
|
|
+ pool->current = pool;
|
|
+ pool->chain = NULL;
|
|
}
|
|
-
|
|
- return ngx_palloc_large(pool, size);
|
|
}
|
|
|
|
|
|
-static void *
|
|
-ngx_palloc_block(ngx_pool_t *pool, size_t size)
|
|
+void *
|
|
+ngx_malloc(ngx_pool_t *pool, size_t size)
|
|
{
|
|
- u_char *m;
|
|
- size_t psize;
|
|
- ngx_pool_t *p, *new, *current;
|
|
+ ngx_pool_data_t *d;
|
|
+ void *p;
|
|
|
|
- psize = (size_t) (pool->d.end - (u_char *) pool);
|
|
-
|
|
- m = ngx_memalign(NGX_POOL_ALIGNMENT, psize, pool->log);
|
|
- if (m == NULL) {
|
|
+ p = ngx_alloc(size, pool->log);
|
|
+ if (p == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
- new = (ngx_pool_t *) m;
|
|
-
|
|
- new->d.end = m + psize;
|
|
- new->d.next = NULL;
|
|
- new->d.failed = 0;
|
|
-
|
|
- m += sizeof(ngx_pool_data_t);
|
|
- m = ngx_align_ptr(m, NGX_ALIGNMENT);
|
|
- new->d.last = m + size;
|
|
-
|
|
- current = pool->current;
|
|
-
|
|
- for (p = current; p->d.next; p = p->d.next) {
|
|
- if (p->d.failed++ > 4) {
|
|
- current = p->d.next;
|
|
- }
|
|
+ d = ngx_alloc(sizeof(ngx_pool_data_t), pool->log);
|
|
+ if (d == NULL){
|
|
+ ngx_free(p);
|
|
+ return NULL;
|
|
}
|
|
|
|
- p->d.next = new;
|
|
-
|
|
- pool->current = current ? current : new;
|
|
-
|
|
- return m;
|
|
+ d->alloc = p;
|
|
+ d->next = pool->d;
|
|
+ pool->d = d;
|
|
+ return p;
|
|
}
|
|
|
|
|
|
-static void *
|
|
-ngx_palloc_large(ngx_pool_t *pool, size_t size)
|
|
+void *
|
|
+ngx_palloc(ngx_pool_t *pool, size_t size)
|
|
{
|
|
- void *p;
|
|
- ngx_uint_t n;
|
|
- ngx_pool_large_t *large;
|
|
-
|
|
- p = ngx_alloc(size, pool->log);
|
|
- if (p == NULL) {
|
|
- return NULL;
|
|
- }
|
|
-
|
|
- n = 0;
|
|
-
|
|
- for (large = pool->large; large; large = large->next) {
|
|
- if (large->alloc == NULL) {
|
|
- large->alloc = p;
|
|
- return p;
|
|
- }
|
|
-
|
|
- if (n++ > 3) {
|
|
- break;
|
|
- }
|
|
- }
|
|
-
|
|
- large = ngx_palloc(pool, sizeof(ngx_pool_large_t));
|
|
- if (large == NULL) {
|
|
- ngx_free(p);
|
|
- return NULL;
|
|
- }
|
|
+ return ngx_malloc(pool, size);
|
|
+}
|
|
|
|
- large->alloc = p;
|
|
- large->next = pool->large;
|
|
- pool->large = large;
|
|
|
|
- return p;
|
|
+void *
|
|
+ngx_pnalloc(ngx_pool_t *pool, size_t size)
|
|
+{
|
|
+ return ngx_malloc(pool, size);
|
|
}
|
|
|
|
|
|
@@ -259,38 +154,48 @@ void *
|
|
ngx_pmemalign(ngx_pool_t *pool, size_t size, size_t alignment)
|
|
{
|
|
void *p;
|
|
- ngx_pool_large_t *large;
|
|
+ ngx_pool_data_t *d;
|
|
|
|
p = ngx_memalign(alignment, size, pool->log);
|
|
if (p == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
- large = ngx_palloc(pool, sizeof(ngx_pool_large_t));
|
|
- if (large == NULL) {
|
|
+ d = ngx_alloc(sizeof(ngx_pool_data_t), pool->log);
|
|
+ if (d == NULL){
|
|
ngx_free(p);
|
|
return NULL;
|
|
}
|
|
|
|
- large->alloc = p;
|
|
- large->next = pool->large;
|
|
- pool->large = large;
|
|
-
|
|
+ d->alloc = p;
|
|
+ d->next = pool->d;
|
|
+ pool->d = d;
|
|
return p;
|
|
}
|
|
|
|
|
|
ngx_int_t
|
|
-ngx_pfree(ngx_pool_t *pool, void *p)
|
|
+ngx_pfree(ngx_pool_t *pool, void *data)
|
|
{
|
|
- ngx_pool_large_t *l;
|
|
+ ngx_pool_data_t *p, *d;
|
|
|
|
- for (l = pool->large; l; l = l->next) {
|
|
- if (p == l->alloc) {
|
|
- ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
|
|
- "free: %p", l->alloc);
|
|
- ngx_free(l->alloc);
|
|
- l->alloc = NULL;
|
|
+ p = NULL;
|
|
+ for (d = pool->d; d; p = d, d = d->next) {
|
|
+ if (data == d->alloc) {
|
|
+
|
|
+ ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", d->alloc);
|
|
+
|
|
+ ngx_free(d->alloc);
|
|
+ d->alloc = NULL;
|
|
+
|
|
+ if (p) {
|
|
+ p->next = d->next;
|
|
+
|
|
+ } else {
|
|
+ pool->d = d->next;
|
|
+ }
|
|
+
|
|
+ ngx_free(d);
|
|
|
|
return NGX_OK;
|
|
}
|
|
diff -urp nginx-1.5.9/src/core/ngx_palloc.h nginx-1.5.9-patched/src/core/ngx_palloc.h
|
|
--- nginx-1.5.9/src/core/ngx_palloc.h 2014-01-22 05:43:00.000000000 -0800
|
|
+++ nginx-1.5.9-patched/src/core/ngx_palloc.h 2014-01-27 21:25:14.911049721 -0800
|
|
@@ -38,28 +38,21 @@ struct ngx_pool_cleanup_s {
|
|
};
|
|
|
|
|
|
-typedef struct ngx_pool_large_s ngx_pool_large_t;
|
|
-
|
|
-struct ngx_pool_large_s {
|
|
- ngx_pool_large_t *next;
|
|
- void *alloc;
|
|
-};
|
|
+typedef struct ngx_pool_data_s ngx_pool_large_t;
|
|
+typedef struct ngx_pool_data_s ngx_pool_data_t;
|
|
|
|
|
|
-typedef struct {
|
|
- u_char *last;
|
|
- u_char *end;
|
|
- ngx_pool_t *next;
|
|
- ngx_uint_t failed;
|
|
-} ngx_pool_data_t;
|
|
+struct ngx_pool_data_s {
|
|
+ ngx_pool_data_t *next;
|
|
+ void *alloc;
|
|
+};
|
|
|
|
|
|
struct ngx_pool_s {
|
|
- ngx_pool_data_t d;
|
|
+ ngx_pool_data_t *d;
|
|
size_t max;
|
|
ngx_pool_t *current;
|
|
ngx_chain_t *chain;
|
|
- ngx_pool_large_t *large;
|
|
ngx_pool_cleanup_t *cleanup;
|
|
ngx_log_t *log;
|
|
};
|