array out of memory fixlet, InvocationTargetException handling, less debug output...
[cacao.git] / loader.c
index 25cefc519231bc6fe3dab378dcb2b9e8e0980331..945d41aaf5417154b9962079552e9a76af5d2d4e 100644 (file)
--- a/loader.c
+++ b/loader.c
@@ -28,8 +28,9 @@
    Changes: Andreas Krall
             Roman Obermaiser
             Mark Probst
+                       Edwin Steiner
 
-   $Id: loader.c 687 2003-12-04 22:29:54Z edwin $
+   $Id: loader.c 696 2003-12-06 20:10:05Z edwin $
 
 */
 
@@ -416,8 +417,7 @@ bool suck_start(utf *classname)
                }
        }
        if (verbose) {
-               sprintf(logtext, "Warning: Can not open class file '%s'", filename);
-               dolog();
+               dolog("Warning: Can not open class file '%s'", filename);
        }
 
        return false;
@@ -440,9 +440,8 @@ void suck_stop()
 
        if (classdata_left > 0) {
                /* surplus */           
-               sprintf(logtext, "There are %d access bytes at end of classfile",
+               dolog("There are %d access bytes at end of classfile",
                                classdata_left);
-               dolog();
        }
 
        /* free memory */
@@ -545,9 +544,8 @@ voidptr innerclass_getconstant (classinfo *c, u4 pos, u4 ctype)
 
        /* check type of constantpool entry */
        if (c->cptags[pos] != ctype) {
-               sprintf (logtext, "Type mismatch on constant: %d requested, %d here (innerclass_getconstant)",
+               error ("Type mismatch on constant: %d requested, %d here (innerclass_getconstant)",
                 (int) ctype, (int) c->cptags[pos] );
-               error();
                }
                
        return c->cpinfos[pos];
@@ -891,6 +889,7 @@ static void method_load (methodinfo *m, classinfo *c)
        m -> flags = suck_u2 ();
        m -> name =  class_getconstant (c, suck_u2(), CONSTANT_Utf8);
        m -> descriptor = class_getconstant (c, suck_u2(), CONSTANT_Utf8);
+       checkmethoddescriptor(m->descriptor);
        
        m -> jcode = NULL;
        m -> exceptiontable = NULL;
@@ -1038,9 +1037,8 @@ voidptr class_getconstant (classinfo *c, u4 pos, u4 ctype)
 
        if (c->cptags[pos] != ctype) {
                class_showconstantpool(c);
-               sprintf (logtext, "Type mismatch on constant: %d requested, %d here (class_getconstant)",
+               error ("Type mismatch on constant: %d requested, %d here (class_getconstant)",
                 (int) ctype, (int) c->cptags[pos] );
-               error();
                }
                
        return c->cpinfos[pos];
@@ -1280,8 +1278,7 @@ static void class_loadcpool (classinfo *c)
                                }
                                                                                
                        default:
-                               sprintf (logtext, "Unkown constant type: %d",(int) t);
-                               error ();
+                               error ("Unkown constant type: %d",(int) t);
                
                        }  /* end switch */
                        
@@ -1416,9 +1413,10 @@ static int class_load(classinfo *c)
 
        /* output for debugging purposes */
        if (loadverbose) {              
+               char logtext[MAXLOGTEXT];
                sprintf(logtext, "Loading class: ");
                utf_sprint(logtext+strlen(logtext), c->name);
-               dolog();
+               dolog(logtext);
        }
        
        /* load classdata, throw exception on error */
@@ -1434,9 +1432,8 @@ static int class_load(classinfo *c)
        mi = suck_u2(); 
        ma = suck_u2();
        if (ma != MAJOR_VERSION && (ma != MAJOR_VERSION+1 || mi != 0)) {
-               sprintf (logtext, "File version %d.%d is not supported",
+               error ("File version %d.%d is not supported",
                                 (int) ma, (int) mi);
-               error();
                }
 
        class_loadcpool (c);
@@ -1449,6 +1446,8 @@ static int class_load(classinfo *c)
 
        /* ACC flags */
        c -> flags = suck_u2 (); 
+       /*if (!(c->flags & ACC_PUBLIC)) { log_text("CLASS NOT PUBLIC"); } JOWENN*/
+
        /* this class */
        suck_u2 ();       
        
@@ -1520,9 +1519,10 @@ static s4 class_highestinterface (classinfo *c)
        s4 i;
        
        if ( ! (c->flags & ACC_INTERFACE) ) {
+               char logtext[MAXLOGTEXT];
                sprintf (logtext, "Interface-methods count requested for non-interface:  ");
        utf_sprint (logtext+strlen(logtext), c->name);
-       error();
+       error(logtext);
        }
     
     h = c->index;
@@ -1601,6 +1601,8 @@ class_new_array(classinfo *c)
        methodinfo *clone;
        int namelen;
 
+       /* XXX remove */ /* dolog("class_new_array: %s",c->name->text); */
+
        /* Array classes are not loaded from classfiles. */
        list_remove (&unloadedclasses, c);
 
@@ -1628,12 +1630,12 @@ class_new_array(classinfo *c)
        c->super = class_java_lang_Object;
 
     c->interfacescount = 2;
-    c->interfaces = MNEW(classinfo*,2);
+    c->interfaces = MNEW(classinfo*,2); /* XXX use GC? */
     c->interfaces[0] = class_java_lang_Cloneable;
     c->interfaces[1] = class_java_io_Serializable;
 
        c->methodscount = 1;
-       c->methods = MNEW (methodinfo, c->methodscount);
+       c->methods = MNEW (methodinfo, c->methodscount); /* XXX use GC? */
 
        clone = c->methods;
        memset(clone,0,sizeof(methodinfo));
@@ -1845,9 +1847,10 @@ void class_link(classinfo *c)
 
 
        if (linkverbose) {
+               char logtext[MAXLOGTEXT];
                sprintf (logtext, "Linking Class: ");
                utf_sprint (logtext+strlen(logtext), c->name );
-               dolog ();
+               dolog (logtext);
        }
 
        /* compute vftbl length */
@@ -2379,10 +2382,11 @@ void class_init(classinfo *c)
         m = class_findmethod (c, utf_clinit, utf_fidesc);
         if (!m) {
                 if (initverbose) {
+                                               char logtext[MAXLOGTEXT];
                         sprintf (logtext, "Class ");
                         utf_sprint (logtext+strlen(logtext), c->name);
                         sprintf (logtext+strlen(logtext), " has no initializer");
-                        dolog ();
+                        dolog (logtext);
                         }
 /*              goto callinitialize;*/
                 return;
@@ -2392,9 +2396,10 @@ void class_init(classinfo *c)
                 panic ("Class initializer is not static!");
 
         if (initverbose) {
+                               char logtext[MAXLOGTEXT];
                 sprintf (logtext, "Starting initializer for class: ");
                 utf_sprint (logtext+strlen(logtext), c->name);
-                dolog ();
+                dolog (logtext);
         }
 
 #ifdef USE_THREADS
@@ -2419,9 +2424,10 @@ void class_init(classinfo *c)
                 }
 
         if (initverbose) {
+                               char logtext[MAXLOGTEXT];
                 sprintf (logtext, "Finished initializer for class: ");
                 utf_sprint (logtext+strlen(logtext), c->name);
-                dolog ();
+                dolog (logtext);
         }
         if (c->name == utf_systemclass) {
                 /* class java.lang.System requires explicit initialization */
@@ -2810,7 +2816,7 @@ void create_primitive_classes()
                c->loaded=true;
                /* add to unlinked classes */
                list_addlast (&unlinkedclasses, c);             
-               c -> super = class_java_lang_Object;
+/*JOWENN primitive types don't have objects as super class             c -> super = class_java_lang_Object; */
                class_link (c);
 
                primitivetype_table[i].class_primitive = c;
@@ -2879,7 +2885,7 @@ classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mod
        char *start = utf_ptr;
        bool error = false;
        utf *name;
-       
+
        SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,error);
        if (error) return NULL;
        if (next) *next = utf_ptr;