Mercurial > hg > nginx
annotate src/core/ngx_palloc.c @ 1333:07ebeeb55700
escape space, etc in $memcached_key
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 22 Jul 2007 19:18:59 +0000 |
parents | 276b981ca92f |
children | d65172100f6b |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
5 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
8 #include <ngx_core.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
501 | 11 ngx_pool_t * |
12 ngx_create_pool(size_t size, ngx_log_t *log) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 { |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
14 ngx_pool_t *p; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
501 | 16 p = ngx_alloc(size, log); |
17 if (p == NULL) { | |
527 | 18 return NULL; |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
19 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
485 | 21 p->last = (u_char *) p + sizeof(ngx_pool_t); |
22 p->end = (u_char *) p + size; | |
581 | 23 p->current = p; |
24 p->chain = NULL; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 p->next = NULL; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 p->large = NULL; |
509 | 27 p->cleanup = NULL; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 p->log = log; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
33 |
501 | 34 void |
35 ngx_destroy_pool(ngx_pool_t *pool) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 { |
509 | 37 ngx_pool_t *p, *n; |
38 ngx_pool_large_t *l; | |
39 ngx_pool_cleanup_t *c; | |
40 | |
41 for (c = pool->cleanup; c; c = c->next) { | |
42 if (c->handler) { | |
43 c->handler(c->data); | |
44 } | |
45 } | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
47 for (l = pool->large; l; l = l->next) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
48 |
461 | 49 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc); |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
50 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
51 if (l->alloc) { |
477 | 52 ngx_free(l->alloc); |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
53 } |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
54 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
56 #if (NGX_DEBUG) |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
57 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
58 /* |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
59 * we could allocate the pool->log from this pool |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
60 * so we can not use this log while the free()ing the pool |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
61 */ |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
62 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
63 for (p = pool, n = pool->next; /* void */; p = n, n = n->next) { |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
64 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
461 | 65 "free: %p, unused: %uz", p, p->end - p->last); |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
66 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
67 if (n == NULL) { |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
68 break; |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
69 } |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
70 } |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
71 |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
72 #endif |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
73 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
74 for (p = pool, n = pool->next; /* void */; p = n, n = n->next) { |
477 | 75 ngx_free(p); |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
76 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
77 if (n == NULL) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
78 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
79 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
80 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
83 |
501 | 84 void * |
85 ngx_palloc(ngx_pool_t *pool, size_t size) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 { |
485 | 87 u_char *m; |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
88 ngx_pool_t *p, *n, *current; |
629 | 89 ngx_pool_large_t *large; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 |
429
694cd6cdb714
nginx-0.0.11-2004-09-17-20:07:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
426
diff
changeset
|
91 if (size <= (size_t) NGX_MAX_ALLOC_FROM_POOL |
485 | 92 && size <= (size_t) (pool->end - (u_char *) pool) |
589 | 93 - (size_t) ngx_align_ptr(sizeof(ngx_pool_t), NGX_ALIGNMENT)) |
429
694cd6cdb714
nginx-0.0.11-2004-09-17-20:07:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
426
diff
changeset
|
94 { |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
95 p = pool->current; |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
96 current = p; |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
97 |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
98 for ( ;; ) { |
589 | 99 |
1207
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
100 #if (NGX_HAVE_NONALIGNED) |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
101 |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
102 /* |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
103 * allow non-aligned memory blocks for small allocations (1, 2, |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
104 * or 3 bytes) and for odd length strings (struct's have aligned |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
105 * size) |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
106 */ |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
107 |
589 | 108 if (size < sizeof(int) || (size & 1)) { |
109 m = p->last; | |
110 | |
1207
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
111 } else |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
112 #endif |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
113 |
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
114 { |
589 | 115 m = ngx_align_ptr(p->last, NGX_ALIGNMENT); |
116 } | |
104
7db96f59bc29
nginx-0.0.1-2003-06-12-09:54:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
117 |
7db96f59bc29
nginx-0.0.1-2003-06-12-09:54:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
118 if ((size_t) (p->end - m) >= size) { |
452 | 119 p->last = m + size; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 return m; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 |
581 | 124 if ((size_t) (p->end - m) < NGX_ALIGNMENT) { |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
125 current = p->next; |
581 | 126 } |
127 | |
128 if (p->next == NULL) { | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 break; |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
130 } |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
131 |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
132 p = p->next; |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
133 pool->current = current; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 |
426
3f88935a02e8
nginx-0.0.10-2004-09-14-23:39:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
347
diff
changeset
|
136 /* allocate a new pool block */ |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
137 |
501 | 138 n = ngx_create_pool((size_t) (p->end - (u_char *) p), p->log); |
139 if (n == NULL) { | |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
140 return NULL; |
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
141 } |
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
142 |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
143 pool->current = current ? current : n; |
581 | 144 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 p->next = n; |
589 | 146 m = ngx_align_ptr(n->last, NGX_ALIGNMENT); |
452 | 147 n->last = m + size; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
148 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 return m; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
150 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
347
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
152 #if 0 |
501 | 153 p = ngx_memalign(ngx_pagesize, size, pool->log); |
154 if (p == NULL) { | |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
155 return NULL; |
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
156 } |
347
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
157 #else |
501 | 158 p = ngx_alloc(size, pool->log); |
159 if (p == NULL) { | |
347
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
160 return NULL; |
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
161 } |
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
162 #endif |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
629 | 164 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); |
165 if (large == NULL) { | |
1317 | 166 ngx_free(p); |
629 | 167 return NULL; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
168 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
170 large->alloc = p; |
629 | 171 large->next = pool->large; |
172 pool->large = large; | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
173 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
174 return p; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
175 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
176 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 |
501 | 178 ngx_int_t |
179 ngx_pfree(ngx_pool_t *pool, void *p) | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
180 { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
181 ngx_pool_large_t *l; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
183 for (l = pool->large; l; l = l->next) { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
184 if (p == l->alloc) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
185 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
461 | 186 "free: %p", l->alloc); |
477 | 187 ngx_free(l->alloc); |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
188 l->alloc = NULL; |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
189 |
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
190 return NGX_OK; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
191 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 } |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
193 |
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
194 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
197 |
501 | 198 void * |
199 ngx_pcalloc(ngx_pool_t *pool, size_t size) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 { |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 void *p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
203 p = ngx_palloc(pool, size); |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
204 if (p) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
205 ngx_memzero(p, size); |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
206 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
207 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 } |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
210 |
509 | 211 |
212 ngx_pool_cleanup_t * | |
563 | 213 ngx_pool_cleanup_add(ngx_pool_t *p, size_t size) |
509 | 214 { |
215 ngx_pool_cleanup_t *c; | |
216 | |
217 c = ngx_palloc(p, sizeof(ngx_pool_cleanup_t)); | |
218 if (c == NULL) { | |
219 return NULL; | |
220 } | |
221 | |
563 | 222 if (size) { |
223 c->data = ngx_palloc(p, size); | |
224 if (c->data == NULL) { | |
225 return NULL; | |
226 } | |
227 | |
228 } else { | |
229 c->data = NULL; | |
230 } | |
231 | |
232 c->handler = NULL; | |
509 | 233 c->next = p->cleanup; |
234 | |
235 p->cleanup = c; | |
236 | |
563 | 237 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, p->log, 0, "add cleanup: %p", c); |
238 | |
509 | 239 return c; |
240 } | |
241 | |
242 | |
243 void | |
244 ngx_pool_cleanup_file(void *data) | |
245 { | |
246 ngx_pool_cleanup_file_t *c = data; | |
247 | |
563 | 248 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, c->log, 0, "run cleanup: %p, fd:%d", |
249 c, c->fd); | |
250 | |
509 | 251 if (ngx_close_file(c->fd) == NGX_FILE_ERROR) { |
252 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, | |
253 ngx_close_file_n " \"%s\" failed", c->name); | |
254 } | |
255 } | |
256 | |
257 | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
258 void |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
259 ngx_pool_delete_file(void *data) |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
260 { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
261 ngx_pool_cleanup_file_t *c = data; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
262 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
263 ngx_err_t err; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
264 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
265 ngx_log_debug3(NGX_LOG_DEBUG_ALLOC, c->log, 0, "run cleanup: %p, fd:%d %s", |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
266 c, c->fd, c->name); |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
267 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
268 if (ngx_delete_file(c->name) == NGX_FILE_ERROR) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
269 err = ngx_errno; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
270 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
271 if (err != NGX_ENOENT) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
272 ngx_log_error(NGX_LOG_CRIT, c->log, err, |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
273 ngx_delete_file_n " \"%s\" failed", c->name); |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
274 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
275 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
276 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
277 if (ngx_close_file(c->fd) == NGX_FILE_ERROR) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
278 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
279 ngx_close_file_n " \"%s\" failed", c->name); |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
280 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
281 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
282 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
283 |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
284 #if 0 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
285 |
501 | 286 static void * |
287 ngx_get_cached_block(size_t size) | |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
288 { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
289 void *p; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
290 ngx_cached_block_slot_t *slot; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
291 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
292 if (ngx_cycle->cache == NULL) { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
293 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
294 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
295 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
296 slot = &ngx_cycle->cache[(size + ngx_pagesize - 1) / ngx_pagesize]; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
297 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
298 slot->tries++; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
299 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
300 if (slot->number) { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
301 p = slot->block; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
302 slot->block = slot->block->next; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
303 slot->number--; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
304 return p; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
305 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
306 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
307 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
308 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
309 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
310 #endif |