Ignore:
Timestamp:
2009-07-05T07:49:25+02:00 (6 years ago)
Author:
moo
Message:

merged r363,r366,r376,r381,r382,r383,r384,r385,r386,r387 from trunk

Location:
branches/1.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3

  • branches/1.3/xc_malloc.c

    r593 r602  
    2020};
    2121
     22/* {{{ _xc_malloc_shm_t */
     23struct _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
    2233#define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
    2334
     35static 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/* }}} */
     45static 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
    2453static XC_MEM_MALLOC(xc_malloc_malloc) /* {{{ */
    2554{
    26     return malloc(size);
     55    return xc_add_to_blocks(mem, malloc(size), size);
    2756}
    2857/* }}} */
    2958static XC_MEM_FREE(xc_malloc_free) /* {{{ return block size freed */
    3059{
     60    xc_del_from_blocks(mem, (void *) p);
    3161    free((void *) p);
    3262    return 0;
     
    3565static XC_MEM_CALLOC(xc_malloc_calloc) /* {{{ */
    3666{
    37     return calloc(memb, size);
     67    return xc_add_to_blocks(mem, calloc(memb, size), size);
    3868}
    3969/* }}} */
    4070static XC_MEM_REALLOC(xc_malloc_realloc) /* {{{ */
    4171{
    42     return realloc((void *) p, size);
     72    return xc_add_to_blocks(mem, realloc((void *) p, size), size);
    4373}
    4474/* }}} */
    4575static XC_MEM_STRNDUP(xc_malloc_strndup) /* {{{ */
    4676{
    47     char *p = malloc(len);
     77    char *p = xc_add_to_blocks(mem, malloc(len), len);
    4878    if (!p) {
    4979        return NULL;
     
    111141/* }}} */
    112142
    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 
    121143static XC_SHM_CAN_READONLY(xc_malloc_can_readonly) /* {{{ */
    122144{
     
    126148static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */
    127149{
     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
    128163    return 0;
    129164}
     
    147182static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */
    148183{
     184#ifdef HAVE_XCACHE_TEST
     185    zend_hash_destroy(&shm->blocks);
     186#endif
    149187    free(shm);
    150188    return;
     
    157195    shm->size = size;
    158196
     197#ifdef HAVE_XCACHE_TEST
     198    zend_hash_init(&shm->blocks, 64, NULL, NULL, 1);
     199#endif
    159200    return shm;
    160201err:
Note: See TracChangeset for help on using the changeset viewer.