comparison src/core/ngx_palloc.c @ 270:6eb1e38f0f1f NGINX_0_5_5

nginx 0.5.5 *) Change: the -v switch does not show compiler information any more. *) Feature: the -V switch. *) Feature: the "worker_rlimit_core" directive supports size in K, M, and G. *) Bugfix: the nginx.pm module now could be installed by an unprivileged user. *) Bugfix: a segmentation fault might occur if the $r->request_body or $r->request_body_file methods were used. *) Bugfix: the ppc platform specific bugs.
author Igor Sysoev <http://sysoev.ru>
date Sun, 24 Dec 2006 00:00:00 +0300
parents 6ae1357b7b7c
children 704622b2528a
comparison
equal deleted inserted replaced
269:aa9c0062124d 270:6eb1e38f0f1f
83 83
84 void * 84 void *
85 ngx_palloc(ngx_pool_t *pool, size_t size) 85 ngx_palloc(ngx_pool_t *pool, size_t size)
86 { 86 {
87 u_char *m; 87 u_char *m;
88 ngx_pool_t *p, *n; 88 ngx_pool_t *p, *n, *current;
89 ngx_pool_large_t *large; 89 ngx_pool_large_t *large;
90 90
91 if (size <= (size_t) NGX_MAX_ALLOC_FROM_POOL 91 if (size <= (size_t) NGX_MAX_ALLOC_FROM_POOL
92 && size <= (size_t) (pool->end - (u_char *) pool) 92 && size <= (size_t) (pool->end - (u_char *) pool)
93 - (size_t) ngx_align_ptr(sizeof(ngx_pool_t), NGX_ALIGNMENT)) 93 - (size_t) ngx_align_ptr(sizeof(ngx_pool_t), NGX_ALIGNMENT))
94 { 94 {
95 for (p = pool->current; /* void */ ; p = p->next) { 95 p = pool->current;
96 current = p;
97
98 for ( ;; ) {
96 99
97 if (size < sizeof(int) || (size & 1)) { 100 if (size < sizeof(int) || (size & 1)) {
98 m = p->last; 101 m = p->last;
99 102
100 } else { 103 } else {
106 109
107 return m; 110 return m;
108 } 111 }
109 112
110 if ((size_t) (p->end - m) < NGX_ALIGNMENT) { 113 if ((size_t) (p->end - m) < NGX_ALIGNMENT) {
111 pool->current = p->next; 114 current = p->next;
112 } 115 }
113 116
114 if (p->next == NULL) { 117 if (p->next == NULL) {
115 break; 118 break;
116 } 119 }
120
121 p = p->next;
122 pool->current = current;
117 } 123 }
118 124
119 /* allocate a new pool block */ 125 /* allocate a new pool block */
120 126
121 n = ngx_create_pool((size_t) (p->end - (u_char *) p), p->log); 127 n = ngx_create_pool((size_t) (p->end - (u_char *) p), p->log);
122 if (n == NULL) { 128 if (n == NULL) {
123 return NULL; 129 return NULL;
124 } 130 }
125 131
126 if (pool->current == NULL) { 132 pool->current = current ? current : n;
127 pool->current = n;
128 }
129 133
130 p->next = n; 134 p->next = n;
131 m = ngx_align_ptr(n->last, NGX_ALIGNMENT); 135 m = ngx_align_ptr(n->last, NGX_ALIGNMENT);
132 n->last = m + size; 136 n->last = m + size;
133 137