diff options
author | Akira TAGOH <akira@tagoh.org> | 2006-11-04 06:41:18 +0000 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2006-11-04 06:41:18 +0000 |
commit | 144dc9ca2fcf5cbecb1598e3fe9ab41b611dd9e5 (patch) | |
tree | 52ebfc60cc7c89c1068a46a507428e6c74ac907b | |
parent | 9717851f69f0ceae508e162768b098d6f58d6c4b (diff) |
* hieroglyph/vm.c (hg_vm_lookup): ues logger facility.
(hg_vm_lookup_with_string): likewise.
(hg_vm_set_error): likewise.
* hieroglyph/hgplugins.c (_hg_plugin_load): use logger facility.
* hieroglyph/hgmem.c (_hg_mem_init_stack_start): use logger facility.
(hg_mem_pool_new): likewise.
(hg_mem_gc_mark_array_region): likewise.
* hieroglyph/hgallocator-bfit.c (_hg_allocator_bfit_real_garbage_collection):
use logger facility.
(_hg_allocator_bfit_real_gc_mark): likewise.
* src/hgs.c (main): set flags from HIEROGLYPH_DEBUG environment
variable.
* devices/cairo/hgdevice-cairo.c (_hg_cairo_device_print_path):
use logger facility.
(_hg_cairo_device_real_eofill): likewise.
(_hg_cairo_device_real_fill): likewise.
(_hg_cairo_device_real_stroke): likewise.
(_hg_cairo_device_set_matrix): likewise.
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | devices/cairo/hgdevice-cairo.c | 40 | ||||
-rw-r--r-- | hieroglyph/hgallocator-bfit.c | 60 | ||||
-rw-r--r-- | hieroglyph/hgmem.c | 27 | ||||
-rw-r--r-- | hieroglyph/hgplugins.c | 4 | ||||
-rw-r--r-- | hieroglyph/version.h.in | 2 | ||||
-rw-r--r-- | hieroglyph/vm.c | 7 | ||||
-rw-r--r-- | src/hgs.c | 18 |
8 files changed, 94 insertions, 88 deletions
@@ -1,5 +1,29 @@ 2006-11-04 Akira TAGOH <at@gclab.org> + * hieroglyph/vm.c (hg_vm_lookup): ues logger facility. + (hg_vm_lookup_with_string): likewise. + (hg_vm_set_error): likewise. + + * hieroglyph/hgplugins.c (_hg_plugin_load): use logger facility. + + * hieroglyph/hgmem.c (_hg_mem_init_stack_start): use logger facility. + (hg_mem_pool_new): likewise. + (hg_mem_gc_mark_array_region): likewise. + + * hieroglyph/hgallocator-bfit.c (_hg_allocator_bfit_real_garbage_collection): + use logger facility. + (_hg_allocator_bfit_real_gc_mark): likewise. + + * src/hgs.c (main): set flags from HIEROGLYPH_DEBUG environment + variable. + + * devices/cairo/hgdevice-cairo.c (_hg_cairo_device_print_path): + use logger facility. + (_hg_cairo_device_real_eofill): likewise. + (_hg_cairo_device_real_fill): likewise. + (_hg_cairo_device_real_stroke): likewise. + (_hg_cairo_device_set_matrix): likewise. + * hieroglyph/vm.c (hg_vm_init): initialize logger facility. (hg_vm_finalize): finalize logger. diff --git a/devices/cairo/hgdevice-cairo.c b/devices/cairo/hgdevice-cairo.c index c8fbcee..46f74e6 100644 --- a/devices/cairo/hgdevice-cairo.c +++ b/devices/cairo/hgdevice-cairo.c @@ -62,28 +62,28 @@ static HgDeviceVTable __hg_cairo_device_vtable = { /* * Private Functions */ -#ifdef DEBUG_PATH +#ifdef DEBUG static void _hg_cairo_device_print_path(HgPathNode *node) { - g_print("\n"); + hg_log_debug(DEBUG_PATH, ""); while (node) { switch (node->type) { case HG_PATH_CLOSE: - g_print("closepath\n"); + hg_log_debug(DEBUG_PATH, "closepath"); break; case HG_PATH_MOVETO: - g_print("%f %f moveto\n", node->x, node->y); + hg_log_debug(DEBUG_PATH, "%f %f moveto", node->x, node->y); break; case HG_PATH_LINETO: - g_print("%f %f lineto\n", node->x, node->y); + hg_log_debug(DEBUG_PATH, "%f %f lineto", node->x, node->y); break; case HG_PATH_RLINETO: - g_print("%f %f rlineto\n", node->x, node->y); + hg_log_debug(DEBUG_PATH, "%f %f rlineto", node->x, node->y); break; case HG_PATH_CURVETO: if (node->next && node->next->next) { - g_print("%f %f %f %f %f %f curveto\n", node->x, node->y, node->next->x, node->next->y, node->next->next->x, node->next->next->y); + hg_log_debug(DEBUG_PATH, "%f %f %f %f %f %f curveto", node->x, node->y, node->next->x, node->next->y, node->next->next->x, node->next->next->y); node = node->next->next; } else { hg_log_warning("[BUG] Invalid path for curve."); @@ -91,7 +91,7 @@ _hg_cairo_device_print_path(HgPathNode *node) break; case HG_PATH_ARC: if (node->next && node->next->next) { - g_print("%f %f %f %f %f arc\n", node->x, node->y, node->next->x, node->next->next->x, node->next->next->y); + hg_log_debug(DEBUG_PATH, "%f %f %f %f %f arc", node->x, node->y, node->next->x, node->next->next->x, node->next->next->y); node = node->next->next; } else { hg_log_warning("[BUG] Invalid path for arc."); @@ -99,7 +99,7 @@ _hg_cairo_device_print_path(HgPathNode *node) break; case HG_PATH_MATRIX: if (node->next && node->next->next) { - g_print("[%f %f %f %f %f %f] matrix\n", node->x, node->y, node->next->x, node->next->y, node->next->next->x, node->next->next->y); + hg_log_debug(DEBUG_PATH, "[%f %f %f %f %f %f] matrix", node->x, node->y, node->next->x, node->next->y, node->next->next->x, node->next->next->y); node = node->next->next; } else { hg_log_warning("[BUG] Invalid matrix was given."); @@ -111,9 +111,11 @@ _hg_cairo_device_print_path(HgPathNode *node) } node = node->next; } - g_print("%% end\n\n"); + hg_log_debug(DEBUG_PATH, "%% end\n"); } -#endif /* DEBUG_PATH */ +#else +#define _hg_cairo_device_print_path(_node_) +#endif /* DEBUG */ /* * hsv_to_rgb() is borrowed from GTK+ @@ -258,10 +260,8 @@ _hg_cairo_device_real_eofill(HgDevice *device, { HgCairoDevice *cdev = (HgCairoDevice *)device; -#ifdef DEBUG_PATH - g_print("eofill\n"); + hg_log_debug(DEBUG_PATH, "%% eofill"); _hg_cairo_device_print_path(render->path); -#endif /* DEBUG_PATH */ _hg_cairo_device_set_matrix(cdev, &render->mtx); if (!_hg_cairo_device_set_path(cdev, render->path)) return FALSE; @@ -291,10 +291,8 @@ _hg_cairo_device_real_fill(HgDevice *device, { HgCairoDevice *cdev = (HgCairoDevice *)device; -#ifdef DEBUG_PATH - g_print("fill\n"); + hg_log_debug(DEBUG_PATH, "%% fill"); _hg_cairo_device_print_path(render->path); -#endif /* DEBUG_PATH */ _hg_cairo_device_set_matrix(cdev, &render->mtx); if (!_hg_cairo_device_set_path(cdev, render->path)) return FALSE; @@ -327,10 +325,8 @@ _hg_cairo_device_real_stroke(HgDevice *device, guint len, i; HgValueNode *node; -#ifdef DEBUG_PATH - g_print("stroke\n"); + hg_log_debug(DEBUG_PATH, "%% stroke"); _hg_cairo_device_print_path(render->path); -#endif /* DEBUG_PATH */ _hg_cairo_device_set_matrix(cdev, &render->mtx); if (!_hg_cairo_device_set_path(cdev, render->path)) return FALSE; @@ -387,9 +383,7 @@ _hg_cairo_device_set_matrix(HgCairoDevice *device, cairo_matrix_init(&trans, 1.0, 0.0, 0.0, -1.0, 0.0, device->device.height); cairo_matrix_multiply(&trans, &mtx_, &trans); -#ifdef DEBUG_PATH - g_print("[%f %f %f %f %f %f] setmatrix\n", trans.xx, trans.yx, trans.xy, trans.yy, trans.x0, trans.y0); -#endif /* DEBUG_PATH */ + hg_log_debug(DEBUG_PATH, "[%f %f %f %f %f %f] setmatrix\n", trans.xx, trans.yx, trans.xy, trans.yy, trans.x0, trans.y0); cairo_set_matrix(device->reference, &trans); } diff --git a/hieroglyph/hgallocator-bfit.c b/hieroglyph/hgallocator-bfit.c index 4ed8f91..b14c847 100644 --- a/hieroglyph/hgallocator-bfit.c +++ b/hieroglyph/hgallocator-bfit.c @@ -713,9 +713,9 @@ _hg_allocator_bfit_real_garbage_collection(HgMemPool *pool) guint i; gboolean retval = FALSE; GList *reflist; -#ifdef DEBUG_GC +#ifdef DEBUG guint total = 0, swept = 0; -#endif /* DEBUG_GC */ +#endif /* DEBUG */ if (pool->is_collecting) { /* just return without doing anything */ @@ -737,24 +737,18 @@ _hg_allocator_bfit_real_garbage_collection(HgMemPool *pool) p->age_of_gc_mark++; } } -#ifdef DEBUG_GC - g_print("DEBUG_GC: starting GC for %s\n", pool->name); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "starting GC for %s", pool->name); if (!pool->destroyed) { if (!pool->use_gc) { pool->is_collecting = FALSE; return FALSE; } -#ifdef DEBUG_GC - g_print("DEBUG_GC: marking start.\n"); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "marking start."); /* mark phase */ pool->allocator->vtable->gc_mark(pool); } -#ifdef DEBUG_GC - g_print("DEBUG_GC: sweeping start.\n"); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "sweeping start."); /* sweep phase */ for (i = 0; i < priv->heap2block_array->len; i++) { HgMemBFitBlock *block = g_ptr_array_index(priv->heap2block_array, i), *tmp; @@ -772,24 +766,22 @@ _hg_allocator_bfit_real_garbage_collection(HgMemPool *pool) if (block->in_use > 0) { if (!hg_mem_is_gc_mark__inline(obj) && (pool->destroyed || !hg_mem_is_locked(obj))) { -#ifdef DEBUG_GC +#ifdef DEBUG swept++; - g_print("DEBUG_GC: sweeping %p (block: %p memobj: %p size: %" G_GSIZE_FORMAT " age: %d[current %d])\n", obj->data, obj->subid, obj, ((HgMemBFitBlock *)obj->subid)->length, HG_MEMOBJ_GET_MARK_AGE (obj), obj->pool->age_of_gc_mark); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "sweeping %p (block: %p memobj: %p size: %" G_GSIZE_FORMAT " age: %d[current %d])", obj->data, obj->subid, obj, ((HgMemBFitBlock *)obj->subid)->length, HG_MEMOBJ_GET_MARK_AGE (obj), obj->pool->age_of_gc_mark); +#endif /* DEBUG */ hg_mem_free(obj->data); retval = TRUE; } } -#ifdef DEBUG_GC +#ifdef DEBUG total++; -#endif /* DEBUG_GC */ +#endif /* DEBUG */ block = tmp; } } -#ifdef DEBUG_GC - g_print("DEBUG_GC: GC finished (total: %d blocks swept: %d blocks)\n", - total, swept); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "GC finished (total: %d blocks swept: %d blocks)", + total, swept); pool->is_collecting = FALSE; return retval; @@ -804,9 +796,7 @@ _hg_allocator_bfit_real_gc_mark(HgMemPool *pool) return; pool->is_processing = TRUE; -#ifdef DEBUG_GC - g_print("MARK AGE: %d (%s)\n", pool->age_of_gc_mark, pool->name); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "MARK AGE: %d (%s)", pool->age_of_gc_mark, pool->name); G_STMT_START { GList *list, *reflist; HgMemObject *obj; @@ -820,13 +810,9 @@ _hg_allocator_bfit_real_gc_mark(HgMemPool *pool) } else { if (!hg_mem_is_gc_mark__inline(obj)) { hg_mem_gc_mark__inline(obj); -#ifdef DEBUG_GC - g_print("MARK: %p (mem: %p age: %d) from root node.\n", obj->data, obj, HG_MEMOBJ_GET_MARK_AGE (obj)); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "MARK: %p (mem: %p age: %d) from root node.", obj->data, obj, HG_MEMOBJ_GET_MARK_AGE (obj)); } else { -#ifdef DEBUG_GC - g_print("MARK[already]: %p (mem: %p age: %d) from root node.\n", obj->data, obj, HG_MEMOBJ_GET_MARK_AGE (obj)); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "MARK[already]: %p (mem: %p age: %d) from root node.", obj->data, obj, HG_MEMOBJ_GET_MARK_AGE (obj)); } } } @@ -834,24 +820,16 @@ _hg_allocator_bfit_real_gc_mark(HgMemPool *pool) for (reflist = pool->other_pool_ref_list; reflist != NULL; reflist = g_list_next(reflist)) { -#ifdef DEBUG_GC - g_print("DEBUG_GC: entering %s\n", ((HgMemPool *)reflist->data)->name); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "entering %s", ((HgMemPool *)reflist->data)->name); ((HgMemPool *)reflist->data)->allocator->vtable->gc_mark(reflist->data); -#ifdef DEBUG_GC - g_print("DEBUG_GC: leaving %s\n", ((HgMemPool *)reflist->data)->name); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "leaving %s", ((HgMemPool *)reflist->data)->name); } /* trace in the registers */ setjmp(env); -#ifdef DEBUG_GC - g_print("DEBUG_GC: marking from registers.\n"); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "marking from registers."); hg_mem_gc_mark_array_region(pool, (gpointer)env, (gpointer)env + sizeof (env)); /* trace the stack */ -#ifdef DEBUG_GC - g_print("DEBUG_GC: marking from stacks.\n"); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "marking from stacks."); hg_mem_gc_mark_array_region(pool, _hg_stack_start, _hg_stack_end); } G_STMT_END; diff --git a/hieroglyph/hgmem.c b/hieroglyph/hgmem.c index c4c4637..10bca0d 100644 --- a/hieroglyph/hgmem.c +++ b/hieroglyph/hgmem.c @@ -65,7 +65,8 @@ _hg_mem_init_stack_start(void) if ((fd = open("/proc/self/stat", O_RDONLY)) == -1 || read(fd, stat_buffer, STAT_BUFSIZE) < 2 * STAT_SKIP) { - g_error("Failed to read /proc/self/stat"); + hg_log_error("Failed to read /proc/self/stat"); + abort(); } else { c = stat_buffer[offset++]; for (i = 0; i < STAT_SKIP; i++) { @@ -79,8 +80,10 @@ _hg_mem_init_stack_start(void) c = stat_buffer[offset++]; } close(fd); - if (result < 0x10000000) - g_error("the stack bottom may be invalid: %x.", result); + if (result < 0x10000000) { + hg_log_error("the stack bottom may be invalid: %x.", result); + abort(); + } _hg_stack_start = (gpointer)result; } #else @@ -237,7 +240,7 @@ hg_mem_pool_new(HgAllocator *allocator, pool = (HgMemPool *)g_new(HgMemPool, 1); if (pool == NULL) { - g_error("Failed to allocate a memory pool for %s", identity); + hg_log_error("Failed to allocate a memory pool for %s", identity); return NULL; } pool->name = g_strdup(identity); @@ -607,27 +610,19 @@ hg_mem_gc_mark_array_region(HgMemPool *pool, obj = hg_mem_get_object__inline_nocheck(*(gsize *)p); if (pool->allocator->vtable->is_safe_object(pool, obj)) { if (!hg_mem_is_gc_mark__inline(obj)) { -#ifdef DEBUG_GC - g_print("MARK: %p (mem: %p age: %d) from array region.\n", obj->data, obj, HG_MEMOBJ_GET_MARK_AGE (obj)); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "MARK: %p (mem: %p age: %d) from array region.\n", obj->data, obj, HG_MEMOBJ_GET_MARK_AGE (obj)); hg_mem_gc_mark__inline(obj); } else { -#ifdef DEBUG_GC - g_print("MARK[already]: %p (mem: %p) from array region.\n", obj->data, obj); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "MARK[already]: %p (mem: %p) from array region.\n", obj->data, obj); } } obj = p; if (pool->allocator->vtable->is_safe_object(pool, obj)) { if (!hg_mem_is_gc_mark__inline(obj)) { -#ifdef DEBUG_GC - g_print("MARK: %p (mem: %p) from array region.\n", obj->data, obj); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "MARK: %p (mem: %p) from array region.\n", obj->data, obj); hg_mem_gc_mark__inline(obj); } else { -#ifdef DEBUG_GC - g_print("MARK[already]: %p (mem: %p) from array region.\n", obj->data, obj); -#endif /* DEBUG_GC */ + hg_log_debug(DEBUG_GC, "MARK[already]: %p (mem: %p) from array region.\n", obj->data, obj); } } } diff --git a/hieroglyph/hgplugins.c b/hieroglyph/hgplugins.c index 8047535..f6a8630 100644 --- a/hieroglyph/hgplugins.c +++ b/hieroglyph/hgplugins.c @@ -111,10 +111,8 @@ _hg_plugin_load(HgMemPool *pool, } else { retval->module = module; } -#ifdef DEBUG_PLUGIN } else { - hg_log_warning(g_module_error()); -#endif + hg_log_debug(DEBUG_PLUGIN, g_module_error()); } return retval; diff --git a/hieroglyph/version.h.in b/hieroglyph/version.h.in index 4dbad8d..5dd8f47 100644 --- a/hieroglyph/version.h.in +++ b/hieroglyph/version.h.in @@ -29,7 +29,7 @@ G_BEGIN_DECLS #define HIEROGLYPH_VERSION "@VERSION@" -#define HIEROGLYPH_UUID "7f4b1b31-6cd2-41b5-8ec2-f27bf6615dac" +#define HIEROGLYPH_UUID "17bc12b8-af9f-4216-bf93-2c83e487c600" const char *__hg_rcsid G_GNUC_UNUSED = "$Rev$"; diff --git a/hieroglyph/vm.c b/hieroglyph/vm.c index 658b809..fe9257b 100644 --- a/hieroglyph/vm.c +++ b/hieroglyph/vm.c @@ -952,7 +952,7 @@ hg_vm_lookup(HgVM *vm, node = hg_stack_index(vm->dstack, i); if (node == NULL || !HG_IS_VALUE_DICT (node)) { - g_error("dictionary stack was broken."); + hg_log_error("dictionary stack was broken."); break; } dict = HG_VALUE_GET_DICT (node); @@ -977,7 +977,7 @@ hg_vm_lookup_with_string(HgVM *vm, for (i = 0; i < depth; i++) { node = hg_stack_index(vm->dstack, i); if (node == NULL || !HG_IS_VALUE_DICT (node)) { - g_error("dictionary stack was broken."); + hg_log_error("dictionary stack was broken."); break; } if ((retval = hg_dict_lookup_with_string(HG_VALUE_GET_DICT (node), key)) != NULL) @@ -1168,7 +1168,8 @@ hg_vm_set_error(HgVM *vm, } copy_proc = hg_object_copy((HgObject *)proc); if (copy_proc == NULL) { - g_error("FATAL: failed to allocate a memory for an error handler. there are no way to recover it unfortunately."); + hg_log_error("FATAL: failed to allocate a memory for an error handler. there are no way to recover it unfortunately."); + abort(); } self = hg_stack_pop(vm->estack); _hg_stack_push(vm->estack, copy_proc); @@ -24,6 +24,7 @@ #include <hieroglyph/hgdevice.h> #include <hieroglyph/hgdict.h> #include <hieroglyph/hgfile.h> +#include <hieroglyph/hglog.h> #include <hieroglyph/hgmem.h> #include <hieroglyph/hgvaluenode.h> #include <hieroglyph/vm.h> @@ -90,12 +91,27 @@ main(int argc, {NULL} }; GError *error = NULL; - const gchar *psfile = NULL; + const gchar *psfile = NULL, *env; gint32 errcode = 0; HG_MEM_INIT; hg_vm_init(); + /* set debugging flags prior to initialize VM */ + if ((env = g_getenv("HIEROGLYPH_DEBUG")) != NULL) { + gchar **flags = g_strsplit(env, ",:", 0); + int i; + + for (i = 0; flags[i] != NULL; i++) { + gchar *key = g_strdup_printf("DEBUG_%s", flags[i]); + + hg_log_set_flag(key, TRUE); + g_free(key); + } + + g_strfreev(flags); + } + vm = hg_vm_new(VM_EMULATION_LEVEL_1); group = g_option_group_new(NULL, NULL, NULL, vm, NULL); |