author | prr |
Fri, 10 May 2019 16:22:35 -0700 | |
changeset 54877 | dde07ac16610 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22266
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <stdlib.h> |
|
27 |
#include <jni.h> |
|
22275
de7efc0bb1a5
8031708: Windows x86 build failure: JNU_ThrowOutOfMemoryError undefined
chegar
parents:
22266
diff
changeset
|
28 |
#include <jni_util.h> |
2 | 29 |
#include <stdio.h> |
30 |
#include <jvm.h> |
|
31 |
||
34885 | 32 |
#include "java_lang_StringCoding.h" |
2 | 33 |
|
34 |
static void |
|
35 |
printToFile(JNIEnv *env, jstring s, FILE *file) |
|
36 |
{ |
|
37 |
char *sConverted; |
|
22266
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
38 |
int length = 0; |
2 | 39 |
int i; |
40 |
const jchar *sAsArray; |
|
41 |
||
3060 | 42 |
if (s == NULL) { |
34885 | 43 |
JNU_ThrowNullPointerException(env, NULL); |
44 |
return; |
|
3060 | 45 |
} |
46 |
||
2 | 47 |
sAsArray = (*env)->GetStringChars(env, s, NULL); |
22266
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
48 |
if (!sAsArray) |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
49 |
return; |
2 | 50 |
length = (*env)->GetStringLength(env, s); |
22266
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
51 |
if (length == 0) { |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
52 |
(*env)->ReleaseStringChars(env, s, sAsArray); |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
53 |
return; |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
54 |
} |
2 | 55 |
sConverted = (char *) malloc(length + 1); |
22266
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
56 |
if (!sConverted) { |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
57 |
(*env)->ReleaseStringChars(env, s, sAsArray); |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
58 |
JNU_ThrowOutOfMemoryError(env, NULL); |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
59 |
return; |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
60 |
} |
d70900404b67
8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents:
5506
diff
changeset
|
61 |
|
2 | 62 |
for(i = 0; i < length; i++) { |
63 |
sConverted[i] = (0x7f & sAsArray[i]); |
|
64 |
} |
|
65 |
sConverted[length] = '\0'; |
|
66 |
jio_fprintf(file, "%s", sConverted); |
|
67 |
(*env)->ReleaseStringChars(env, s, sAsArray); |
|
68 |
free(sConverted); |
|
69 |
} |
|
70 |
||
71 |
JNIEXPORT void JNICALL |
|
34885 | 72 |
Java_java_lang_StringCoding_err(JNIEnv *env, jclass cls, jstring s) |
2 | 73 |
{ |
74 |
printToFile(env, s, stderr); |
|
75 |
} |