pike.git / src / block_alloc.h

version» Context lines:

pike.git/src/block_alloc.h:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: block_alloc.h,v 1.58 2002/12/02 11:08:22 mast Exp $ + || $Id: block_alloc.h,v 1.59 2003/01/08 09:22:51 grubba Exp $   */      #undef PRE_INIT_BLOCK   #undef INIT_BLOCK   #undef EXIT_BLOCK   #undef BLOCK_ALLOC   #undef LOW_PTR_HASH_ALLOC   #undef PTR_HASH_ALLOC_FIXED   #undef PTR_HASH_ALLOC   #undef COUNT_BLOCK
pike.git/src/block_alloc.h:365:    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    return p; \    } \    } \    return 0; \   } \    \   struct DATA *PIKE_CONCAT(find_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval = (size_t)ptr; \ +  size_t hval = (size_t)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    if(!PIKE_CONCAT(DATA,_hash_table_size)) { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \    } \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \   } \    \    \    \   struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)ptr; \ +  size_t hval=(size_t)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    p=PIKE_CONCAT3(make_,DATA,_unlocked)(ptr,hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \   } \    \   struct DATA *PIKE_CONCAT(get_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)ptr; \ +  size_t hval=(size_t)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    if(!(p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))) \    p=PIKE_CONCAT3(make_,DATA,_unlocked)(ptr, hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return p; \   } \    \   int PIKE_CONCAT3(check_,DATA,_semafore)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)ptr; \ +  size_t hval=(size_t)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    if((p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))) \    { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \    } \    \    PIKE_CONCAT3(make_,DATA,_unlocked)(ptr, hval); \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 1; \   } \    \   void PIKE_CONCAT(move_,DATA)(struct DATA *block, void *new_ptr) \   { \ -  size_t hval = (size_t) block->PTR_HASH_ALLOC_DATA; \ +  size_t hval = (size_t)(((char *)block->PTR_HASH_ALLOC_DATA)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    hval %= PIKE_CONCAT(DATA,_hash_table_size); \    if (!PIKE_CONCAT3(really_low_find_,DATA,_unlocked)( \    block->PTR_HASH_ALLOC_DATA, hval)) \    Pike_fatal("The block to move wasn't found.\n"); \    DO_IF_DEBUG( \    if (PIKE_CONCAT(DATA,_hash_table)[hval] != block) \    Pike_fatal("Expected the block to be at the top of the hash chain.\n"); \    ); \    PIKE_CONCAT(DATA,_hash_table)[hval] = block->BLOCK_ALLOC_NEXT; \    block->PTR_HASH_ALLOC_DATA = new_ptr; \ -  hval = (size_t) new_ptr % PIKE_CONCAT(DATA,_hash_table_size); \ +  hval = (size_t)(((char *)new_ptr)-(char *)0) % \ +  PIKE_CONCAT(DATA,_hash_table_size); \    block->BLOCK_ALLOC_NEXT = PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval] = block; \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \   } \    \   int PIKE_CONCAT(remove_,DATA)(void *ptr) \   { \    struct DATA *p; \ -  size_t hval=(size_t)ptr; \ +  size_t hval=(size_t)(((char *)ptr)-(char *)0); \    DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex))); \    if(!PIKE_CONCAT(DATA,_hash_table)) \    { \    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex))); \    return 0; \    } \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    if((p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))) \    { \    PIKE_CONCAT(num_,DATA)--; \
pike.git/src/block_alloc.h:551:    malloc(PIKE_CONCAT(DATA,_hash_table_size)* \    sizeof(struct DATA *)))) \    { \    MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \    sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \    while(e-- > 0) \    { \    while((p=old_hash[e])) \    { \    old_hash[e]=p->BLOCK_ALLOC_NEXT; \ -  hval=(size_t)(p->PTR_HASH_ALLOC_DATA); \ +  hval=(size_t)(((char *)p->PTR_HASH_ALLOC_DATA)-(char *)0); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    } \    } \    free((char *)old_hash); \    }else{ \    PIKE_CONCAT(DATA,_hash_table)=old_hash; \    PIKE_CONCAT(DATA,_hash_table_size)=e; \    } \
pike.git/src/block_alloc.h:576:    struct DATA *p; \    \    DO_IF_DEBUG( if(!PIKE_CONCAT(DATA,_hash_table)) \    Pike_fatal("Hash table error!\n"); ) \    PIKE_CONCAT(num_,DATA)++; \    \    if(( PIKE_CONCAT(num_,DATA)>>BLOCK_ALLOC_HSIZE_SHIFT ) >= \    PIKE_CONCAT(DATA,_hash_table_size)) \    { \    PIKE_CONCAT(DATA,_rehash)(); \ -  hval=(size_t)ptr; \ +  hval=(size_t)(((char *)ptr)-(char *)0); \    hval%=PIKE_CONCAT(DATA,_hash_table_size); \    } \    \    p=BA_UL(PIKE_CONCAT(alloc_,DATA))(); \    p->PTR_HASH_ALLOC_DATA=ptr; \    p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \    PIKE_CONCAT(DATA,_hash_table)[hval]=p; \    return p; \   }