You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/05/05 08:58:27 UTC
svn commit: r771592 - in /commons/sandbox/runtime/trunk/src/main/native:
include/acr_private.h shared/clazz.c shared/descriptor.c shared/error.c
shared/pointer.c shared/string.c test/testcase.c
Author: mturk
Date: Tue May 5 06:58:27 2009
New Revision: 771592
URL: http://svn.apache.org/viewvc?rev=771592&view=rev
Log:
Various cleanups
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=771592&r1=771591&r2=771592&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Tue May 5 06:58:27 2009
@@ -301,7 +301,7 @@
_m##I##n.i = (*_E)->GetMethodID(_E, _clazzn.i, _m##I##n.n, \
_m##I##n.s); \
if ((*_E)->ExceptionCheck(_E) || _m##I##n.i == NULL) { \
- return 1; \
+ return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
@@ -310,7 +310,7 @@
_m##I##n.i = (*_E)->GetStaticMethodID(_E, _clazzn.i, _m##I##n.n, \
_m##I##n.s); \
if ((*_E)->ExceptionCheck(_E) || _m##I##.i == NULL) { \
- return 1; \
+ return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
@@ -319,7 +319,7 @@
_f##I##n.i = (*_E)->GetFieldID(_E, _clazzn.i, _f##I##n.n, \
_f##I##n.s); \
if ((*_E)->ExceptionCheck(_E) || _f##I##n.i == NULL) { \
- return 1; \
+ return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
@@ -328,7 +328,7 @@
_f##I##n.i = (*_E)->GetStaticFieldID(_E, _clazzn.i, _f##I##n.n, \
_f##I##n.s); \
if ((*_E)->ExceptionCheck(_E) || _f##I##n.i == NULL) { \
- return 1; \
+ return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=771592&r1=771591&r2=771592&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Tue May 5 06:58:27 2009
@@ -32,10 +32,10 @@
const char *name;
jclass clazz;
} core_classes[] = {
- { "Ljava/lang/Object;", NULL },
- { "Ljava/lang/String;", NULL },
- { "Ljava/nio/ByteBuffer;", NULL },
- { "Ljava/io/File;", NULL },
+ { "java/lang/Object", NULL },
+ { "java/lang/String", NULL },
+ { "java/nio/ByteBuffer", NULL },
+ { "java/io/File", NULL },
{ "[Z", NULL },
{ "[B", NULL },
{ "[C", NULL },
@@ -181,12 +181,11 @@
ACR_DECLARE(int) ACR_LoadClass(JNIEnv *_E, JAVA_C_ID *clazz, int init_array)
{
- int rv = ACR_SUCCESS;
jobject c;
if (clazz->i != NULL) {
/* Already inited */
- return rv;
+ return ACR_SUCCESS;
}
if ((*_E)->EnsureLocalCapacity(_E, 3) < 0) {
goto failed;
@@ -200,8 +199,7 @@
goto failed;
}
clazz->i = (jclass)(*_E)->NewGlobalRef(_E, c);
- if ((*_E)->ExceptionCheck(_E) || clazz->i == NULL) {
- clazz->i = NULL;
+ if (clazz->i == NULL) {
goto failed;
}
(*_E)->DeleteLocalRef(_E, c);
@@ -209,14 +207,13 @@
if (init_array) {
char an[ACR_SBUFF_SIZ];
/* Init class array */
- sprintf(an, "[L%s;", clazz->n);
+ snprintf(an, ACR_SBUFF_SIZ, "[L%s;", clazz->n);
c = (jobject)(*_E)->FindClass(_E, an);
if (c == NULL) {
goto failed;
}
clazz->a = (jclass)(*_E)->NewGlobalRef(_E, c);
- if ((*_E)->ExceptionCheck(_E) || clazz->a == NULL) {
- clazz->a = NULL;
+ if (clazz->a == NULL) {
goto failed;
}
}
@@ -224,14 +221,14 @@
/* We don't need Objec[][] arrays */
clazz->a = NULL;
}
- return rv;
+ return ACR_SUCCESS;
failed:
if (clazz->i != NULL) {
(*_E)->DeleteGlobalRef(_E, clazz->i);
clazz->i = NULL;
}
- return ACR_EGENERAL;
+ return ACR_ECLASSNOTFOUND;
}
ACR_DECLARE(void) ACR_UnloadClass(JNIEnv *_E, JAVA_C_ID *clazz)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=771592&r1=771591&r2=771592&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Tue May 5 06:58:27 2009
@@ -290,11 +290,6 @@
return ACR_ENOLOCK;
}
SET_IFIELD_P(0001, _O, p);
-#ifdef _JNI_CHECK_EXCEPTIONS
- if ((*_E)->ExceptionCheck(_E)) {
- return ACR_EGENERAL;
- }
-#endif
(*_E)->MonitorExit(_E, _O);
return ACR_SUCCESS;
}
@@ -311,11 +306,6 @@
return ACR_ENOLOCK;
}
SET_IFIELD_I(0000, _O, i);
-#ifdef _JNI_CHECK_EXCEPTIONS
- if ((*_E)->ExceptionCheck(_E)) {
- return ACR_EGENERAL;
- }
-#endif
(*_E)->MonitorExit(_E, _O);
return ACR_SUCCESS;
}
@@ -328,11 +318,6 @@
{
if (_clazzn.i && J4MID(0000)) {
SET_IFIELD_I(0003, _O, e);
-#ifdef _JNI_CHECK_EXCEPTIONS
- if ((*_E)->ExceptionCheck(_E)) {
- return ACR_EGENERAL;
- }
-#endif
return ACR_SUCCESS;
}
else {
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=771592&r1=771591&r2=771592&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Tue May 5 06:58:27 2009
@@ -56,22 +56,35 @@
if (!env)
env = ACR_GetJNIEnv();
if (!env) {
- fprintf(stderr, "[ERROR] Cannot allocate JNI Environment\n");
+#ifdef ACR_ENABLE_TEST
+ fprintf(stderr, "[ERROR] Cannot allocate JNI Environment\n");
+ if (msg)
+ fprintf(stderr, "[ERROR] %s\n", msg);
+ fflush(stderr);
+#endif
+ return;
+ }
+ if ((*env)->ExceptionCheck(env)) {
+ /* We already have a pending exception. */
+#ifdef ACR_ENABLE_TEST
+ fprintf(stderr, "[INFO] Exception is already in the queue.\n");
+ fprintf(stderr, "[INFO] Class '%s' was not thrown.\n", clazz);
if (msg)
- fprintf(stderr, " %s\n", msg);
+ fprintf(stderr, "[INFO] %s\n", msg);
fflush(stderr);
+#endif
return;
}
ec = (*env)->FindClass(env, clazz);
- if (IS_JOBJECT_NULL(env, ec)) {
+ if (ec == NULL) {
/* If the class cannot be found,
* the Exception has already been thrown.
* See JNI Find Class for the Exceptions thrown.
*/
#ifdef ACR_ENABLE_TEST
- fprintf(stderr, "[ERROR] Cannot find class '%s'\n", clazz);
+ fprintf(stderr, "[ERROR] Cannot find class '%s'\n", clazz);
if (msg)
- fprintf(stderr, " %s\n", msg);
+ fprintf(stderr, "[ERROR] %s\n", msg);
fflush(stderr);
#endif
return;
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=771592&r1=771591&r2=771592&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Tue May 5 06:58:27 2009
@@ -267,18 +267,8 @@
}
SET_IFIELD_P(0000, _O, p);
-#ifdef _JNI_CHECK_EXCEPTIONS
- if ((*_E)->ExceptionCheck(_E)) {
- return ACR_EGENERAL;
- }
-#endif
if (len) {
SET_IFIELD_P(0002, _O, len);
-#ifdef _JNI_CHECK_EXCEPTIONS
- if ((*_E)->ExceptionCheck(_E)) {
- return ACR_EGENERAL;
- }
-#endif
}
(*_E)->MonitorExit(_E, _O);
return ACR_SUCCESS;
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=771592&r1=771591&r2=771592&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Tue May 5 06:58:27 2009
@@ -311,7 +311,6 @@
ACR_DECLARE(char *) ACR_GetJavaStringA(JNIEnv *_E, jstring str)
{
jbyteArray sb = NULL;
- jthrowable ee;
char *rs = NULL;
if (!str) {
@@ -322,8 +321,9 @@
return NULL;
}
sb = CALL_METHOD0(Object, 0001, str);
- ee = (*_E)->ExceptionOccurred(_E);
- if (!ee) {
+ if ((*_E)->ExceptionCheck(_E))
+ return NULL;
+ else {
jint len = (*_E)->GetArrayLength(_E, sb);
rs = (char *)ACR_Malloc(_E, THROW_FMARK, len + 1);
if (rs == NULL) {
@@ -333,11 +333,7 @@
(*_E)->GetByteArrayRegion(_E, sb, 0, len, (jbyte *)rs);
rs[len] = '\0'; /* NUL-terminate */
}
- else {
- (*_E)->DeleteLocalRef(_E, ee);
- }
(*_E)->DeleteLocalRef(_E, sb);
-
return rs;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=771592&r1=771591&r2=771592&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Tue May 5 06:58:27 2009
@@ -45,6 +45,8 @@
ACR_JNI_EXPORT_DECLARE(void, TestPrivate, test002)(ACR_JNISTDARGS, jint err)
{
ACR_ThrowException(NULL, THROW_FMARK, ACR_EX_ENOMEM, err);
+ /* This will display an [INFO] in console */
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL, err);
}
ACR_JNI_EXPORT_DECLARE(void, TestPrivate, test003)(ACR_JNISTDARGS, jint d)