Merged with tip.
[cacao.git] / src / vm / string.c
index 98063bb62ddd2c69e5b1954697a6bb7da1bf047c..74400828214dddca58a96e3403a2af24e4842b42 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/string.c - java.lang.String related functions
 
-   Copyright (C) 1996-2005, 2006, 2007 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, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
@@ -29,6 +27,8 @@
 
 #include <assert.h>
 
+#include "vmcore/system.h"
+
 #include "vm/types.h"
 
 #include "vm/global.h"
@@ -45,7 +45,7 @@
 #include "vm/array.h"
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
-#include "vm/primitive.h"
+#include "vm/primitive.hpp"
 #include "vm/stringlocal.h"
 #include "vm/vm.h"
 
@@ -85,6 +85,8 @@ typedef java_lang_String heapstring_t;
 
 bool string_init(void)
 {
+       TRACESUBSYSTEMINITIALIZATION("string_init");
+
        /* create string (javastring) hashtable */
 
        hashtable_create(&hashtable_string, HASHTABLE_STRING_SIZE);
@@ -139,7 +141,7 @@ void stringtable_update(void)
                                if (!a->header.objheader.vftbl) 
                                        /* vftbl of character-array is NULL */ 
                                        a->header.objheader.vftbl =
-                                               primitive_arrayclass_get_by_type(ARRAYTYPE_CHAR)->vftbl;
+                                               Primitive_get_arrayclass_by_type(ARRAYTYPE_CHAR)->vftbl;
 
                                /* follow link in external hash chain */
                                s = s->hashlink;
@@ -228,7 +230,8 @@ java_handle_t *javastring_safe_new_from_utf8(const char *text)
        s4 nbytes;
        s4 len;
 
-       assert(text);
+       if (text == NULL)
+               return NULL;
 
        /* Get number of bytes. We need this to completely emulate the messy */
        /* behaviour of the RI. :(                                           */
@@ -586,7 +589,7 @@ static java_object_t *literalstring_u2(java_chararray_t *a, u4 length,
     /* location in hashtable found, complete arrayheader */
 
     ca->header.objheader.vftbl =
-               primitive_arrayclass_get_by_type(ARRAYTYPE_CHAR)->vftbl;
+               Primitive_get_arrayclass_by_type(ARRAYTYPE_CHAR)->vftbl;
     ca->header.size            = length;
 
        assert(class_java_lang_String);
@@ -709,6 +712,9 @@ java_object_t *literalstring_new(utf *u)
 
 *******************************************************************************/
 
+#if 0
+/* TWISTI This one is currently not used. */
+
 static void literalstring_free(java_object_t* string)
 {
        heapstring_t     *s;
@@ -723,6 +729,7 @@ static void literalstring_free(java_object_t* string)
        /* dispose memory of java-characterarray */
        FREE(a, sizeof(java_chararray_t) + sizeof(u2) * (a->header.size - 1)); /* +10 ?? */
 }
+#endif
 
 
 /* javastring_intern ***********************************************************
@@ -755,13 +762,13 @@ java_handle_t *javastring_intern(java_handle_t *s)
 }
 
 
-/* javastring_print ************************************************************
+/* javastring_fprint ***********************************************************
 
-   Print the given Java string.
+   Print the given Java string to the given stream.
 
 *******************************************************************************/
 
-void javastring_print(java_handle_t *s)
+void javastring_fprint(java_handle_t *s, FILE *stream)
 {
        java_lang_String        *so;
        java_handle_chararray_t *value;
@@ -778,7 +785,7 @@ void javastring_print(java_handle_t *s)
 
        for (i = offset; i < offset + count; i++) {
                c = LLNI_array_direct(value, i);
-               putchar(c);
+               fputc(c, stream);
        }
 }