Commit 515c1a0d authored by Jean-Paul Saman's avatar Jean-Paul Saman

object_heap.c: calculate the correct index into the heap.

The location of an object in the heap was wrongly determined, by applying the HEAP_ID_MASK to the object id. Instead the heap->id_offset should have been substracted from the object id. The object id is created by using the i-th position plus heap->id_offset.
parent 4a3eac85
......@@ -128,7 +128,7 @@ object_base_p object_heap_lookup( object_heap_p heap, int id )
{
return NULL;
}
id &= OBJECT_HEAP_ID_MASK;
id -= heap->id_offset;
obj = (object_base_p) (heap->heap_index + id * heap->object_size);
/* Check if the object has in fact been allocated */
......@@ -157,7 +157,7 @@ object_base_p object_heap_next( object_heap_p heap, object_heap_iterator *iter )
{
object_base_p obj;
int i = *iter + 1;
while ( i < heap->heap_size)
while ( i < heap->heap_size )
{
obj = (object_base_p) (heap->heap_index + i * heap->object_size);
if (obj->next_free == ALLOCATED)
......@@ -171,8 +171,6 @@ object_base_p object_heap_next( object_heap_p heap, object_heap_iterator *iter )
return NULL;
}
/*
* Frees an object
*/
......@@ -185,7 +183,7 @@ void object_heap_free( object_heap_p heap, object_base_p obj )
ASSERT( obj->next_free == ALLOCATED );
obj->next_free = heap->next_free;
heap->next_free = obj->id & OBJECT_HEAP_ID_MASK;
heap->next_free = obj->id - heap->id_offset;
}
}
......
......@@ -46,7 +46,6 @@
#define VA_OBJECT_HEAP_H
#define OBJECT_HEAP_OFFSET_MASK 0x7f000000
#define OBJECT_HEAP_ID_MASK 0x00ffffff
typedef struct object_base *object_base_p;
typedef struct object_heap *object_heap_p;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment