aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_array.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-01-09 05:36:00 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-01-09 05:36:00 +0000
commit4e9393a0548d783cd6f50d1fcd003c85a24b2b16 (patch)
tree300b40876e7ea6c103b7a080e380cdaaaf31260e /src/core/ngx_array.c
parentc1817846d29be14903e40a0551f706ff50e09dcf (diff)
downloadnginx-4e9393a0548d783cd6f50d1fcd003c85a24b2b16.tar.gz
nginx-4e9393a0548d783cd6f50d1fcd003c85a24b2b16.zip
nginx-0.0.1-2003-01-09-08:36:00 import
Diffstat (limited to 'src/core/ngx_array.c')
-rw-r--r--src/core/ngx_array.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/core/ngx_array.c b/src/core/ngx_array.c
index 08ad5887b..0043929e9 100644
--- a/src/core/ngx_array.c
+++ b/src/core/ngx_array.c
@@ -2,19 +2,17 @@
#include <ngx_config.h>
#include <ngx_alloc.h>
+#include <ngx_string.h>
#include <ngx_array.h>
+
ngx_array_t *ngx_create_array(ngx_pool_t *p, int n, size_t size)
{
ngx_array_t *a;
- a = ngx_palloc(p, sizeof(ngx_array_t));
- if (a == NULL)
- return NULL;
+ ngx_test_null(a, ngx_palloc(p, sizeof(ngx_array_t)), NULL);
- a->elts = ngx_palloc(p, n * size);
- if (a->elts == NULL)
- return NULL;
+ ngx_test_null(a->elts, ngx_palloc(p, n * size), NULL);
a->pool = p;
a->nelts = 0;
@@ -24,24 +22,31 @@ ngx_array_t *ngx_create_array(ngx_pool_t *p, int n, size_t size)
return a;
}
+
void ngx_destroy_array(ngx_array_t *a)
{
- ngx_pool_t *p = a->pool;
+ ngx_pool_t *p;
+
+ p = a->pool;
- if (a->elts + a->size * a->nalloc == p->last)
+ if (a->elts + a->size * a->nalloc == p->last) {
p->last -= a->size * a->nalloc;
+ }
- if ((char *) a + sizeof(ngx_array_t) == p->last)
+ if ((char *) a + sizeof(ngx_array_t) == p->last) {
p->last = (char *) a;
+ }
}
+
void *ngx_push_array(ngx_array_t *a)
{
- void *elt;
+ void *elt, *new;
+ ngx_pool_t *p;
/* array is full */
if (a->nelts == a->nalloc) {
- ngx_pool_t *p = a->pool;
+ p = a->pool;
/* array allocation is the last in the pool */
if (a->elts + a->size * a->nelts == p->last
@@ -52,11 +57,9 @@ void *ngx_push_array(ngx_array_t *a)
/* allocate new array */
} else {
- void *new = ngx_palloc(p, 2 * a->nalloc * a->size);
- if (new == NULL)
- return NULL;
+ ngx_test_null(new, ngx_palloc(p, 2 * a->nalloc * a->size), NULL);
- memcpy(new, a->elts, a->nalloc * a->size);
+ ngx_memcpy(new, a->elts, a->nalloc * a->size);
a->elts = new;
a->nalloc *= 2;
}