Changeset 386 for trunk


Ignore:
Timestamp:
2007-05-15T08:24:17+02:00 (8 years ago)
Author:
moo
Message:

fix is_readwrite of malloc scheme

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xc_malloc.c

    r381 r386  
    1616}; 
    1717 
     18/* {{{ _xc_malloc_shm_t */ 
     19struct _xc_malloc_shm_t { 
     20    xc_shm_handlers_t *handlers; 
     21    xc_shmsize_t       size; 
     22    xc_shmsize_t       memoffset; 
     23#ifdef HAVE_XCACHE_TEST 
     24    HashTable blocks; 
     25#endif 
     26}; 
     27/* }}} */ 
     28 
    1829#define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0) 
    1930 
     31static void *xc_add_to_blocks(xc_mem_t *mem, void *p, size_t size) /* {{{ */ 
     32{ 
     33#ifdef HAVE_XCACHE_TEST 
     34    if (p) { 
     35        zend_hash_add(&mem->shm->blocks, (void *) &p, sizeof(p), (void *) &size, sizeof(size), NULL); 
     36    } 
     37#endif 
     38    return p; 
     39} 
     40/* }}} */ 
     41static void xc_del_from_blocks(xc_mem_t *mem, void *p) /* {{{ */ 
     42{ 
     43#ifdef HAVE_XCACHE_TEST 
     44    zend_hash_del(&mem->shm->blocks, (void *) &p, sizeof(p)); 
     45#endif 
     46} 
     47/* }}} */ 
     48 
    2049static XC_MEM_MALLOC(xc_malloc_malloc) /* {{{ */ 
    2150{ 
    22     return malloc(size); 
     51    return xc_add_to_blocks(mem, malloc(size), size); 
    2352} 
    2453/* }}} */ 
    2554static XC_MEM_FREE(xc_malloc_free) /* {{{ return block size freed */ 
    2655{ 
     56    xc_del_from_blocks(mem, (void *) p); 
    2757    free((void *) p); 
    2858    return 0; 
     
    3161static XC_MEM_CALLOC(xc_malloc_calloc) /* {{{ */ 
    3262{ 
    33     return calloc(memb, size); 
     63    return xc_add_to_blocks(mem, calloc(memb, size), size); 
    3464} 
    3565/* }}} */ 
    3666static XC_MEM_REALLOC(xc_malloc_realloc) /* {{{ */ 
    3767{ 
    38     return realloc((void *) p, size); 
     68    return xc_add_to_blocks(mem, realloc((void *) p, size), size); 
    3969} 
    4070/* }}} */ 
    4171static XC_MEM_STRNDUP(xc_malloc_strndup) /* {{{ */ 
    4272{ 
    43     char *p = malloc(len); 
     73    char *p = xc_add_to_blocks(mem, malloc(len), len); 
    4474    if (!p) { 
    4575        return NULL; 
     
    107137/* }}} */ 
    108138 
    109 /* {{{ _xc_malloc_shm_t */ 
    110 struct _xc_malloc_shm_t { 
    111     xc_shm_handlers_t *handlers; 
    112     xc_shmsize_t       size; 
    113     xc_shmsize_t       memoffset; 
    114 }; 
    115 /* }}} */ 
    116  
    117139static XC_SHM_CAN_READONLY(xc_malloc_can_readonly) /* {{{ */ 
    118140{ 
     
    122144static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */ 
    123145{ 
     146    HashPosition pos; 
     147    size_t *psize; 
     148    char **ptr; 
     149 
     150    zend_hash_internal_pointer_reset_ex(&shm->blocks, &pos); 
     151    while (zend_hash_get_current_data_ex(&shm->blocks, (void **) &psize, &pos) == SUCCESS) { 
     152        zend_hash_get_current_key_ex(&shm->blocks, (void *) &ptr, NULL, NULL, 0, &pos); 
     153        if ((char *) p >= *ptr && (char *) p < *ptr + *psize) { 
     154            return 1; 
     155        } 
     156        zend_hash_move_forward_ex(&shm->blocks, &pos); 
     157    } 
     158 
    124159    return 0; 
    125160} 
     
    144179{ 
    145180    free(shm); 
     181#ifdef HAVE_XCACHE_TEST 
     182    zend_hash_destroy(&shm->blocks); 
     183#endif 
    146184    return; 
    147185} 
     
    153191    shm->size = size; 
    154192 
     193#ifdef HAVE_XCACHE_TEST 
     194    zend_hash_init(&shm->blocks, 64, NULL, NULL, 1); 
     195#endif 
    155196    return shm; 
    156197err: 
Note: See TracChangeset for help on using the changeset viewer.