### Eclipse Workspace Patch 1.0 #P ispobjecttest Index: src/string/api.c =================================================================== --- src/string/api.c (revision 41260) +++ src/string/api.c (working copy) @@ -92,6 +92,8 @@ if (PObj_is_cowed_TESTALL(s)) { STRING for_alloc; + POBJ_set_check_magic(&for_alloc); + /* Create new pool data for this header to use, * independent of the original COW data */ PObj_constant_CLEAR(s); Index: src/gc/system.c =================================================================== --- src/gc/system.c (revision 41260) +++ src/gc/system.c (working copy) @@ -454,13 +454,19 @@ /* ...so ensure that Parrot_gc_mark_PObj_alive checks PObj_on_free_list_FLAG * before adding it to the next_for_GC list, to have * vtable->mark() called. */ - Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); +# ifdef PObj_do_is_pobj_check + if (!PObj_is_live_or_free_TESTALL((PObj *)ptr)) +# endif + Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); } else if (buffer_min <= ptr && ptr < buffer_max && is_buffer_ptr(interp, (void *)ptr)) { /* ...and since Parrot_gc_mark_PObj_alive doesn't care about bufstart, it * doesn't really matter if it sets a flag */ - Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); +# ifdef PObj_do_is_pobj_check + if (!PObj_is_live_or_free_TESTALL((PObj *)ptr)) +# endif + Parrot_gc_mark_PObj_alive(interp, (PObj *)ptr); } } } Index: src/gc/api.c =================================================================== --- src/gc/api.c (revision 41260) +++ src/gc/api.c (working copy) @@ -198,6 +198,8 @@ /* TODO: Have each core register a ->pobject_lives function pointer in the Arenas struct, and call that pointer directly instead of having a messy set of #if preparser conditions. */ + POBJ_PARROT_ASSERT_check_is_pobj(obj); + #if PARROT_GC_GMS do { if (!PObj_live_TEST(obj) && \ @@ -341,6 +343,8 @@ pmc->vtable = NULL; PMC_data(pmc) = NULL; + POBJ_set_check_magic(pmc); + return pmc; } @@ -358,7 +362,11 @@ Parrot_gc_free_pmc_header(PARROT_INTERP, ARGMOD(PMC *pmc)) { ASSERT_ARGS(Parrot_gc_free_pmc_header) - Small_Object_Pool * const pool = (PObj_constant_TEST(pmc)) ? + Small_Object_Pool * pool; + + POBJ_PARROT_ASSERT_check_is_pobj(pmc); + + pool = (PObj_constant_TEST(pmc)) ? interp->arena_base->constant_pmc_pool : interp->arena_base->pmc_pool; Parrot_pmc_destroy(interp, pmc); @@ -383,6 +391,8 @@ { ASSERT_ARGS(Parrot_gc_free_pmc_sync) + POBJ_PARROT_ASSERT_check_is_pobj(p); + if (PObj_is_PMC_shared_TEST(p) && PMC_sync(p)) { MUTEX_DESTROY(PMC_sync(p)->pmc_lock); mem_internal_free(PMC_sync(p)); @@ -407,6 +417,8 @@ { ASSERT_ARGS(Parrot_gc_add_pmc_sync) + POBJ_PARROT_ASSERT_check_is_pobj(pmc); + /* This mutex already exists, leave it alone. */ if (PMC_sync(pmc)) return; @@ -453,6 +465,8 @@ PObj_get_FLAGS(string) |= flags | PObj_is_string_FLAG | PObj_is_COWable_FLAG | PObj_live_FLAG; + POBJ_set_check_magic(string); + return string; } @@ -470,8 +484,11 @@ Parrot_gc_free_string_header(PARROT_INTERP, ARGMOD(STRING *s)) { ASSERT_ARGS(Parrot_gc_free_string_header) + + POBJ_PARROT_ASSERT_check_is_pobj(s); + if (!PObj_constant_TEST(s)) { - Small_Object_Pool * const pool = interp->arena_base->string_header_pool; + Small_Object_Pool * pool = interp->arena_base->string_header_pool; pool->add_free_object(interp, pool, s); } } @@ -495,10 +512,15 @@ Parrot_gc_new_bufferlike_header(PARROT_INTERP, size_t size) { ASSERT_ARGS(Parrot_gc_new_bufferlike_header) + Buffer *buffer; Small_Object_Pool * const pool = get_bufferlike_pool(interp, size); - return get_free_buffer(interp, pool); + buffer = (Buffer*)get_free_buffer(interp, pool); + + POBJ_set_check_magic(buffer); + + return buffer; } /* @@ -529,6 +551,8 @@ memset(buffer + 1, 0, pool->object_size - sizeof (Buffer) - GC_HEADER_SIZE); + POBJ_set_check_magic(buffer); + return buffer; } @@ -549,7 +573,11 @@ size_t size) { ASSERT_ARGS(Parrot_gc_free_bufferlike_header) - Small_Object_Pool * const pool = get_bufferlike_pool(interp, size); + Small_Object_Pool * pool; + + POBJ_PARROT_ASSERT_check_is_pobj(obj); + + pool = get_bufferlike_pool(interp, size); pool->add_free_object(interp, pool, obj); } @@ -574,6 +602,8 @@ size_t new_size; char *mem; + POBJ_PARROT_ASSERT_check_is_pobj(buffer); + Buffer_buflen(buffer) = 0; Buffer_bufstart(buffer) = NULL; new_size = aligned_size(buffer, size); @@ -611,6 +641,8 @@ Memory_Pool * const pool = interp->arena_base->memory_pool; size_t new_size, needed, old_size; + POBJ_PARROT_ASSERT_check_is_pobj(buffer); + /* * we don't shrink buffers */ @@ -682,6 +714,8 @@ Memory_Pool *pool; char *mem; + POBJ_PARROT_ASSERT_check_is_pobj(str); + Buffer_buflen(str) = 0; Buffer_bufstart(str) = NULL; @@ -725,8 +759,11 @@ size_t copysize; char *mem, *oldmem; size_t new_size, needed, old_size; + Memory_Pool * pool; - Memory_Pool * const pool = + POBJ_PARROT_ASSERT_check_is_pobj(str); + + pool = PObj_constant_TEST(str) ? interp->arena_base->constant_string_pool : interp->arena_base->memory_pool; Index: include/parrot/pobj.h =================================================================== --- include/parrot/pobj.h (revision 41260) +++ include/parrot/pobj.h (working copy) @@ -15,17 +15,36 @@ #include "parrot/config.h" +/* To enable test which test whether the object which are entered into the gc functions + are indeed pobject enable this define */ +#define PObj_do_is_pobj_check 1 + /* Parrot Object - base class for all others */ typedef struct pobj_t { Parrot_UInt flags; +#ifdef PObj_do_is_pobj_check + Parrot_UInt is_pobj_test; +#endif } PObj; typedef struct buffer_t { Parrot_UInt flags; +#ifdef PObj_do_is_pobj_check + Parrot_UInt is_pobj_test; +#endif void * _bufstart; size_t _buflen; } Buffer; +#ifdef PObj_do_is_pobj_check +# define is_pobj_check_magic 0xcecaacec +# define POBJ_set_check_magic(pobj) (pobj)->is_pobj_test = is_pobj_check_magic +# define POBJ_PARROT_ASSERT_check_is_pobj(pobj) PARROT_ASSERT((pobj)->is_pobj_test == is_pobj_check_magic) +#else +# define POBJ_set_check_magic(pobj) +# define POBJ_PARROT_ASSERT_check_is_pobj(pobj) +#endif + #define Buffer_bufstart(buffer) (buffer)->_bufstart #define Buffer_buflen(buffer) (buffer)->_buflen @@ -81,6 +100,9 @@ struct parrot_string_t { Parrot_UInt flags; +#ifdef PObj_do_is_pobj_check + Parrot_UInt is_pobj_test; +#endif void * _bufstart; size_t _buflen; char *strstart; @@ -98,6 +120,9 @@ /* note that cache and flags are isomorphic with Buffer and PObj */ struct PMC { Parrot_UInt flags; +#ifdef PObj_do_is_pobj_check + Parrot_UInt is_pobj_test; +#endif VTABLE *vtable; DPOINTER *data;