*) add ngx_palloc_aligned() to allocate explicitlty aligned memory
*) allows non-aligned memory blocks for small allocations and for odd
length strings on all platforms
*) use ngx_palloc_aligned()
Igor Sysoev
14 years ago
98 | 98 | |
99 | 99 | for ( ;; ) { |
100 | 100 | |
101 | #if (NGX_HAVE_NONALIGNED) | |
102 | ||
103 | 101 | /* |
104 | 102 | * allow non-aligned memory blocks for small allocations (1, 2, |
105 | 103 | * or 3 bytes) and for odd length strings (struct's have aligned |
109 | 107 | if (size < sizeof(int) || (size & 1)) { |
110 | 108 | m = p->last; |
111 | 109 | |
112 | } else | |
113 | #endif | |
114 | ||
115 | { | |
110 | } else { | |
116 | 111 | m = ngx_align_ptr(p->last, NGX_ALIGNMENT); |
117 | 112 | } |
118 | 113 | |
173 | 168 | pool->large = large; |
174 | 169 | |
175 | 170 | return p; |
171 | } | |
172 | ||
173 | ||
174 | void * | |
175 | ngx_palloc_aligned(ngx_pool_t *pool, size_t size) | |
176 | { | |
177 | if (size & 1) { | |
178 | size++; | |
179 | } | |
180 | ||
181 | return ngx_palloc(pool, size); | |
176 | 182 | } |
177 | 183 | |
178 | 184 |
68 | 68 | void ngx_destroy_pool(ngx_pool_t *pool); |
69 | 69 | |
70 | 70 | void *ngx_palloc(ngx_pool_t *pool, size_t size); |
71 | void *ngx_palloc_aligned(ngx_pool_t *pool, size_t size); | |
71 | 72 | void *ngx_pcalloc(ngx_pool_t *pool, size_t size); |
72 | 73 | ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p); |
73 | 74 |
164 | 164 | #endif |
165 | 165 | |
166 | 166 | if (pool) { |
167 | return ngx_palloc(pool, size); | |
167 | return ngx_palloc_aligned(pool, size); | |
168 | 168 | } |
169 | 169 | |
170 | 170 | return NULL; |
1023 | 1023 | lq = (ngx_http_location_queue_t *) q; |
1024 | 1024 | len = lq->name->len - prefix; |
1025 | 1025 | |
1026 | node = ngx_pcalloc(cf->pool, | |
1027 | offsetof(ngx_http_location_tree_node_t, name) + len); | |
1026 | node = ngx_palloc_aligned(cf->pool, | |
1027 | offsetof(ngx_http_location_tree_node_t, name) + len); | |
1028 | 1028 | if (node == NULL) { |
1029 | 1029 | return NULL; |
1030 | 1030 | } |
1031 | 1031 | |
1032 | node->left = NULL; | |
1033 | node->right = NULL; | |
1034 | node->tree = NULL; | |
1032 | 1035 | node->exact = lq->exact; |
1033 | 1036 | node->inclusive = lq->inclusive; |
1034 | 1037 |