We used to use class->interfaces_count (where 'class' is a pointer to a
cafebabe class struct). But array (and native) classes don't have a
"physical" representation. It's better to just set nr_interfaces to 0
instead of special-casing ->class everywhere; besides, array classes
need to implement the Clonable interface.

Signed-off-by: Vegard Nossum <vegard.nos...@gmail.com>
---
 include/vm/class.h |    1 +
 vm/class.c         |    7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/vm/class.h b/include/vm/class.h
index 830b6d5..4333f4a 100644
--- a/include/vm/class.h
+++ b/include/vm/class.h
@@ -33,6 +33,7 @@ struct vm_class {
        char *name;
 
        struct vm_class *super;
+       unsigned int nr_interfaces;
        struct vm_class **interfaces;
        struct vm_field *fields;
        struct vm_method *methods;
diff --git a/vm/class.c b/vm/class.c
index 0bf8137..72cf18b 100644
--- a/vm/class.c
+++ b/vm/class.c
@@ -186,8 +186,9 @@ int vm_class_link(struct vm_class *vmc, const struct 
cafebabe_class *class)
                vmc->super = NULL;
        }
 
+       vmc->nr_interfaces = class->interfaces_count;
        vmc->interfaces
-               = malloc(sizeof(*vmc->interfaces) * class->interfaces_count);
+               = malloc(sizeof(*vmc->interfaces) * vmc->nr_interfaces);
        if (!vmc->interfaces) {
                NOT_IMPLEMENTED;
                return -1;
@@ -323,6 +324,7 @@ int vm_class_link_primitive_class(struct vm_class *vmc, 
const char *class_name)
        vmc->state = VM_CLASS_LINKED;
 
        vmc->super = vm_java_lang_Object;
+       vmc->nr_interfaces = 0;
        vmc->interfaces = NULL;
        vmc->fields = NULL;
        vmc->methods = NULL;
@@ -348,6 +350,7 @@ int vm_class_link_array_class(struct vm_class *vmc, const 
char *class_name)
        vmc->state = VM_CLASS_LINKED;
 
        vmc->super = vm_java_lang_Object;
+       vmc->nr_interfaces = 0;
        vmc->interfaces = NULL;
        vmc->fields = NULL;
        vmc->methods = NULL;
@@ -786,7 +789,7 @@ bool vm_class_is_assignable_from(const struct vm_class 
*vmc, const struct vm_cla
        if (from->super && vm_class_is_assignable_from(vmc, from->super))
                return true;
 
-       for (unsigned int i = 0; i < from->class->interfaces_count; ++i) {
+       for (unsigned int i = 0; i < from->nr_interfaces; ++i) {
                if (vm_class_is_assignable_from(vmc, from->interfaces[i]))
                        return true;
        }
-- 
1.6.0.4


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to