* src/vm/signal.c (signal_thread): Restart sigwait if it has been
[cacao.git] / src / native / vm / gnuclasspath / gnu_java_lang_VMCPStringBuilder.cpp
1 /* src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp
2
3    Copyright (C) 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdint.h>
29
30 #include "native/jni.h"
31 #include "native/llni.h"
32 #include "native/native.h"
33
34 #include "native/include/java_lang_String.h"
35
36 // FIXME
37 extern "C" {
38 #include "native/include/gnu_java_lang_VMCPStringBuilder.h"
39 }
40
41 #include "vm/builtin.h"
42 #include "vm/exceptions.hpp"
43
44 #include "vmcore/globals.hpp"
45
46
47 /*
48  * Class:     gnu/java/lang/VMCPStringBuilder
49  * Method:    toString
50  * Signature: ([CII)Ljava/lang/String;
51  */
52 JNIEXPORT java_lang_String* JNICALL Java_gnu_java_lang_VMCPStringBuilder_toString(JNIEnv *env, jclass clazz, java_handle_chararray_t *value, int32_t startIndex, int32_t count)
53 {
54         int32_t          length;
55         java_handle_t    *o;
56         java_lang_String *s;
57
58         /* This is a native version of
59            java.lang.String.<init>([CIIZ)Ljava/lang/String; */
60
61     if (startIndex < 0) {
62 /*              exceptions_throw_stringindexoutofboundsexception("offset: " + offset); */
63                 exceptions_throw_stringindexoutofboundsexception();
64                 return NULL;
65         }
66
67     if (count < 0) {
68 /*              exceptions_throw_stringindexoutofboundsexception("count: " + count); */
69                 exceptions_throw_stringindexoutofboundsexception();
70                 return NULL;
71         }
72
73     /* equivalent to: offset + count < 0 || offset + count > data.length */
74
75         LLNI_CRITICAL_START;
76         length = LLNI_array_size(value);
77         LLNI_CRITICAL_END;
78
79     if (length - startIndex < count) {
80 /*              exceptions_throw_stringindexoutofboundsexception("offset + count: " + (offset + count)); */
81                 exceptions_throw_stringindexoutofboundsexception();
82                 return NULL;
83         }
84
85         o = builtin_new(class_java_lang_String);
86
87         if (o == NULL)
88                 return NULL;
89
90         s = (java_lang_String *) o;
91
92         LLNI_field_set_ref(s, value,  value);
93         LLNI_field_set_val(s, count,  count);
94         LLNI_field_set_val(s, offset, startIndex);
95
96         return s;
97 }
98
99
100 /* native methods implemented by this file ************************************/
101
102 static JNINativeMethod methods[] = {
103         { (char*) "toString", (char*) "([CII)Ljava/lang/String;", (void*) (uintptr_t) &Java_gnu_java_lang_VMCPStringBuilder_toString },
104 };
105
106
107 /* _Jv_gnu_java_lang_VMCPStringBuilder *****************************************
108
109    Register native functions.
110
111 *******************************************************************************/
112
113 // FIXME
114 extern "C" {
115 void _Jv_gnu_java_lang_VMCPStringBuilder_init(void)
116 {
117         utf *u;
118
119         u = utf_new_char("gnu/java/lang/VMCPStringBuilder");
120
121         native_method_register(u, methods, NATIVE_METHODS_COUNT);
122 }
123 }
124
125
126 /*
127  * These are local overrides for various environment variables in Emacs.
128  * Please do not remove this and leave it at the end of the file, where
129  * Emacs will automagically detect them.
130  * ---------------------------------------------------------------------
131  * Local variables:
132  * mode: c++
133  * indent-tabs-mode: t
134  * c-basic-offset: 4
135  * tab-width: 4
136  * End:
137  */