* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / native / vm / VMClassLoader.c
index e9df30a45297e75283f07e9af2036e538e292605..db996ca16774c9b218ab1e8b4c235cf5478b9314 100644 (file)
@@ -1,9 +1,9 @@
 /* src/native/vm/VMClassLoader.c - java/lang/VMClassLoader
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Roman Obermaiser
 
@@ -30,7 +30,7 @@
             Christian Thalinger
             Edwin Steiner
 
-   $Id: VMClassLoader.c 3888 2005-12-05 22:08:45Z twisti $
+   $Id: VMClassLoader.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
 
@@ -59,6 +59,8 @@
 #include "vm/options.h"
 #include "vm/statistics.h"
 #include "vm/stringlocal.h"
+#include "vm/suck.h"
+#include "vm/zip.h"
 #include "vm/jit/asmpart.h"
 
 
@@ -74,14 +76,17 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIE
        classbuffer *cb;
        utf         *utfname;
 
-       if ((cl == NULL) || (data == NULL)) {
-               *exceptionptr = new_nullpointerexception();
+       /* check if data was passed */
+
+       if (data == NULL) {
+               exceptions_throw_nullpointerexception();
                return NULL;
        }
 
+       /* check the indexes passed */
+
        if ((offset < 0) || (len < 0) || ((offset + len) > data->header.size)) {
-               *exceptionptr =
-                       new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+               exceptions_throw_arrayindexoutofboundsexception();
                return NULL;
        }
 
@@ -107,7 +112,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIE
 
        c = class_create_classinfo(utfname);
 
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
        /* measure time */
 
        if (getloadingtime)
@@ -134,7 +139,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_defineClass(JNIE
 
        FREE(cb, classbuffer);
 
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
        /* measure time */
 
        if (getloadingtime)
@@ -230,14 +235,14 @@ JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jc
        ci = (classinfo *) c;
 
        if (!ci) {
-               *exceptionptr = new_nullpointerexception();
+               exceptions_throw_nullpointerexception();
                return;
        }
 
        /* link the class */
 
        if (!(ci->state & CLASS_LINKED))
-               link_class(ci);
+               (void) link_class(ci);
 
        return;
 }
@@ -254,7 +259,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv
        utf *u;
 
        if (!name) {
-               *exceptionptr = new_nullpointerexception();
+               exceptions_throw_nullpointerexception();
                return NULL;
        }
 
@@ -302,18 +307,18 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv
  */
 JNIEXPORT java_util_Vector* JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv *env, jclass clazz, java_lang_String *name)
 {
-       jobject           o;
-       methodinfo       *m;
-       java_lang_String *path;
-       classpath_info   *cpi;
-       utf              *utfname;
-       char             *charname;
-       char             *end;
-       char             *tmppath;
-       s4                namelen;
-       s4                pathlen;
-       struct stat       buf;
-       jboolean          ret;
+       jobject               o;
+       methodinfo           *m;
+       java_lang_String     *path;
+       list_classpath_entry *lce;
+       utf                  *utfname;
+       char                 *charname;
+       char                 *end;
+       char                 *tmppath;
+       s4                    namelen;
+       s4                    pathlen;
+       struct stat           buf;
+       jboolean              ret;
 
        /* get the resource name as utf string */
 
@@ -352,57 +357,46 @@ JNIEXPORT java_util_Vector* JNICALL Java_java_lang_VMClassLoader_nativeGetResour
        if (!m)
                return NULL;
 
-       for (cpi = classpath_entries; cpi != NULL; cpi = cpi->next) {
+       for (lce = list_first(list_classpath_entries); lce != NULL;
+                lce = list_next(list_classpath_entries, lce)) {
                /* clear path pointer */
                path = NULL;
 
-#if defined(USE_ZLIB)
-               if (cpi->type == CLASSPATH_ARCHIVE) {
+#if defined(ENABLE_ZLIB)
+               if (lce->type == CLASSPATH_ARCHIVE) {
 
-#if defined(USE_THREADS)
-                       /* enter a monitor on zip/jar archives */
-
-                       builtin_monitorenter((java_objectheader *) cpi);
-#endif
-
-                       if (cacao_locate(cpi->uf, utfname) == UNZ_OK) {
-                               pathlen = strlen("jar:file://") + cpi->pathlen + strlen("!/") +
+                       if (zip_find(lce, utfname)) {
+                               pathlen = strlen("jar:file://") + lce->pathlen + strlen("!/") +
                                        namelen + strlen("0");
 
                                tmppath = MNEW(char, pathlen);
 
-                               sprintf(tmppath, "jar:file://%s!/%s", cpi->path, charname);
+                               sprintf(tmppath, "jar:file://%s!/%s", lce->path, charname);
                                path = javastring_new_char(tmppath),
 
                                MFREE(tmppath, char, pathlen);
                        }
 
-#if defined(USE_THREADS)
-                       /* leave the monitor */
-
-                       builtin_monitorexit((java_objectheader *) cpi);
-#endif
-
                } else {
-#endif /* defined(USE_ZLIB) */
-                       pathlen = strlen("file://") + cpi->pathlen + namelen + strlen("0");
+#endif /* defined(ENABLE_ZLIB) */
+                       pathlen = strlen("file://") + lce->pathlen + namelen + strlen("0");
 
                        tmppath = MNEW(char, pathlen);
 
-                       sprintf(tmppath, "file://%s%s", cpi->path, charname);
+                       sprintf(tmppath, "file://%s%s", lce->path, charname);
 
                        if (stat(tmppath + strlen("file://") - 1, &buf) == 0)
                                path = javastring_new_char(tmppath),
 
                        MFREE(tmppath, char, pathlen);
-#if defined(USE_ZLIB)
+#if defined(ENABLE_ZLIB)
                }
 #endif
 
                /* if a resource was found, add it to the vector */
 
                if (path) {
-                       ret = (jboolean) asm_calljavafunction_int(m, o, path, NULL, NULL);
+                       ASM_CALLJAVAFUNCTION_INT(ret, m, o, path, NULL, NULL);
 
                        if (!ret)
                                return NULL;