comparison src/core/ngx_array.c @ 485:4ebe09b07e30 release-0.1.17

nginx-0.1.17-RELEASE import *) Change: the ngx_http_rewrite_module was rewritten from the scratch. Now it is possible to redirect, to return the error codes, to check the variables and referrers. The directives can be used inside locations. The redirect directive was canceled. *) Feature: the ngx_http_geo_module. *) Feature: the proxy_set_x_var and fastcgi_set_var directives. *) Bugfix: the location configuration with "=" modifier may be used in another location. *) Bugfix: the correct content type was set only for requests that use small caps letters in extension. *) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the location, and access was denied, and the error was redirected to a static page, then the segmentation fault occurred. *) Bugfix: if in a proxied "Location" header was a relative URL, then a host name and a slash were added to them; the bug had appeared in 0.1.14. *) Bugfix: the system error message was not logged on Linux.
author Igor Sysoev <igor@sysoev.ru>
date Thu, 03 Feb 2005 19:33:37 +0000
parents 42d11f017717
children d4ea69372b94
comparison
equal deleted inserted replaced
484:60452f1c0c62 485:4ebe09b07e30
6 6
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 9
10 10
11 ngx_array_t *ngx_create_array(ngx_pool_t *p, ngx_uint_t n, size_t size) 11 ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size)
12 { 12 {
13 ngx_array_t *a; 13 ngx_array_t *a;
14 14
15 ngx_test_null(a, ngx_palloc(p, sizeof(ngx_array_t)), NULL); 15 if (!(a = ngx_palloc(p, sizeof(ngx_array_t)))) {
16 return NULL;
17 }
16 18
17 ngx_test_null(a->elts, ngx_palloc(p, n * size), NULL); 19 if (!(a->elts = ngx_palloc(p, n * size))) {
20 return NULL;
21 }
18 22
23 a->nelts = 0;
24 a->size = size;
25 a->nalloc = n;
19 a->pool = p; 26 a->pool = p;
20 a->nelts = 0;
21 a->nalloc = n;
22 a->size = size;
23 27
24 return a; 28 return a;
25 } 29 }
26 30
27 31
28 void ngx_destroy_array(ngx_array_t *a) 32 void ngx_array_destroy(ngx_array_t *a)
29 { 33 {
30 ngx_pool_t *p; 34 ngx_pool_t *p;
31 35
32 p = a->pool; 36 p = a->pool;
33 37
34 if ((char *) a->elts + a->size * a->nalloc == p->last) { 38 if ((u_char *) a->elts + a->size * a->nalloc == p->last) {
35 p->last -= a->size * a->nalloc; 39 p->last -= a->size * a->nalloc;
36 } 40 }
37 41
38 if ((char *) a + sizeof(ngx_array_t) == p->last) { 42 if ((u_char *) a + sizeof(ngx_array_t) == p->last) {
39 p->last = (char *) a; 43 p->last = (u_char *) a;
40 } 44 }
41 } 45 }
42 46
43 47
44 void *ngx_push_array(ngx_array_t *a) 48 void *ngx_array_push(ngx_array_t *a)
45 { 49 {
46 void *elt, *new; 50 void *elt, *new;
51 size_t size;
47 ngx_pool_t *p; 52 ngx_pool_t *p;
48 53
49 /* array is full */
50 if (a->nelts == a->nalloc) { 54 if (a->nelts == a->nalloc) {
55
56 /* the array is full */
57
58 size = a->size * a->nalloc;
59
51 p = a->pool; 60 p = a->pool;
52 61
53 /* array allocation is the last in the pool */ 62 if ((u_char *) a->elts + size == p->last && p->last + a->size <= p->end)
54 if ((char *) a->elts + a->size * a->nelts == p->last
55 && (unsigned) (p->end - p->last) >= a->size)
56 { 63 {
64 /*
65 * the array allocation is the last in the pool
66 * and there is space for new allocation
67 */
68
57 p->last += a->size; 69 p->last += a->size;
58 a->nalloc++; 70 a->nalloc++;
59 71
60 /* allocate new array */
61 } else { 72 } else {
62 ngx_test_null(new, ngx_palloc(p, 2 * a->nalloc * a->size), NULL); 73 /* allocate a new array */
63 74
64 ngx_memcpy(new, a->elts, a->nalloc * a->size); 75 if (!(new = ngx_palloc(p, 2 * size))) {
76 return NULL;
77 }
78
79 ngx_memcpy(new, a->elts, size);
65 a->elts = new; 80 a->elts = new;
66 a->nalloc *= 2; 81 a->nalloc *= 2;
67 } 82 }
68 } 83 }
69 84
70 elt = (char *) a->elts + a->size * a->nelts; 85 elt = (u_char *) a->elts + a->size * a->nelts;
71 a->nelts++; 86 a->nelts++;
72 87
73 return elt; 88 return elt;
74 } 89 }
90
91
92 void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n)
93 {
94 void *elt, *new;
95 size_t size;
96 ngx_uint_t nalloc;
97 ngx_pool_t *p;
98
99 size = n * a->size;
100
101 if (a->nelts + n > a->nalloc) {
102
103 /* the array is full */
104
105 p = a->pool;
106
107 if ((u_char *) a->elts + a->size * a->nalloc == p->last
108 && p->last + size <= p->end)
109 {
110 /*
111 * the array allocation is the last in the pool
112 * and there is space for new allocation
113 */
114
115 p->last += size;
116 a->nalloc += n;
117
118 } else {
119 /* allocate a new array */
120
121 nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
122
123 if (!(new = ngx_palloc(p, nalloc * a->size))) {
124 return NULL;
125 }
126
127 ngx_memcpy(new, a->elts, a->nelts * a->size);
128 a->elts = new;
129 a->nalloc = nalloc;
130 }
131 }
132
133 elt = (u_char *) a->elts + a->size * a->nelts;
134 a->nelts += n;
135
136 return elt;
137 }