- Timestamp:
- Feb 16, 2007 9:44:36 PM (18 years ago)
- Location:
- pjproject/trunk/pjlib/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/pool.c
r725 r953 175 175 PJ_CHECK_STACK(); 176 176 177 /* Size must be at least sizeof(pj_pool)+sizeof(pj_pool_block) */ 178 PJ_ASSERT_RETURN(initial_size >= sizeof(pj_pool_t)+sizeof(pj_pool_block), 179 NULL); 180 177 181 /* If callback is NULL, set calback from the policy */ 178 182 if (callback == NULL) -
pjproject/trunk/pjlib/src/pj/pool_buf.c
r839 r953 54 54 { 55 55 struct creation_param *param; 56 void *buf; 56 57 57 58 PJ_UNUSED_ARG(factory); 58 59 59 60 param = pj_thread_local_get(tls); 60 PJ_ASSERT_RETURN(param != NULL, NULL); 61 if (param == NULL) { 62 /* Don't assert(), this is normal no-memory situation */ 63 return NULL; 64 } 61 65 62 66 pj_thread_local_set(tls, NULL); … … 64 68 PJ_ASSERT_RETURN(size <= param->size, NULL); 65 69 66 return param->stack_buf; 70 buf = param->stack_buf; 71 72 /* Prevent the buffer from being reused */ 73 param->stack_buf = NULL; 74 75 return buf; 67 76 } 68 77 -
pjproject/trunk/pjlib/src/pjlib-test/pool.c
r65 r953 18 18 */ 19 19 #include <pj/pool.h> 20 #include <pj/pool_buf.h> 20 21 #include <pj/rand.h> 21 22 #include <pj/log.h> 23 #include <pj/except.h> 22 24 #include "test.h" 23 25 … … 140 142 } 141 143 144 /* Test the buffer based pool */ 145 static int pool_buf_test(void) 146 { 147 enum { STATIC_BUF_SIZE = 40 }; 148 /* 16 is the internal struct in pool_buf */ 149 static char buf[ STATIC_BUF_SIZE + sizeof(pj_pool_t) + 150 sizeof(pj_pool_block) + 16]; 151 pj_pool_t *pool; 152 void *p; 153 PJ_USE_EXCEPTION; 154 155 PJ_LOG(3,("test", "...pool_buf test")); 156 157 pool = pj_pool_create_on_buf("no name", buf, sizeof(buf)); 158 if (!pool) 159 return -70; 160 161 /* Drain the pool */ 162 PJ_TRY { 163 if ((p=pj_pool_alloc(pool, STATIC_BUF_SIZE/2)) == NULL) 164 return -75; 165 166 if ((p=pj_pool_alloc(pool, STATIC_BUF_SIZE/2)) == NULL) 167 return -76; 168 } 169 PJ_CATCH_ANY { 170 return -77; 171 } 172 PJ_END; 173 174 /* On the next alloc, exception should be thrown */ 175 PJ_TRY { 176 p = pj_pool_alloc(pool, STATIC_BUF_SIZE); 177 if (p != NULL) { 178 /* This is unexpected, the alloc should fail */ 179 return -78; 180 } 181 } 182 PJ_CATCH_ANY { 183 /* This is the expected result */ 184 } 185 PJ_END; 186 187 /* Done */ 188 return 0; 189 } 190 191 142 192 int pool_test(void) 143 193 { … … 161 211 } 162 212 213 rc = pool_buf_test(); 214 if (rc != 0) 215 return rc; 216 217 163 218 return 0; 164 219 }
Note: See TracChangeset
for help on using the changeset viewer.