Ticket #1008: isobjcheck.patch

File isobjcheck.patch, 7.3 KB (added by jessevdam, 12 years ago)

checking for pobj

  • src/string/api.c

    ### Eclipse Workspace Patch 1.0
    #P ispobjecttest
     
    9292    if (PObj_is_cowed_TESTALL(s)) { 
    9393        STRING for_alloc; 
    9494 
     95        POBJ_set_check_magic(&for_alloc); 
     96 
    9597        /* Create new pool data for this header to use, 
    9698         * independent of the original COW data */ 
    9799        PObj_constant_CLEAR(s); 
  • src/gc/system.c

     
    454454                /* ...so ensure that Parrot_gc_mark_PObj_alive checks PObj_on_free_list_FLAG 
    455455                 * before adding it to the next_for_GC list, to have 
    456456                 * vtable->mark() called. */ 
    457                 Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); 
     457#  ifdef PObj_do_is_pobj_check 
     458                if (!PObj_is_live_or_free_TESTALL((PObj *)ptr)) 
     459#  endif 
     460                    Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); 
    458461            } 
    459462            else if (buffer_min <= ptr && ptr < buffer_max && 
    460463                    is_buffer_ptr(interp, (void *)ptr)) { 
    461464                /* ...and since Parrot_gc_mark_PObj_alive doesn't care about bufstart, it 
    462465                 * doesn't really matter if it sets a flag */ 
    463                 Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); 
     466#  ifdef PObj_do_is_pobj_check 
     467                if (!PObj_is_live_or_free_TESTALL((PObj *)ptr)) 
     468#  endif 
     469                    Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); 
    464470            } 
    465471        } 
    466472    } 
  • src/gc/api.c

     
    198198    /* TODO: Have each core register a ->pobject_lives function pointer in the 
    199199       Arenas struct, and call that pointer directly instead of having a messy 
    200200       set of #if preparser conditions. */ 
     201    POBJ_PARROT_ASSERT_check_is_pobj(obj); 
     202 
    201203#if PARROT_GC_GMS 
    202204    do { 
    203205        if (!PObj_live_TEST(obj) && \ 
     
    341343    pmc->vtable         = NULL; 
    342344    PMC_data(pmc)       = NULL; 
    343345 
     346    POBJ_set_check_magic(pmc); 
     347 
    344348    return pmc; 
    345349} 
    346350 
     
    358362Parrot_gc_free_pmc_header(PARROT_INTERP, ARGMOD(PMC *pmc)) 
    359363{ 
    360364    ASSERT_ARGS(Parrot_gc_free_pmc_header) 
    361     Small_Object_Pool * const pool = (PObj_constant_TEST(pmc)) ? 
     365    Small_Object_Pool * pool; 
     366 
     367    POBJ_PARROT_ASSERT_check_is_pobj(pmc); 
     368 
     369    pool = (PObj_constant_TEST(pmc)) ? 
    362370        interp->arena_base->constant_pmc_pool : interp->arena_base->pmc_pool; 
    363371 
    364372    Parrot_pmc_destroy(interp, pmc); 
     
    383391{ 
    384392    ASSERT_ARGS(Parrot_gc_free_pmc_sync) 
    385393 
     394    POBJ_PARROT_ASSERT_check_is_pobj(p); 
     395 
    386396    if (PObj_is_PMC_shared_TEST(p) && PMC_sync(p)) { 
    387397        MUTEX_DESTROY(PMC_sync(p)->pmc_lock); 
    388398        mem_internal_free(PMC_sync(p)); 
     
    407417{ 
    408418    ASSERT_ARGS(Parrot_gc_add_pmc_sync) 
    409419 
     420    POBJ_PARROT_ASSERT_check_is_pobj(pmc); 
     421 
    410422    /* This mutex already exists, leave it alone. */ 
    411423    if (PMC_sync(pmc)) 
    412424        return; 
     
    453465    PObj_get_FLAGS(string) |= 
    454466        flags | PObj_is_string_FLAG | PObj_is_COWable_FLAG | PObj_live_FLAG; 
    455467 
     468    POBJ_set_check_magic(string); 
     469 
    456470    return string; 
    457471} 
    458472 
     
    470484Parrot_gc_free_string_header(PARROT_INTERP, ARGMOD(STRING *s)) 
    471485{ 
    472486    ASSERT_ARGS(Parrot_gc_free_string_header) 
     487 
     488    POBJ_PARROT_ASSERT_check_is_pobj(s); 
     489 
    473490    if (!PObj_constant_TEST(s)) { 
    474         Small_Object_Pool * const pool = interp->arena_base->string_header_pool; 
     491        Small_Object_Pool * pool = interp->arena_base->string_header_pool; 
    475492        pool->add_free_object(interp, pool, s); 
    476493    } 
    477494} 
     
    495512Parrot_gc_new_bufferlike_header(PARROT_INTERP, size_t size) 
    496513{ 
    497514    ASSERT_ARGS(Parrot_gc_new_bufferlike_header) 
     515    Buffer *buffer; 
    498516 
    499517    Small_Object_Pool * const pool = get_bufferlike_pool(interp, size); 
    500518 
    501     return get_free_buffer(interp, pool); 
     519    buffer = (Buffer*)get_free_buffer(interp, pool); 
     520 
     521    POBJ_set_check_magic(buffer); 
     522 
     523    return buffer; 
    502524} 
    503525 
    504526/* 
     
    529551        memset(buffer + 1, 0, 
    530552                pool->object_size - sizeof (Buffer) - GC_HEADER_SIZE); 
    531553 
     554    POBJ_set_check_magic(buffer); 
     555 
    532556    return buffer; 
    533557} 
    534558 
     
    549573    size_t size) 
    550574{ 
    551575    ASSERT_ARGS(Parrot_gc_free_bufferlike_header) 
    552     Small_Object_Pool * const pool = get_bufferlike_pool(interp, size); 
     576    Small_Object_Pool * pool; 
     577 
     578    POBJ_PARROT_ASSERT_check_is_pobj(obj); 
     579 
     580    pool = get_bufferlike_pool(interp, size); 
    553581    pool->add_free_object(interp, pool, obj); 
    554582} 
    555583 
     
    574602    size_t new_size; 
    575603    char *mem; 
    576604 
     605    POBJ_PARROT_ASSERT_check_is_pobj(buffer); 
     606 
    577607    Buffer_buflen(buffer) = 0; 
    578608    Buffer_bufstart(buffer) = NULL; 
    579609    new_size = aligned_size(buffer, size); 
     
    611641    Memory_Pool * const pool = interp->arena_base->memory_pool; 
    612642    size_t new_size, needed, old_size; 
    613643 
     644    POBJ_PARROT_ASSERT_check_is_pobj(buffer); 
     645 
    614646    /* 
    615647     * we don't shrink buffers 
    616648     */ 
     
    682714    Memory_Pool *pool; 
    683715    char        *mem; 
    684716 
     717    POBJ_PARROT_ASSERT_check_is_pobj(str); 
     718 
    685719    Buffer_buflen(str)   = 0; 
    686720    Buffer_bufstart(str) = NULL; 
    687721 
     
    725759    size_t copysize; 
    726760    char *mem, *oldmem; 
    727761    size_t new_size, needed, old_size; 
     762    Memory_Pool * pool; 
    728763 
    729     Memory_Pool * const pool = 
     764    POBJ_PARROT_ASSERT_check_is_pobj(str); 
     765 
     766    pool = 
    730767        PObj_constant_TEST(str) 
    731768            ? interp->arena_base->constant_string_pool 
    732769            : interp->arena_base->memory_pool; 
  • include/parrot/pobj.h

     
    1515 
    1616#include "parrot/config.h" 
    1717 
     18/* To enable test which test whether the object which are entered into the gc functions 
     19   are indeed pobject enable this define */ 
     20#define PObj_do_is_pobj_check 1 
     21 
    1822/* Parrot Object - base class for all others */ 
    1923typedef struct pobj_t { 
    2024    Parrot_UInt flags; 
     25#ifdef PObj_do_is_pobj_check 
     26    Parrot_UInt is_pobj_test; 
     27#endif 
    2128} PObj; 
    2229 
    2330typedef struct buffer_t { 
    2431    Parrot_UInt flags; 
     32#ifdef PObj_do_is_pobj_check 
     33    Parrot_UInt is_pobj_test; 
     34#endif 
    2535    void *     _bufstart; 
    2636    size_t     _buflen; 
    2737} Buffer; 
    2838 
     39#ifdef PObj_do_is_pobj_check 
     40#  define is_pobj_check_magic 0xcecaacec 
     41#  define POBJ_set_check_magic(pobj)              (pobj)->is_pobj_test = is_pobj_check_magic 
     42#  define POBJ_PARROT_ASSERT_check_is_pobj(pobj)  PARROT_ASSERT((pobj)->is_pobj_test == is_pobj_check_magic) 
     43#else 
     44#  define POBJ_set_check_magic(pobj) 
     45#  define POBJ_PARROT_ASSERT_check_is_pobj(pobj) 
     46#endif 
     47 
    2948#define Buffer_bufstart(buffer)    (buffer)->_bufstart 
    3049#define Buffer_buflen(buffer)      (buffer)->_buflen 
    3150 
     
    81100 
    82101struct parrot_string_t { 
    83102    Parrot_UInt flags; 
     103#ifdef PObj_do_is_pobj_check 
     104    Parrot_UInt is_pobj_test; 
     105#endif 
    84106    void *     _bufstart; 
    85107    size_t     _buflen; 
    86108    char       *strstart; 
     
    98120/* note that cache and flags are isomorphic with Buffer and PObj */ 
    99121struct PMC { 
    100122    Parrot_UInt     flags; 
     123#ifdef PObj_do_is_pobj_check 
     124    Parrot_UInt     is_pobj_test; 
     125#endif 
    101126    VTABLE         *vtable; 
    102127    DPOINTER       *data; 
    103128