diff options
author | Akira TAGOH <akira@tagoh.org> | 2007-11-27 00:49:48 +0000 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2007-11-27 00:49:48 +0000 |
commit | ae9b673764c35b593582d248036f102639c573d2 (patch) | |
tree | 258c210193a387e0c37b1f74a26f80d5e48bddda | |
parent | 18c0114661d1c1c75130f7a56441fc33047d622c (diff) |
2007-11-27 Akira TAGOH <akira@tagoh.org>
* hieroglyph/hgobject.c (_hg_object_new): Initialize the object type.
(hg_object_name_new): Initialize the unused value too.
* hieroglyph/vm.c (hg_vm_get_current_allocation_mode): new function.
(hg_vm_set_current_allocation_mode): likewise.
(hg_vm_get_attributes): Follow the value for the allocation mode.
* hieroglyph/hgdict.c (_hg_object_dict_insert): Fix a typo.
(hg_object_dict_new): Initialize the array area.
* configure.ac (AC_INIT): Update the bug report address.
* tests/hgdict.c: Add more test cases.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | hieroglyph/hgdict.c | 4 | ||||
-rw-r--r-- | hieroglyph/hgobject.c | 11 | ||||
-rw-r--r-- | hieroglyph/hgtypes.h | 1 | ||||
-rw-r--r-- | hieroglyph/version.h.in | 8 | ||||
-rw-r--r-- | hieroglyph/vm.c | 15 | ||||
-rw-r--r-- | hieroglyph/vm.h | 77 | ||||
-rw-r--r-- | tests/hgdict.c | 139 |
9 files changed, 225 insertions, 48 deletions
@@ -1,3 +1,19 @@ +2007-11-27 Akira TAGOH <akira@tagoh.org> + + * hieroglyph/hgobject.c (_hg_object_new): Initialize the object type. + (hg_object_name_new): Initialize the unused value too. + + * hieroglyph/vm.c (hg_vm_get_current_allocation_mode): new function. + (hg_vm_set_current_allocation_mode): likewise. + (hg_vm_get_attributes): Follow the value for the allocation mode. + + * hieroglyph/hgdict.c (_hg_object_dict_insert): Fix a typo. + (hg_object_dict_new): Initialize the array area. + + * configure.ac (AC_INIT): Update the bug report address. + + * tests/hgdict.c: Add more test cases. + 2007-10-22 Akira TAGOH <akira@tagoh.org> * hieroglyph/hgarray.c (hg_object_array_new): initialize the array. diff --git a/configure.ac b/configure.ac index 3062541..f7dadd3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT([hieroglyph], 0.0.1, [akira@tagoh.org]) +AC_INIT([hieroglyph], 0.0.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=Hieroglyph]) . ./requires diff --git a/hieroglyph/hgdict.c b/hieroglyph/hgdict.c index cd45e5b..b5c619a 100644 --- a/hieroglyph/hgdict.c +++ b/hieroglyph/hgdict.c @@ -25,6 +25,7 @@ #include "config.h" #endif +#include <string.h> #include <glib/gstrfuncs.h> #include <hieroglyph/hgobject.h> #include "hgdict.h" @@ -119,7 +120,7 @@ _hg_object_dict_insert(hg_object_t *dict, } } - return FALSE; + return retval; } /* @@ -138,6 +139,7 @@ hg_object_dict_new(hg_vm_t *vm, HG_OBJECT_GET_TYPE (retval) = HG_OBJECT_TYPE_DICT; HG_OBJECT_DICT (retval)->length = n_nodes; HG_OBJECT_DICT (retval)->used = 0; + memset(HG_OBJECT_DICT_DATA (retval), 0, sizeof (hg_dictdata_t) * __hg_dict_primes[n_nodes]); } return retval; diff --git a/hieroglyph/hgobject.c b/hieroglyph/hgobject.c index 3519a6f..95aec7c 100644 --- a/hieroglyph/hgobject.c +++ b/hieroglyph/hgobject.c @@ -52,12 +52,19 @@ _hg_object_new(hg_vm_t *vm, retval = hg_vm_malloc(vm, total_size); if (retval != NULL) { +#ifdef DEBUG + /* We don't ensure whether or not the allocated object is sane + * to be used in C. any classes must have their own initializer + * as needed + */ memset(HG_OBJECT_OBJECT (retval), -1, sizeof (_hg_object_t) + data_size); +#endif /* DEBUG */ hg_vm_get_attributes(vm, &attr); HG_OBJECT_HEADER (retval)->token_type = hg_vm_get_object_format(vm); HG_OBJECT_HEADER (retval)->n_objects = 0xff; HG_OBJECT_HEADER (retval)->total_length = total_size; HG_OBJECT_OBJECT (retval)->attr.attributes = attr.attributes; + HG_OBJECT_GET_TYPE (retval) = -1; } else { hg_vm_set_error(vm, HG_e_VMerror); } @@ -479,6 +486,10 @@ hg_object_name_new(hg_vm_t *vm, } else { HG_OBJECT_GET_TYPE (retval) = HG_OBJECT_TYPE_NAME; } + /* initialize the reserved area to not confuse between + * the encoding named object and the named object. + */ + HG_OBJECT_NAME (retval)->reserved1 = 0; HG_OBJECT_NAME (retval)->length = size; memcpy(HG_OBJECT_DATA (retval), value, size); } diff --git a/hieroglyph/hgtypes.h b/hieroglyph/hgtypes.h index 6705f82..a49b268 100644 --- a/hieroglyph/hgtypes.h +++ b/hieroglyph/hgtypes.h @@ -804,6 +804,7 @@ enum hg_emulationtype_e { }; struct hg_vm_s { + gboolean is_global; }; G_END_DECLS diff --git a/hieroglyph/version.h.in b/hieroglyph/version.h.in index fa38507..14ae25c 100644 --- a/hieroglyph/version.h.in +++ b/hieroglyph/version.h.in @@ -21,8 +21,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#ifndef f421545e-1fe0-4719-8407-50677cae0f6eVERSION_H__ -#define f421545e-1fe0-4719-8407-50677cae0f6eVERSION_H__ +#ifndef be37381d-6757-45e2-818f-020bd2a1f7f0VERSION_H__ +#define be37381d-6757-45e2-818f-020bd2a1f7f0VERSION_H__ #include <glib/gmacros.h> @@ -30,10 +30,10 @@ G_BEGIN_DECLS #define HIEROGLYPH_VERSION "@VERSION@" -#define HIEROGLYPH_UUID "f421545e-1fe0-4719-8407-50677cae0f6e" +#define HIEROGLYPH_UUID "be37381d-6757-45e2-818f-020bd2a1f7f0" const char *__hg_rcsid G_GNUC_UNUSED = "$Rev$"; G_END_DECLS -#endif /* f421545e-1fe0-4719-8407-50677cae0f6eVERSION_H__ */ +#endif /* be37381d-6757-45e2-818f-020bd2a1f7f0VERSION_H__ */ diff --git a/hieroglyph/vm.c b/hieroglyph/vm.c index fd2c5a1..9733234 100644 --- a/hieroglyph/vm.c +++ b/hieroglyph/vm.c @@ -378,6 +378,19 @@ hg_vm_get_object_format(hg_vm_t *vm) return 0; } +gboolean +hg_vm_get_current_allocation_mode(hg_vm_t *vm) +{ + return vm->is_global; +} + +void +hg_vm_set_current_allocation_mode(hg_vm_t *vm, + gboolean is_global) +{ + vm->is_global = is_global; +} + void hg_vm_get_attributes(hg_vm_t *vm, hg_attribute_t *attr) @@ -392,7 +405,7 @@ hg_vm_get_attributes(hg_vm_t *vm, attr->bit.is_locked = FALSE; attr->bit.reserved4 = FALSE; attr->bit.reserved5 = FALSE; - attr->bit.is_global = FALSE; + attr->bit.is_global = hg_vm_get_current_allocation_mode(vm); attr->bit.is_checked = FALSE; } diff --git a/hieroglyph/vm.h b/hieroglyph/vm.h index 904bf9b..b04199e 100644 --- a/hieroglyph/vm.h +++ b/hieroglyph/vm.h @@ -27,43 +27,46 @@ #include <hieroglyph/hgtypes.h> -hg_vm_t *hg_vm_new (void) G_GNUC_WARN_UNUSED_RESULT; -void hg_vm_destroy (hg_vm_t *vm); -gpointer hg_vm_malloc (hg_vm_t *vm, - gsize size) G_GNUC_WARN_UNUSED_RESULT; -gpointer hg_vm_realloc (hg_vm_t *vm, - gpointer object, - gsize size) G_GNUC_WARN_UNUSED_RESULT; -void hg_vm_mfree (hg_vm_t *vm, - gpointer data); -guchar hg_vm_get_object_format (hg_vm_t *vm); -void hg_vm_get_attributes (hg_vm_t *vm, - hg_attribute_t *attr); -void hg_vm_set_error (hg_vm_t *vm, - hg_error_t error); -hg_error_t hg_vm_get_error (hg_vm_t *vm); -void hg_vm_clear_error (hg_vm_t *vm); -hg_object_t *hg_vm_get_io (hg_vm_t *vm, - hg_filetype_t iotype); -void hg_vm_set_io (hg_vm_t *vm, - hg_object_t *object); -gboolean hg_vm_initialize (hg_vm_t *vm); -gboolean hg_vm_finalize (hg_vm_t *vm); -hg_emulationtype_t hg_vm_get_emulation_level(hg_vm_t *vm); -gboolean hg_vm_set_emulation_level(hg_vm_t *vm, - hg_emulationtype_t level); -gboolean hg_vm_stepi (hg_vm_t *vm, - gboolean *is_proceeded); -gboolean hg_vm_step (hg_vm_t *vm); -hg_object_t *hg_vm_get_dict (hg_vm_t *vm); -hg_object_t *hg_vm_dict_lookup (hg_vm_t *vm, - hg_object_t *object); -gboolean hg_vm_dict_remove (hg_vm_t *vm, - const gchar *name, - gboolean remove_all); -hg_object_t *hg_vm_get_currentdict (hg_vm_t *vm); -hg_object_t *hg_vm_name_lookup (hg_vm_t *vm, - const gchar *name) G_GNUC_WARN_UNUSED_RESULT; +hg_vm_t *hg_vm_new (void) G_GNUC_WARN_UNUSED_RESULT; +void hg_vm_destroy (hg_vm_t *vm); +gpointer hg_vm_malloc (hg_vm_t *vm, + gsize size) G_GNUC_WARN_UNUSED_RESULT; +gpointer hg_vm_realloc (hg_vm_t *vm, + gpointer object, + gsize size) G_GNUC_WARN_UNUSED_RESULT; +void hg_vm_mfree (hg_vm_t *vm, + gpointer data); +guchar hg_vm_get_object_format (hg_vm_t *vm); +gboolean hg_vm_get_current_allocation_mode(hg_vm_t *vm); +void hg_vm_set_current_allocation_mode(hg_vm_t *vm, + gboolean is_global); +void hg_vm_get_attributes (hg_vm_t *vm, + hg_attribute_t *attr); +void hg_vm_set_error (hg_vm_t *vm, + hg_error_t error); +hg_error_t hg_vm_get_error (hg_vm_t *vm); +void hg_vm_clear_error (hg_vm_t *vm); +hg_object_t *hg_vm_get_io (hg_vm_t *vm, + hg_filetype_t iotype); +void hg_vm_set_io (hg_vm_t *vm, + hg_object_t *object); +gboolean hg_vm_initialize (hg_vm_t *vm); +gboolean hg_vm_finalize (hg_vm_t *vm); +hg_emulationtype_t hg_vm_get_emulation_level (hg_vm_t *vm); +gboolean hg_vm_set_emulation_level (hg_vm_t *vm, + hg_emulationtype_t level); +gboolean hg_vm_stepi (hg_vm_t *vm, + gboolean *is_proceeded); +gboolean hg_vm_step (hg_vm_t *vm); +hg_object_t *hg_vm_get_dict (hg_vm_t *vm); +hg_object_t *hg_vm_dict_lookup (hg_vm_t *vm, + hg_object_t *object); +gboolean hg_vm_dict_remove (hg_vm_t *vm, + const gchar *name, + gboolean remove_all); +hg_object_t *hg_vm_get_currentdict (hg_vm_t *vm); +hg_object_t *hg_vm_name_lookup (hg_vm_t *vm, + const gchar *name) G_GNUC_WARN_UNUSED_RESULT; #endif /* __HIEROGLYPH__VM_H__ */ diff --git a/tests/hgdict.c b/tests/hgdict.c index a4140c1..14026a0 100644 --- a/tests/hgdict.c +++ b/tests/hgdict.c @@ -25,6 +25,7 @@ #include "config.h" #endif #include <hieroglyph/hgdict.h> +#include <hieroglyph/hgobject.h> #include <hieroglyph/vm.h> #include "main.h" @@ -47,13 +48,36 @@ teardown(void) /* dict object */ TDEF (hg_object_dict_new) { - g_print("FIXME: %s\n", __FUNCTION__); + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + fail_unless(HG_OBJECT_IS_DICT (obj), "Object isn't a dict object"); + + hg_object_free(vm, obj); } TEND TDEF (hg_object_dict_compare) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj2; + + obj = hg_object_dict_new(vm, 10); + obj2 = hg_object_dict_new(vm, 10); + + TNUL (obj); + TNUL (obj2); + fail_unless(!hg_object_dict_compare(obj, obj2), "Different allocation has to be failed"); + + hg_object_free(vm, obj); + hg_object_free(vm, obj2); + + obj = hg_object_dict_new(vm, 10); + obj2 = hg_object_dup(vm, obj); + + TNUL (obj); + TNUL (obj2); + fail_unless(hg_object_dict_compare(obj, obj2), "Failed to compare the dict objects"); + + hg_object_free(vm, obj); } TEND @@ -65,7 +89,112 @@ TEND TDEF (hg_object_dict_insert) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj1, *obj1_, *obj2, *obj2_, *obj3, *obj3_, *obj4, *obj4_, *obj_; + gboolean allocmode = hg_vm_get_current_allocation_mode(vm); + + /* objects allocated from the global pool */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + + obj1 = hg_object_name_new(vm, "bool", FALSE); + obj1_ = hg_object_boolean_new(vm, TRUE); + obj2 = hg_object_name_new(vm, "int", FALSE); + obj2_ = hg_object_integer_new(vm, 10); + obj3 = hg_object_name_new(vm, "name", FALSE); + obj3_ = hg_object_name_new(vm, "foo", FALSE); + TNUL (obj1); + TNUL (obj1_); + TNUL (obj2); + TNUL (obj2_); + TNUL (obj3); + TNUL (obj3_); + + fail_unless(hg_object_dict_insert(obj, obj1, obj1_), "Failed to insert an object (bool)"); + fail_unless(hg_object_dict_insert(obj, obj2, obj2_), "Failed to insert an object (int)"); + fail_unless(hg_object_dict_insert(obj, obj3, obj3_), "Failed to insert an object (named)"); + + fail_unless((obj_ = hg_object_dict_lookup(obj, obj1)) != NULL, "Failed to look up the object (bool)"); + fail_unless(hg_object_compare(obj1_, obj_), "Failed to compare the object after looking up (bool)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj2)) != NULL, "Failed to look up the object (int)"); + fail_unless(hg_object_compare(obj2_, obj_), "Failed to compare the object after looking up (int)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj3)) != NULL, "Failed to look up the object (named)"); + fail_unless(hg_object_compare(obj3_, obj_), "Failed to compare the object after looking up (named)"); + + /* Insert object allocated in the local pool to the global object */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj4 = hg_object_name_new(vm, "bool2", FALSE); + obj4_ = hg_object_boolean_new(vm, TRUE); + TNUL (obj4); + TNUL (obj4_); + fail_unless(!hg_object_dict_insert(obj, obj4, obj4_), "Have to fail inserting the local object into the global object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj4_); + hg_object_free(vm, obj4); + hg_object_free(vm, obj3_); + hg_object_free(vm, obj3); + hg_object_free(vm, obj2_); + hg_object_free(vm, obj2); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* objects allocated from the local pool */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + fail_unless(!HG_OBJECT_ATTR_IS_GLOBAL (obj), "Object wasn't allocated from the local pool."); + + obj1 = hg_object_name_new(vm, "bool", FALSE); + obj1_ = hg_object_boolean_new(vm, TRUE); + obj2 = hg_object_name_new(vm, "int", FALSE); + obj2_ = hg_object_integer_new(vm, 10); + obj3 = hg_object_name_new(vm, "name", FALSE); + obj3_ = hg_object_name_new(vm, "foo", FALSE); + TNUL (obj1); + TNUL (obj1_); + TNUL (obj2); + TNUL (obj2_); + TNUL (obj3); + TNUL (obj3_); + + fail_unless(hg_object_dict_insert(obj, obj1, obj1_), "Failed to insert an object (bool)"); + fail_unless(hg_object_dict_insert(obj, obj2, obj2_), "Failed to insert an object (int)"); + fail_unless(hg_object_dict_insert(obj, obj3, obj3_), "Failed to insert an object (named)"); + + fail_unless((obj_ = hg_object_dict_lookup(obj, obj1)) != NULL, "Failed to look up the object (bool)"); + fail_unless(hg_object_compare(obj1_, obj_), "Failed to compare the object after looking up (bool)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj2)) != NULL, "Failed to look up the object (int)"); + fail_unless(hg_object_compare(obj2_, obj_), "Failed to compare the object after looking up (int)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj3)) != NULL, "Failed to look up the object (named)"); + fail_unless(hg_object_compare(obj3_, obj_), "Failed to compare the object after looking up (named)"); + + /* Insert object allocated in the global pool to the local object */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj4 = hg_object_name_new(vm, "bool2", FALSE); + obj4_ = hg_object_boolean_new(vm, TRUE); + TNUL (obj4); + TNUL (obj4_); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj4), "Object wasn't allocated from the global pool."); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj4_), "Object wasn't allocated from the global pool."); + fail_unless(hg_object_dict_insert(obj, obj4, obj4_), "Don't have to fail inserting the global object into the local object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj4_); + hg_object_free(vm, obj4); + hg_object_free(vm, obj3_); + hg_object_free(vm, obj3); + hg_object_free(vm, obj2_); + hg_object_free(vm, obj2); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* recover the allocation mode */ + hg_vm_set_current_allocation_mode(vm, allocmode); } TEND @@ -95,7 +224,9 @@ TEND TDEF (hg_object_dict_lookup) { - g_print("FIXME: %s\n", __FUNCTION__); + /* all the testcases should be in insert/replace testing. + * so there are nothing we have to do here so far. + */ } TEND |