pike.git / src / pike_types.c

version» Context lines:

pike.git/src/pike_types.c:20:   #include "pike_error.h"   #include "las.h"   #include "lex.h"   #include "pike_memory.h"   #include "bignum.h"   #include "main.h"   #include "opcodes.h"   #include "cyclic.h"   #include "gc.h"   #include "pike_compiler.h" - #include "block_alloc.h" + #include "block_allocator.h"      #ifdef PIKE_DEBUG   #define PIKE_TYPE_DEBUG   #endif /* PIKE_DEBUG */      /*    * Flags used by low_match_types().    */   #define A_EXACT 1   #define B_EXACT 2
pike.git/src/pike_types.c:270:    * INT min (int) max (int)    * OBJECT implements/is object id(int)    *    * Note that the cdr of a FUNCTION is a valid FUNCTION for the rest of    * the arguments.    *    * Note also that functions that don't take any arguments, or just    * a many argument just have a MANY node, and no FUNCTION node.    *    */ - #define PIKE_TYPE_CHUNK 128 - BLOCK_ALLOC(pike_type, PIKE_TYPE_CHUNK) + static struct block_allocator type_allocator = BA_INIT(sizeof(struct pike_type), 128);    -  + PMOD_EXPORT void really_free_pike_type(struct pike_type * t) { +  ba_free(&type_allocator, t); + } +  + ATTRIBUTE((malloc)) + PMOD_EXPORT struct pike_type * alloc_pike_type() { +  return ba_alloc(&type_allocator); + } +  + PMOD_EXPORT void count_memory_in_pike_types(size_t *n, size_t *s) { +  ba_count_all(&type_allocator, n, s); + } +    struct pike_type **pike_type_hash = NULL;   size_t pike_type_hash_size = 0;      void debug_free_type(struct pike_type *t)   {   #ifdef DEBUG_MALLOC    if (t == (struct pike_type *)(size_t)0x55555555) {    Pike_fatal("Freeing dead type.\n");    }   #endif /* DEBUG_MALLOC */
pike.git/src/pike_types.c:309:    *t2 = t->next;    break;    }    t2 = &((*t2)->next);    }       car = t->car;    cdr = t->cdr;    type = t->type;    -  really_free_pike_type((struct pike_type *)debug_malloc_pass(t)); +  really_free_pike_type((struct pike_type*)debug_malloc_pass(t));       /* FIXME: Recursion: Should we use a stack? */    switch(type) {    case T_FUNCTION:    case T_MANY:    case T_TUPLE:    case T_MAPPING:    case T_OR:    case T_AND:    case PIKE_T_RING:
pike.git/src/pike_types.c:551:    return t;    }    }      #ifdef PIKE_DEBUG    if ((type == T_OR) && (car->type == T_OR)) {    Pike_fatal("Invalid CAR to OR node.\n");    }   #endif    -  debug_malloc_pass(t = alloc_pike_type()); +  debug_malloc_pass(t = ba_alloc(&type_allocator));      #ifdef ATOMIC_SVALUE    t->ref_type = PIKE_T_TYPE;   #endif    t->refs = 0;    add_ref(t); /* For DMALLOC... */    t->type = type;    t->flags = 0;    t->car = car;    t->cdr = cdr;
pike.git/src/pike_types.c:8539:   static struct callback *pike_type_gc_callback = NULL;   #endif /* PIKE_DEBUG */      void init_types(void)   {    /* Initialize hashtable here. */    pike_type_hash = (struct pike_type **)xalloc(sizeof(struct pike_type *) *    (PIKE_TYPE_HASH_SIZE+1));    MEMSET(pike_type_hash, 0, sizeof(struct pike_type *) * (PIKE_TYPE_HASH_SIZE+1));    pike_type_hash_size = PIKE_TYPE_HASH_SIZE; -  init_pike_type_blocks(); +        int_type_string = CONSTTYPE(tInt); /* MUST come before string! */    string0_type_string = CONSTTYPE(tStr0);    string_type_string = CONSTTYPE(tStr32);    object_type_string = CONSTTYPE(tObj);    program_type_string = CONSTTYPE(tPrg(tObj));    float_type_string = CONSTTYPE(tFloat);    mixed_type_string = CONSTTYPE(tMix);    array_type_string = CONSTTYPE(tArray);    multiset_type_string = CONSTTYPE(tMultiset);
pike.git/src/pike_types.c:8639:    */    pike_type_hash = NULL;    }    /* Don't do this, it messes up stuff...    *    * It's needed for dmalloc to survive.    */    pike_type_hash_size = 0;      #ifdef DO_PIKE_CLEANUP -  free_all_pike_type_blocks(); +  ba_destroy(&type_allocator);   #endif /* DO_PIKE_CLEANUP */   }      PMOD_EXPORT void *find_type(struct pike_type *t,    void *(*cb)(struct pike_type *))   {    void *res;    if (!t) return NULL;       res = cb(t);