summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2006-06-03 12:13:32 +0000
committerAkira TAGOH <akira@tagoh.org>2006-06-03 12:13:32 +0000
commit2aad7c2e3478b66bcdffb079cb90f9016bc90223 (patch)
tree74c740bf03c1096df4d5615c53b34396eb4c047b
parent9a64ca4eb9499a80574128e1dd8b4fb8324d2ef4 (diff)
* hieroglyph/hgmem.c (hg_mem_get_object_size): new function.
* hieroglyph/hgallocator-bfit.c (_hg_allocator_get_object_size__inline): new macro. (_hg_allocator_bfit_real_get_size): new function. * src/hgspy_helper.c (hg_mem_alloc_with_flags): don't access block_size directly. (hg_mem_free): likewise.
-rw-r--r--ChangeLog10
-rw-r--r--hieroglyph/hgallocator-bfit.c26
-rw-r--r--hieroglyph/hgmem.c16
-rw-r--r--hieroglyph/hgmem.h1
-rw-r--r--hieroglyph/hgtypes.h2
-rw-r--r--hieroglyph/version.h.in2
-rw-r--r--src/hgspy_helper.c4
7 files changed, 50 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 4746ad7..7f7edcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2006-06-03 Akira TAGOH <at@gclab.org>
+ * hieroglyph/hgmem.c (hg_mem_get_object_size): new function.
+
+ * hieroglyph/hgallocator-bfit.c (_hg_allocator_get_object_size__inline):
+ new macro.
+ (_hg_allocator_bfit_real_get_size): new function.
+
+ * src/hgspy_helper.c (hg_mem_alloc_with_flags): don't access block_size
+ directly.
+ (hg_mem_free): likewise.
+
* hieroglyph/hgbtree.c (hg_btree_find_near): fixed to get correct near block.
* hieroglyph/hgallocator-bfit.c (_hg_allocator_get_minimum_aligned_size__inline):
diff --git a/hieroglyph/hgallocator-bfit.c b/hieroglyph/hgallocator-bfit.c
index 10f8ef7..b178a91 100644
--- a/hieroglyph/hgallocator-bfit.c
+++ b/hieroglyph/hgallocator-bfit.c
@@ -69,6 +69,7 @@ static void _hg_allocator_bfit_real_free (HgMemPool
gpointer data);
static gpointer _hg_allocator_bfit_real_resize (HgMemObject *object,
gsize size);
+static gsize _hg_allocator_bfit_real_get_size (HgMemObject *object);
static gboolean _hg_allocator_bfit_real_garbage_collection(HgMemPool *pool);
static void _hg_allocator_bfit_real_gc_mark (HgMemPool *pool);
static void _hg_allocator_bfit_real_gc_unmark (HgMemPool *pool);
@@ -90,6 +91,7 @@ static HgAllocatorVTable __hg_allocator_bfit_vtable = {
.alloc = _hg_allocator_bfit_real_alloc,
.free = _hg_allocator_bfit_real_free,
.resize = _hg_allocator_bfit_real_resize,
+ .get_size = _hg_allocator_bfit_real_get_size,
.garbage_collection = _hg_allocator_bfit_real_garbage_collection,
.gc_mark = _hg_allocator_bfit_real_gc_mark,
.gc_unmark = _hg_allocator_bfit_real_gc_unmark,
@@ -118,6 +120,8 @@ static HgObjectVTable __hg_snapshot_vtable = {
G_STMT_START { \
(__hg_aligned_ret) = ((__hg_aga_size) + (__hg_alignment_size)) / (__hg_alignment_size) * (__hg_alignment_size); \
} G_STMT_END
+#define _hg_allocator_get_object_size__inline(__hg_ago_object) \
+ ((HgMemBFitBlock *)(__hg_ago_object)->subid)->length
/* utility functions */
static HgMemBFitBlock *
@@ -509,7 +513,6 @@ _hg_allocator_bfit_real_alloc(HgMemPool *pool,
obj->id = HG_MEM_HEADER;
obj->subid = block;
obj->pool = pool;
- obj->block_size = block_size;
HG_MEMOBJ_INIT_FLAGS (obj);
HG_MEMOBJ_SET_HEAP_ID (obj, block->heap_id);
HG_MEMOBJ_SET_FLAGS (obj, flags);
@@ -564,7 +567,7 @@ _hg_allocator_bfit_real_resize(HgMemObject *object,
_hg_allocator_get_aligned_size__inline(sizeof (HgMemObject) + size,
HG_MEM_ALIGNMENT,
block_size);
- if (block_size > object->block_size) {
+ if (block_size > _hg_allocator_get_object_size__inline(object)) {
gpointer p;
HgMemRelocateInfo info;
HgObject *hobj;
@@ -579,7 +582,8 @@ _hg_allocator_bfit_real_resize(HgMemObject *object,
info.start = (gsize)object;
info.end = (gsize)object;
info.diff = (gsize)p - (gsize)object->data;
- memcpy(p, object->data, object->block_size - sizeof (HgMemObject));
+ memcpy(p, object->data,
+ _hg_allocator_get_object_size__inline(object) - sizeof (HgMemObject));
/* avoid to call HgObject's free function so that
* it will be invoked from copied object.
*/
@@ -595,10 +599,10 @@ _hg_allocator_bfit_real_resize(HgMemObject *object,
}
return p;
- } else if (block_size < object->block_size &&
- (object->block_size - block_size) > min_block_size) {
+ } else if (block_size < _hg_allocator_get_object_size__inline(object) &&
+ (_hg_allocator_get_object_size__inline(object) - block_size) > min_block_size) {
HgHeap *heap = g_ptr_array_index(pool->heap_list, HG_MEMOBJ_GET_HEAP_ID (object));
- gsize fixed_size = object->block_size - block_size;
+ gsize fixed_size = _hg_allocator_get_object_size__inline(object) - block_size;
HgMemBFitBlock *block = _hg_bfit_block_new((gpointer)((gsize)object + block_size),
fixed_size,
heap->serial);
@@ -613,7 +617,7 @@ _hg_allocator_bfit_real_resize(HgMemObject *object,
block->next = blk->next;
if (blk->next)
blk->next->prev = block;
- object->block_size = blk->length = block_size;
+ blk->length = block_size;
blk->next = block;
pool->used_heap_size -= block->length;
_hg_allocator_bfit_add_free_block(priv, block);
@@ -622,6 +626,14 @@ _hg_allocator_bfit_real_resize(HgMemObject *object,
return object->data;
}
+static gsize
+_hg_allocator_bfit_real_get_size(HgMemObject *object)
+{
+ HgMemBFitBlock *block = object->subid;
+
+ return block->length;
+}
+
static gboolean
_hg_allocator_bfit_real_garbage_collection(HgMemPool *pool)
{
diff --git a/hieroglyph/hgmem.c b/hieroglyph/hgmem.c
index ee64213..c6ac101 100644
--- a/hieroglyph/hgmem.c
+++ b/hieroglyph/hgmem.c
@@ -517,6 +517,22 @@ hg_mem_resize(gpointer data,
return obj->pool->allocator->vtable->resize(obj, size);
}
+gsize
+hg_mem_get_object_size(gpointer data)
+{
+ HgMemObject *obj;
+
+ g_return_val_if_fail (data != NULL, 0);
+
+ hg_mem_get_object__inline(data, obj);
+ if (obj == NULL) {
+ g_warning("Invalid object %p was about to get an object size.", data);
+ return 0;
+ }
+
+ return obj->pool->allocator->vtable->get_size(obj);
+}
+
/* GC */
void
hg_mem_add_root_node(HgMemPool *pool,
diff --git a/hieroglyph/hgmem.h b/hieroglyph/hgmem.h
index 69ce0a5..15c3bdf 100644
--- a/hieroglyph/hgmem.h
+++ b/hieroglyph/hgmem.h
@@ -86,6 +86,7 @@ gpointer hg_mem_alloc_with_flags (HgMemPool *pool,
gboolean hg_mem_free (gpointer data);
gpointer hg_mem_resize (gpointer data,
gsize size);
+gsize hg_mem_get_object_size (gpointer data);
/* internal use */
gboolean _hg_mem_pool_is_own_memobject (HgMemPool *pool,
diff --git a/hieroglyph/hgtypes.h b/hieroglyph/hgtypes.h
index 8fc6971..c989ce9 100644
--- a/hieroglyph/hgtypes.h
+++ b/hieroglyph/hgtypes.h
@@ -215,6 +215,7 @@ struct _HieroGlyphAllocatorVTable {
gpointer data);
gpointer (* resize) (HgMemObject *object,
gsize size);
+ gsize (* get_size) (HgMemObject *object);
gboolean (* garbage_collection) (HgMemPool *pool);
void (* gc_mark) (HgMemPool *pool);
void (* gc_unmark) (HgMemPool *pool);
@@ -239,7 +240,6 @@ struct _HieroGlyphMemObject {
gint32 id;
gpointer subid;
HgMemPool *pool;
- gsize block_size;
guint32 flags;
gpointer data[];
};
diff --git a/hieroglyph/version.h.in b/hieroglyph/version.h.in
index ca841ea..4c59bd6 100644
--- a/hieroglyph/version.h.in
+++ b/hieroglyph/version.h.in
@@ -27,7 +27,7 @@
#include <glib/gmacros.h>
#define HIEROGLYPH_VERSION "@VERSION@"
-#define HIEROGLYPH_UUID "f0bfdd37-de7a-47cf-a0e1-cedc25b29ae9"
+#define HIEROGLYPH_UUID "5346c5b2-5d31-4c38-b8f7-1aba0075ebc6"
const char *__hg_rcsid G_GNUC_UNUSED = "$Rev$";
diff --git a/src/hgspy_helper.c b/src/hgspy_helper.c
index 09d55a4..b42a4a5 100644
--- a/src/hgspy_helper.c
+++ b/src/hgspy_helper.c
@@ -84,7 +84,7 @@ hg_mem_alloc_with_flags(HgMemPool *pool,
hg_memory_visualizer_set_chunk_state(HG_MEMORY_VISUALIZER (visual),
HG_MEMOBJ_GET_HEAP_ID (obj),
obj,
- obj->block_size,
+ hg_mem_get_object_size(retval),
HG_CHUNK_USED);
}
@@ -101,7 +101,7 @@ hg_mem_free(gpointer data)
hg_memory_visualizer_set_chunk_state(HG_MEMORY_VISUALIZER (visual),
HG_MEMOBJ_GET_HEAP_ID (obj),
obj,
- obj->block_size,
+ hg_mem_get_object_size(data),
HG_CHUNK_FREE);
}