-ansi -pedantic fixes.
[cacao.git] / native.c
index 1a5badf57c6e9e246e66fc316b988710cf565bf9..22fec7c0ba72e1ad5d96df05714241eb65f726e8 100644 (file)
--- a/native.c
+++ b/native.c
@@ -31,7 +31,7 @@
    The .hh files created with the header file generator are all
    included here as are the C functions implementing these methods.
 
-   $Id: native.c 1331 2004-07-21 15:46:54Z twisti $
+   $Id: native.c 1464 2004-11-06 22:55:46Z motse $
 
 */
 
@@ -82,9 +82,6 @@
 #include "nativetable.inc"
 
 
-/* searchpath for classfiles */
-char *classpath;
-
 /* for java-string to char conversion */
 #define MAXSTRINGSIZE 1000                          
 
@@ -133,9 +130,7 @@ void use_class_as_object(classinfo *c)
 /*************************** include native methods ***************************/ 
 
 #ifdef USE_GTK 
-#include "nat/GdkGraphics.c"
 #include "nat/GtkComponentPeer.c"
-#include "nat/GdkPixbufDecoder.c"
 #include "nat/GtkScrollPanePeer.c"
 #include "nat/GtkFileDialogPeer.c"
 #endif
@@ -146,6 +141,7 @@ void use_class_as_object(classinfo *c)
 #undef JOWENN_DEBUG
 #undef JOWENN_DEBUG1
 
+#ifdef STATIC_CLASSPATH
 #define NATIVETABLESIZE  (sizeof(nativetable)/sizeof(struct nativeref))
 
 /* table for fast string comparison */
@@ -153,7 +149,7 @@ static nativecompref nativecomptable[NATIVETABLESIZE];
 
 /* string comparsion table initialized */
 static bool nativecompdone = false;
-
+#endif
 
 /******************************************************************************/
 
@@ -258,15 +254,6 @@ void init_systemclassloader()
 }
 
 
-/********************* function: native_setclasspath **************************/
-void native_setclasspath(char *path)
-{
-       /* set searchpath for classfiles */
-       classpath = path;
-}
-
-
 /*********************** Function: native_findfunction *************************
 
        Looks up a method (must have the same class name, method name, descriptor
@@ -281,6 +268,7 @@ void native_setclasspath(char *path)
 functionptr native_findfunction(utf *cname, utf *mname, 
                                                                utf *desc, bool isstatic)
 {
+#ifdef STATIC_CLASSPATH
        int i;
        /* entry of table for fast string comparison */
        struct nativecompref *n;
@@ -378,6 +366,10 @@ functionptr native_findfunction(utf *cname, utf *mname,
 
        /* keep compiler happy */
        return NULL;
+#else
+/* dynamic classpath */
+  return 0;
+#endif
 }
 
 
@@ -392,12 +384,20 @@ functionptr native_findfunction(utf *cname, utf *mname,
 
 java_lang_String *javastring_new(utf *u)
 {
-       char *utf_ptr = u->text;        /* current utf character in utf string    */
-       int utflength = utf_strlen(u);  /* length of utf-string if uncompressed   */
+       char *utf_ptr;                  /* current utf character in utf string    */
+       u4 utflength;                   /* length of utf-string if uncompressed   */
        java_lang_String *s;                /* result-string                          */
        java_chararray *a;
        s4 i;
-       
+
+       if (!u) {
+               *exceptionptr = new_nullpointerexception();
+               return NULL;
+       }
+
+       utf_ptr = u->text;
+       utflength = utf_strlen(u);
+
        s = (java_lang_String *) builtin_new(class_java_lang_String);
        a = builtin_newarray_char(utflength);
 
@@ -430,10 +430,17 @@ java_lang_String *javastring_new(utf *u)
 java_lang_String *javastring_new_char(char *text)
 {
        s4 i;
-       s4 len = strlen(text); /* length of the string */
+       s4 len;                /* length of the string */
        java_lang_String *s;   /* result-string */
        java_chararray *a;
-       
+
+       if (!text) {
+               *exceptionptr = new_nullpointerexception();
+               return NULL;
+       }
+
+       len = strlen(text);
+
        s = (java_lang_String *) builtin_new(class_java_lang_String);
        a = builtin_newarray_char(len);
 
@@ -893,7 +900,7 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
 
                        /* string already in hashtable, free memory */
                        if (!copymode)
-                               lit_mem_free(a, sizeof(java_chararray) + sizeof(u2) * (length - 1) + 10);
+                               mem_free(a, sizeof(java_chararray) + sizeof(u2) * (length - 1) + 10);
 
 #ifdef DEBUG_LITERALSTRING_U2
                        printf("literalstring_u2: foundentry at %p\n", js);
@@ -912,7 +919,7 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
     if (copymode) {
                /* create copy of u2-array for new javastring */
                u4 arraysize = sizeof(java_chararray) + sizeof(u2) * (length - 1) + 10;
-               stringdata = lit_mem_alloc(arraysize);
+               stringdata = mem_alloc(arraysize);
 /*             memcpy(stringdata, a, arraysize); */
                memcpy(&(stringdata->header), &(a->header), sizeof(java_arrayheader));
                memcpy(&(stringdata->data), &(a->data) + offset, sizeof(u2) * (length - 1) + 10);
@@ -937,7 +944,10 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
        }
 
     /* create new javastring */
-    js = LNEW(java_lang_String);
+    js = NEW(java_lang_String);
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+       initObjectLock(&js->header);
+#endif
        js->header.vftbl = class_java_lang_String->vftbl;
     js->value  = stringdata;
     js->offset = 0;
@@ -1012,7 +1022,7 @@ java_objectheader *literalstring_new(utf *u)
     u4 i;
 
     /* allocate memory */ 
-    a = lit_mem_alloc(sizeof(java_chararray) + sizeof(u2) * (utflength - 1) + 10);
+    a = mem_alloc(sizeof(java_chararray) + sizeof(u2) * (utflength - 1) + 10);
 
     /* convert utf-string to u2-array */
     for (i = 0; i < utflength; i++)
@@ -1034,10 +1044,10 @@ void literalstring_free(java_objectheader* sobj)
        java_chararray *a = s->value;
 
        /* dispose memory of java.lang.String object */
-       LFREE(s, java_lang_String);
+       FREE(s, java_lang_String);
 
        /* dispose memory of java-characterarray */
-       LFREE(a, sizeof(java_chararray) + sizeof(u2) * (a->header.size - 1)); /* +10 ?? */
+       FREE(a, sizeof(java_chararray) + sizeof(u2) * (a->header.size - 1)); /* +10 ?? */
 }