* src/vmcore/loader.c (vmcore/field.h): Added.
authortwisti <none@none>
Tue, 24 Jul 2007 11:55:07 +0000 (11:55 +0000)
committertwisti <none@none>
Tue, 24 Jul 2007 11:55:07 +0000 (11:55 +0000)
(load_field): Removed.
(load_class_from_classbuffer): Call field_load.

* src/vmcore/field.c (stdint.h): Added.
(vm/exceptions.h): Likewise.
(vm/stringlocal.h): Likewise.
(vm/vm.h): Likewise.
(vmcore/descriptor.h): Likewise.
(vmcore/loader.h): Likewise.
(vmcore/options.h): Likewise.
(vmcore/suck.h): Likewise.
(field_load): New function.

* src/vmcore/field.h (field_load): Added.

src/vmcore/field.c
src/vmcore/field.h
src/vmcore/loader.c

index 4f8dcff7a907a1086812bad79f4117abd0b74be3..c2c337a7a5ae87160ae207fd0eb30c115e8adf6a 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: field.c 8132 2007-06-22 11:15:47Z twisti $
+   $Id: field.c 8227 2007-07-24 11:55:07Z twisti $
 
 */
 
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 #include <stdio.h>
 
 #include "vm/types.h"
 
+#include "vm/exceptions.h"
+#include "vm/stringlocal.h"
+#include "vm/vm.h"
+
 #include "vmcore/class.h"
+#include "vmcore/descriptor.h"
 #include "vmcore/field.h"
+#include "vmcore/loader.h"
+#include "vmcore/options.h"
 #include "vmcore/primitive.h"
 #include "vmcore/references.h"
+#include "vmcore/suck.h"
 #include "vmcore/utf8.h"
 
 
+/* field_load ******************************************************************
+
+   Load everything about a class field from the class file and fill a
+   fieldinfo structure.
+
+*******************************************************************************/
+
+#define field_load_NOVALUE  0xffffffff /* must be bigger than any u2 value! */
+
+bool field_load(classbuffer *cb, fieldinfo *f, descriptor_pool *descpool)
+{
+       classinfo *c;
+       u4 attrnum, i;
+       u4 jtype;
+       u4 pindex = field_load_NOVALUE;     /* constantvalue_index */
+       utf *u;
+
+       c = cb->class;
+
+       if (!suck_check_classbuffer_size(cb, 2 + 2 + 2))
+               return false;
+
+       f->flags = suck_u2(cb);
+
+       if (!(u = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
+               return false;
+
+       f->name = u;
+
+       if (!(u = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
+               return false;
+
+       f->descriptor = u;
+       f->parseddesc = NULL;
+
+       if (!descriptor_pool_add(descpool, u, NULL))
+               return false;
+
+       /* descriptor_pool_add accepts method descriptors, so we have to
+          check against them here before the call of
+          descriptor_to_basic_type below. */
+
+       if (u->text[0] == '(') {
+               exceptions_throw_classformaterror(c, "Method descriptor used for field");
+               return false;
+       }
+
+#ifdef ENABLE_VERIFIER
+       if (opt_verify) {
+               /* check name */
+               if (!is_valid_name_utf(f->name) || f->name->text[0] == '<') {
+                       exceptions_throw_classformaterror(c,
+                                                                                         "Illegal Field name \"%s\"",
+                                                                                         f->name->text);
+                       return false;
+               }
+
+               /* check flag consistency */
+               i = f->flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
+
+               if ((i != 0 && i != ACC_PUBLIC && i != ACC_PRIVATE && i != ACC_PROTECTED) ||
+                       ((f->flags & (ACC_FINAL | ACC_VOLATILE)) == (ACC_FINAL | ACC_VOLATILE))) {
+                       exceptions_throw_classformaterror(c,
+                                                                                         "Illegal field modifiers: 0x%X",
+                                                                                         f->flags);
+                       return false;
+               }
+
+               if (c->flags & ACC_INTERFACE) {
+                       if (((f->flags & (ACC_STATIC | ACC_PUBLIC | ACC_FINAL))
+                               != (ACC_STATIC | ACC_PUBLIC | ACC_FINAL)) ||
+                               f->flags & ACC_TRANSIENT) {
+                               exceptions_throw_classformaterror(c,
+                                                                                                 "Illegal field modifiers: 0x%X",
+                                                                                                 f->flags);
+                               return false;
+                       }
+               }
+       }
+#endif /* ENABLE_VERIFIER */
+
+       /* data type */
+
+       jtype = descriptor_to_basic_type(f->descriptor);
+
+       f->class  = c;
+       f->type   = jtype;
+       f->offset = 0;                             /* offset from start of object */
+
+       switch (f->type) {
+       case TYPE_INT:
+               f->value.i = 0;
+               break;
+
+       case TYPE_FLT:
+               f->value.f = 0.0;
+               break;
+
+       case TYPE_DBL:
+               f->value.d = 0.0;
+               break;
+
+       case TYPE_ADR:
+               f->value.a = NULL;
+               if (!(f->flags & ACC_STATIC))
+                       c->flags |= ACC_CLASS_HAS_POINTERS;
+               break;
+
+       case TYPE_LNG:
+#if U8_AVAILABLE
+               f->value.l = 0;
+#else
+               f->value.l.low  = 0;
+               f->value.l.high = 0;
+#endif
+               break;
+       }
+
+       /* read attributes */
+       if (!suck_check_classbuffer_size(cb, 2))
+               return false;
+
+       attrnum = suck_u2(cb);
+       for (i = 0; i < attrnum; i++) {
+               if (!suck_check_classbuffer_size(cb, 2))
+                       return false;
+
+               if (!(u = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
+                       return false;
+
+               if (u == utf_ConstantValue) {
+                       if (!suck_check_classbuffer_size(cb, 4 + 2))
+                               return false;
+
+                       /* check attribute length */
+
+                       if (suck_u4(cb) != 2) {
+                               exceptions_throw_classformaterror(c, "Wrong size for VALUE attribute");
+                               return false;
+                       }
+                       
+                       /* constant value attribute */
+
+                       if (pindex != field_load_NOVALUE) {
+                               exceptions_throw_classformaterror(c, "Multiple ConstantValue attributes");
+                               return false;
+                       }
+                       
+                       /* index of value in constantpool */
+
+                       pindex = suck_u2(cb);
+               
+                       /* initialize field with value from constantpool */             
+
+                       switch (jtype) {
+                       case TYPE_INT: {
+                               constant_integer *ci; 
+
+                               if (!(ci = class_getconstant(c, pindex, CONSTANT_Integer)))
+                                       return false;
+
+                               f->value.i = ci->value;
+                       }
+                       break;
+                                       
+                       case TYPE_LNG: {
+                               constant_long *cl; 
+
+                               if (!(cl = class_getconstant(c, pindex, CONSTANT_Long)))
+                                       return false;
+
+                               f->value.l = cl->value;
+                       }
+                       break;
+
+                       case TYPE_FLT: {
+                               constant_float *cf;
+
+                               if (!(cf = class_getconstant(c, pindex, CONSTANT_Float)))
+                                       return false;
+
+                               f->value.f = cf->value;
+                       }
+                       break;
+                                                                                       
+                       case TYPE_DBL: {
+                               constant_double *cd;
+
+                               if (!(cd = class_getconstant(c, pindex, CONSTANT_Double)))
+                                       return false;
+
+                               f->value.d = cd->value;
+                       }
+                       break;
+                                               
+                       case TYPE_ADR:
+                               if (!(u = class_getconstant(c, pindex, CONSTANT_String)))
+                                       return false;
+
+                               /* create javastring from compressed utf8-string */
+                               f->value.a = literalstring_new(u);
+                               break;
+       
+                       default: 
+                               vm_abort("field_load: invalid field type %d", jtype);
+                       }
+               }
+#if defined(ENABLE_JAVASE)
+               else if (u == utf_Signature) {
+                       /* Signature */
+
+                       if (!loader_load_attribute_signature(cb, &(f->signature)))
+                               return false;
+               }
+#endif
+               else {
+                       /* unknown attribute */
+
+                       if (!loader_skip_attribute_body(cb))
+                               return false;
+               }
+       }
+
+       /* everything was ok */
+
+       return true;
+}
+
+
 /* field_get_type **************************************************************
 
    Returns the type of the field as class.
index 00616399d4c8aac0d891afdd21d6a4bc3c28c284..a1293b861770d251806d28d5638c776a1872dfb2 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: field.h 8132 2007-06-22 11:15:47Z twisti $
+   $Id: field.h 8227 2007-07-24 11:55:07Z twisti $
 */
 
 
@@ -72,6 +72,7 @@ struct fieldinfo {          /* field of a class                                 */
 
 /* function prototypes ********************************************************/
 
+bool       field_load(classbuffer *cb, fieldinfo *f, descriptor_pool *descpool);
 classinfo *field_get_type(fieldinfo *f);
 void       field_free(fieldinfo *f);
 
index 93aba2eccc3f0b5ccea74aac01a5f618bbdb5b11..bbc99a1dc9e5eb2745ab40adefcc660ea98bdf64 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: loader.c 8086 2007-06-14 15:31:54Z twisti $
+   $Id: loader.c 8227 2007-07-24 11:55:07Z twisti $
 
 */
 
@@ -55,6 +55,7 @@
 #endif
 
 #include "vmcore/classcache.h"
+#include "vmcore/field.h"
 #include "vmcore/linker.h"
 #include "vmcore/loader.h"
 #include "vmcore/options.h"
@@ -818,229 +819,6 @@ bool loader_load_attribute_signature(classbuffer *cb, utf **signature)
 #endif /* defined(ENABLE_JAVASE) */
 
 
-/* load_field ******************************************************************
-
-   Load everything about a class field from the class file and fill a
-   'fieldinfo' structure. For static fields, space in the data segment
-   is allocated.
-
-*******************************************************************************/
-
-#define field_load_NOVALUE  0xffffffff /* must be bigger than any u2 value! */
-
-static bool load_field(classbuffer *cb, fieldinfo *f, descriptor_pool *descpool)
-{
-       classinfo *c;
-       u4 attrnum, i;
-       u4 jtype;
-       u4 pindex = field_load_NOVALUE;     /* constantvalue_index */
-       utf *u;
-
-       c = cb->class;
-
-       if (!suck_check_classbuffer_size(cb, 2 + 2 + 2))
-               return false;
-
-       f->flags = suck_u2(cb);
-
-       if (!(u = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
-               return false;
-
-       f->name = u;
-
-       if (!(u = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
-               return false;
-
-       f->descriptor = u;
-       f->parseddesc = NULL;
-
-       if (!descriptor_pool_add(descpool, u, NULL))
-               return false;
-
-       /* descriptor_pool_add accepts method descriptors, so we have to check  */
-       /* against them here before the call of descriptor_to_basic_type below. */
-       if (u->text[0] == '(') {
-               exceptions_throw_classformaterror(c, "Method descriptor used for field");
-               return false;
-       }
-
-#ifdef ENABLE_VERIFIER
-       if (opt_verify) {
-               /* check name */
-               if (!is_valid_name_utf(f->name) || f->name->text[0] == '<') {
-                       exceptions_throw_classformaterror(c,
-                                                                                         "Illegal Field name \"%s\"",
-                                                                                         f->name->text);
-                       return false;
-               }
-
-               /* check flag consistency */
-               i = f->flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
-
-               if ((i != 0 && i != ACC_PUBLIC && i != ACC_PRIVATE && i != ACC_PROTECTED) ||
-                       ((f->flags & (ACC_FINAL | ACC_VOLATILE)) == (ACC_FINAL | ACC_VOLATILE))) {
-                       exceptions_throw_classformaterror(c,
-                                                                                         "Illegal field modifiers: 0x%X",
-                                                                                         f->flags);
-                       return false;
-               }
-
-               if (c->flags & ACC_INTERFACE) {
-                       if (((f->flags & (ACC_STATIC | ACC_PUBLIC | ACC_FINAL))
-                               != (ACC_STATIC | ACC_PUBLIC | ACC_FINAL)) ||
-                               f->flags & ACC_TRANSIENT) {
-                               exceptions_throw_classformaterror(c,
-                                                                                                 "Illegal field modifiers: 0x%X",
-                                                                                                 f->flags);
-                               return false;
-                       }
-               }
-       }
-#endif /* ENABLE_VERIFIER */
-
-       f->type   = jtype = descriptor_to_basic_type(f->descriptor); /* data type */
-       f->offset = 0;                             /* offset from start of object */
-       f->class  = c;
-
-       switch (f->type) {
-       case TYPE_INT:
-               f->value.i = 0;
-               break;
-
-       case TYPE_FLT:
-               f->value.f = 0.0;
-               break;
-
-       case TYPE_DBL:
-               f->value.d = 0.0;
-               break;
-
-       case TYPE_ADR:
-               f->value.a = NULL;
-               if (!(f->flags & ACC_STATIC))
-                       c->flags |= ACC_CLASS_HAS_POINTERS;
-               break;
-
-       case TYPE_LNG:
-#if U8_AVAILABLE
-               f->value.l = 0;
-#else
-               f->value.l.low  = 0;
-               f->value.l.high = 0;
-#endif
-               break;
-       }
-
-       /* read attributes */
-       if (!suck_check_classbuffer_size(cb, 2))
-               return false;
-
-       attrnum = suck_u2(cb);
-       for (i = 0; i < attrnum; i++) {
-               if (!suck_check_classbuffer_size(cb, 2))
-                       return false;
-
-               if (!(u = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
-                       return false;
-
-               if (u == utf_ConstantValue) {
-                       if (!suck_check_classbuffer_size(cb, 4 + 2))
-                               return false;
-
-                       /* check attribute length */
-
-                       if (suck_u4(cb) != 2) {
-                               exceptions_throw_classformaterror(c, "Wrong size for VALUE attribute");
-                               return false;
-                       }
-                       
-                       /* constant value attribute */
-
-                       if (pindex != field_load_NOVALUE) {
-                               exceptions_throw_classformaterror(c, "Multiple ConstantValue attributes");
-                               return false;
-                       }
-                       
-                       /* index of value in constantpool */
-
-                       pindex = suck_u2(cb);
-               
-                       /* initialize field with value from constantpool */             
-                       switch (jtype) {
-                       case TYPE_INT: {
-                               constant_integer *ci; 
-
-                               if (!(ci = class_getconstant(c, pindex, CONSTANT_Integer)))
-                                       return false;
-
-                               f->value.i = ci->value;
-                       }
-                       break;
-                                       
-                       case TYPE_LNG: {
-                               constant_long *cl; 
-
-                               if (!(cl = class_getconstant(c, pindex, CONSTANT_Long)))
-                                       return false;
-
-                               f->value.l = cl->value;
-                       }
-                       break;
-
-                       case TYPE_FLT: {
-                               constant_float *cf;
-
-                               if (!(cf = class_getconstant(c, pindex, CONSTANT_Float)))
-                                       return false;
-
-                               f->value.f = cf->value;
-                       }
-                       break;
-                                                                                       
-                       case TYPE_DBL: {
-                               constant_double *cd;
-
-                               if (!(cd = class_getconstant(c, pindex, CONSTANT_Double)))
-                                       return false;
-
-                               f->value.d = cd->value;
-                       }
-                       break;
-                                               
-                       case TYPE_ADR:
-                               if (!(u = class_getconstant(c, pindex, CONSTANT_String)))
-                                       return false;
-
-                               /* create javastring from compressed utf8-string */
-                               f->value.a = literalstring_new(u);
-                               break;
-       
-                       default: 
-                               log_text("Invalid Constant - Type");
-                       }
-               }
-#if defined(ENABLE_JAVASE)
-               else if (u == utf_Signature) {
-                       /* Signature */
-
-                       if (!loader_load_attribute_signature(cb, &(f->signature)))
-                               return false;
-               }
-#endif
-               else {
-                       /* unknown attribute */
-
-                       if (!loader_skip_attribute_body(cb))
-                               return false;
-               }
-       }
-
-       /* everything was ok */
-
-       return true;
-}
-
-
 /* loader_load_method **********************************************************
 
    Loads a method from the class file and fills an existing
@@ -2041,7 +1819,7 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
 #endif
 
        for (i = 0; i < c->fieldscount; i++) {
-               if (!load_field(cb, &(c->fields[i]),descpool))
+               if (!field_load(cb, &(c->fields[i]), descpool))
                        goto return_exception;
        }