Changeset 602 for branches/1.3/xc_malloc.c
- Timestamp:
- 2009-07-05T07:49:25+02:00 (4 years ago)
- Location:
- branches/1.3
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
xc_malloc.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3
- Property svn:mergeinfo changed
/trunk merged: 363,366,376,381-387
- Property svn:mergeinfo changed
-
branches/1.3/xc_malloc.c
r593 r602 20 20 }; 21 21 22 /* {{{ _xc_malloc_shm_t */ 23 struct _xc_malloc_shm_t { 24 xc_shm_handlers_t *handlers; 25 xc_shmsize_t size; 26 xc_shmsize_t memoffset; 27 #ifdef HAVE_XCACHE_TEST 28 HashTable blocks; 29 #endif 30 }; 31 /* }}} */ 32 22 33 #define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0) 23 34 35 static void *xc_add_to_blocks(xc_mem_t *mem, void *p, size_t size) /* {{{ */ 36 { 37 #ifdef HAVE_XCACHE_TEST 38 if (p) { 39 zend_hash_add(&mem->shm->blocks, (void *) &p, sizeof(p), (void *) &size, sizeof(size), NULL); 40 } 41 #endif 42 return p; 43 } 44 /* }}} */ 45 static void xc_del_from_blocks(xc_mem_t *mem, void *p) /* {{{ */ 46 { 47 #ifdef HAVE_XCACHE_TEST 48 zend_hash_del(&mem->shm->blocks, (void *) &p, sizeof(p)); 49 #endif 50 } 51 /* }}} */ 52 24 53 static XC_MEM_MALLOC(xc_malloc_malloc) /* {{{ */ 25 54 { 26 return malloc(size);55 return xc_add_to_blocks(mem, malloc(size), size); 27 56 } 28 57 /* }}} */ 29 58 static XC_MEM_FREE(xc_malloc_free) /* {{{ return block size freed */ 30 59 { 60 xc_del_from_blocks(mem, (void *) p); 31 61 free((void *) p); 32 62 return 0; … … 35 65 static XC_MEM_CALLOC(xc_malloc_calloc) /* {{{ */ 36 66 { 37 return calloc(memb, size);67 return xc_add_to_blocks(mem, calloc(memb, size), size); 38 68 } 39 69 /* }}} */ 40 70 static XC_MEM_REALLOC(xc_malloc_realloc) /* {{{ */ 41 71 { 42 return realloc((void *) p, size);72 return xc_add_to_blocks(mem, realloc((void *) p, size), size); 43 73 } 44 74 /* }}} */ 45 75 static XC_MEM_STRNDUP(xc_malloc_strndup) /* {{{ */ 46 76 { 47 char *p = malloc(len);77 char *p = xc_add_to_blocks(mem, malloc(len), len); 48 78 if (!p) { 49 79 return NULL; … … 111 141 /* }}} */ 112 142 113 /* {{{ _xc_malloc_shm_t */114 struct _xc_malloc_shm_t {115 xc_shm_handlers_t *handlers;116 xc_shmsize_t size;117 xc_shmsize_t memoffset;118 };119 /* }}} */120 121 143 static XC_SHM_CAN_READONLY(xc_malloc_can_readonly) /* {{{ */ 122 144 { … … 126 148 static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */ 127 149 { 150 HashPosition pos; 151 size_t *psize; 152 char **ptr; 153 154 zend_hash_internal_pointer_reset_ex(&shm->blocks, &pos); 155 while (zend_hash_get_current_data_ex(&shm->blocks, (void **) &psize, &pos) == SUCCESS) { 156 zend_hash_get_current_key_ex(&shm->blocks, (void *) &ptr, NULL, NULL, 0, &pos); 157 if ((char *) p >= *ptr && (char *) p < *ptr + *psize) { 158 return 1; 159 } 160 zend_hash_move_forward_ex(&shm->blocks, &pos); 161 } 162 128 163 return 0; 129 164 } … … 147 182 static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */ 148 183 { 184 #ifdef HAVE_XCACHE_TEST 185 zend_hash_destroy(&shm->blocks); 186 #endif 149 187 free(shm); 150 188 return; … … 157 195 shm->size = size; 158 196 197 #ifdef HAVE_XCACHE_TEST 198 zend_hash_init(&shm->blocks, 64, NULL, NULL, 1); 199 #endif 159 200 return shm; 160 201 err:
Note: See TracChangeset
for help on using the changeset viewer.

