Changeset 08a40fd


Ignore:
Timestamp:
Jan 19, 2016, 4:17:14 PM (9 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
d67a9a1
Parents:
6be0cf9
Message:

segfault in translator

Location:
src/examples/gc_no_raii
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/src/internal/collector.c

    r6be0cf9 r08a40fd  
    22
    33#include <stdint.h>
     4#include <stdlib.h>
    45#include <string.h>
    56
     
    89#include "gc_tools.h"
    910#include "state.h"
    10 #include "memory_pool.h"
     11// #include "memory_pool.h"
    1112
    1213void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size);
     
    1819
    1920        bool managed = gc_is_managed(target);
    20         gc_object_header* obj = gc_get_object_ptr(target->ptr);
     21        gc_object_header* obj = gc_get_object_ptr((void*)target->ptr);
    2122
    2223        check(gc_is_valide(obj));
     
    3738        check(size < POOL_SIZE_BYTES);
    3839
    39         void* block = nullptr;
     40        void* block = NULL;
    4041        gc_state* gc = gc_get_state();
    4142
    42         if((block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
     43        if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
    4344
    4445        gc_collect(gc);
    4546
    46         if((block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
     47        if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
    4748
    4849        gc_allocate_pool(gc);
    4950
    50         if((block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
     51        if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
    5152
    5253        ofstream_stderr() | "ERROR: allocation in new pool failed" | endl;
    5354        abort();
    5455
    55         return nullptr;
     56        return NULL;
    5657}
    5758
    5859void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size)
    5960{
    60         void* data = (void*)(intptr_t(block) + sizeof(object_header));
     61        void* data = (void*)(((intptr_t)block) + sizeof(gc_object_header));
    6162        void* header = block;
    6263
    63         check(intptr_t(data) > intptr_t(block));
    64         check(intptr_t(data) >= intptr_t(header));
     64        check(((intptr_t)data) > ((intptr_t)block));
     65        check(((intptr_t)data) >= ((intptr_t)header));
    6566        check(is_aligned(data));
    66         check(intptr_t(data) + target_size <= intptr_t(block) + actual_size);
     67        check(((intptr_t)data) + target_size <= ((intptr_t)block) + actual_size);
    6768
    68         object_header* obj = gc_object_header_placement_ctor(header, actual_size);
     69        gc_object_header* obj = gc_object_header_placement_ctor(header, actual_size);
    6970
    7071        (void)obj; //remove unsused warning since this is for debug
    7172        check(obj == get_object_ptr(data));
    7273
    73         gc_register_allocation(get_state(), actual_size);
     74        gc_register_allocation(gc_get_state(), actual_size);
    7475
    7576        return data;
     
    7879//      void process_reference(void** ref, std::vector<void**>& worklist)
    7980//      {
    80 //              check(!gc::get_state().is_in_heap(ref));
     81//              check(!gc::gc_get_state().is_in_heap(ref));
    8182//
    82 //              if(object_header* ptr = get_object_ptr(*ref))
     83//              if(gc_object_header* ptr = get_object_ptr(*ref))
    8384//              {
    8485//                      if(!ptr->is_forwarded)
     
    9899//      }
    99100//
    100 //      void assign_reference(void** ref, object_header* ptr)
     101//      void assign_reference(void** ref, gc_object_header* ptr)
    101102//      {
    102 //              void* address = (void*)(intptr_t(ptr) + sizeof(object_header));
     103//              void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header));
    103104//
    104105//              write_aligned_ptr(ref, address);
    105106//      }
    106107//
    107 //      object_header* copy_object(object_header* ptr)
     108//      gc_object_header* copy_object(gc_object_header* ptr)
    108109//      {
    109110//              check(!ptr->forward);
     
    117118//              std::memcpy(new_block, ptr, ptr->size);
    118119//
    119 //              object_header* fwd_ptr = new (new_block) object_header(ptr);
     120//              gc_object_header* fwd_ptr = new (new_block) gc_object_header(ptr);
    120121//
    121122//              ptr->forward = fwd_ptr;
     
    125126//      }
    126127//
    127 //      void scan_object(object_header* object, std::vector<void**>& worklist)
     128//      void scan_object(gc_object_header* object, std::vector<void**>& worklist)
    128129//      {
    129130//              gcpointer_base* type = object->type_chain;
    130131//              while(type)
    131132//              {
    132 //                      check(intptr_t(type) > intptr_t(object));
    133 //                      check(intptr_t(type) < intptr_t(intptr_t(object) + object->size));
     133//                      check(((intptr_t)type) > ((intptr_t)object));
     134//                      check(((intptr_t)type) < ((intptr_t)((intptr_t)object) + object->size));
    134135//
    135 //                      check(gc::get_state().is_in_to_space(&type->m_ptr));
     136//                      check(gc::gc_get_state().is_in_to_space(&type->m_ptr));
    136137//
    137138//                      worklist.push_back(&type->m_ptr);
Note: See TracChangeset for help on using the changeset viewer.