Author: mturk
Date: Fri Apr 29 12:56:13 2011
New Revision: 1097804
URL: http://svn.apache.org/viewvc?rev=1097804&view=rev
Log:
Use null check macros
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
commons/sandbox/runtime/trunk/src/main/native/shared/baos.c
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
commons/sandbox/runtime/trunk/src/main/native/shared/object.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h?rev=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h Fri
Apr 29 12:56:13 2011
@@ -24,11 +24,17 @@
#include "acr/stddefs.h"
-#define IS_JOBJECT_NULL(E, O) \
- ((O) == 0 || ((*(E))->IsSameObject((E), (O), 0) == JNI_TRUE))
+#define IS_EXCEPTION_PENDING(E) \
+ ((*E)->ExceptionCheck(E) == JNI_TRUE)
-#define IS_JOBJECT_VALID(E, O) \
- ((O) != 0 && ((*(E))->IsSameObject((E), (O), 0) == JNI_FALSE))
+#define IS_JOBJECT_NULL(O) \
+ ((O) == 0 || ((*env)->IsSameObject(env, (O), 0) == JNI_TRUE))
+
+#define IS_JOBJECT_VALID(O) \
+ ((O) != 0 && ((*env)->IsSameObject(env, (O), 0) == JNI_FALSE))
+
+#define JOBJECTS_NOTEQUAL(A, B) \
+ ((*env)->IsSameObject(env, (A), (B)) == JNI_FALSE)
#define J_LOAD_METHOD(I) \
if (_m##I##n.i == 0) { \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h?rev=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h Fri Apr
29 12:56:13 2011
@@ -81,7 +81,7 @@ extern "C" {
#endif
void
-AcrMemoryAbort(JNI_STDENV, int retcode, size_t required,
+AcrMemoryAbort(JNI_STDENV, int exclass, size_t required,
const char *filename, const char *funcname, int lineno);
void *
AcrDebugMalloc(JNI_STDENV, size_t size,
@@ -100,8 +100,8 @@ void *AcrMemdup(JNI_STDENV, const voi
char *AcrStrdup(JNI_STDENV, const char *str);
wchar_t *AcrWcsdup(JNI_STDENV, const wchar_t *str);
-void AcrFree(void *mem);
-void AcrMemCleanse(void *p, size_t len);
+void AcrFree(void *mem);
+void AcrMemCleanse(void *p, size_t len);
ACR_INLINE(int)
AcrStrlen(const char *str)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c?rev=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c Fri Apr 29
12:56:13 2011
@@ -611,7 +611,7 @@ ACR_UNX_EXPORT(jlong, PosixExec, run0)(J
rc = ACR_GET_OS_ERROR();
goto cleanup;
}
- if (envp != 0) {
+ if (IS_JOBJECT_VALID(envp)) {
envs = AcrGetJavaStringArrayA(env, envp);
if (envs == 0) {
rv = ACR_PARENT_ERROR;
@@ -619,23 +619,23 @@ ACR_UNX_EXPORT(jlong, PosixExec, run0)(J
goto cleanup;
}
}
- if (inp != 0) {
+ if (IS_JOBJECT_VALID(inp)) {
ib = &bb[0];
ib->len = (*env)->GetArrayLength(env, inp);
ib->buf = (*env)->GetPrimitiveArrayCritical(env, inp, 0);
}
- if (out != 0)
+ if (IS_JOBJECT_VALID(out))
ob = &bb[1];
- if (err != 0 && err != out)
+ if (IS_JOBJECT_VALID(err) && JOBJECTS_NOTEQUAL(err, out))
eb = &bb[2];
/* Call actual execute
*/
rv = _run_exec(J2S(executable), argp, envs, J2S(cwd),
ob, eb, ib, timeout, &rc);
- if (ib != 0 && inp != 0)
+ if (ib != 0)
(*env)->ReleasePrimitiveArrayCritical(env, inp, ib->buf, 0);
if (rv != ACR_PARENT_ERROR) {
- if (out != 0) {
+ if (ob != 0) {
/* Write to the output stream */
int r = AcrWriteToOutputStream(env, out, ob->buf, ob->len);
if (r != 0) {
@@ -643,7 +643,7 @@ ACR_UNX_EXPORT(jlong, PosixExec, run0)(J
goto cleanup;
}
}
- if (err != 0 && err != out) {
+ if (eb != 0) {
/* Write to the error stream */
int r = AcrWriteToOutputStream(env, err, eb->buf, eb->len);
if (r != 0) {
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c?rev=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c Fri Apr 29
12:56:13 2011
@@ -548,27 +548,27 @@ ACR_WIN_EXPORT(jlong, WindowsExec, run0)
WITH_WSTR(executable) {
WITH_WSTR(args) {
WITH_WSTR(cwd) {
- if (inp != 0) {
+ if (IS_JOBJECT_VALID(inp)) {
ib = &bb[0];
ib->len = (*env)->GetArrayLength(env, inp);
ib->buf = (*env)->GetPrimitiveArrayCritical(env, inp, 0);
}
- if (out != 0)
+ if (IS_JOBJECT_VALID(out))
ob = &bb[1];
- if (err != 0 && err != out)
+ if (IS_JOBJECT_VALID(err) && JOBJECTS_NOTEQUAL(err, out))
eb = &bb[2];
- if (envs != 0)
+ if (IS_JOBJECT_VALID(envs))
envb = (*env)->GetPrimitiveArrayCritical(env, envs, 0);
/* Call actual execute
*/
rv = _run_exec(J2S(executable), J2S(args), 0, J2S(cwd),
ob, eb, ib, timeout, &rc);
- if (ib != 0 && inp != 0)
+ if (ib != 0)
(*env)->ReleasePrimitiveArrayCritical(env, inp, ib->buf, 0);
- if (envs != 0)
+ if (envb != 0)
(*env)->ReleasePrimitiveArrayCritical(env, envs, envb, 0);
if (rv != ACR_PARENT_ERROR) {
- if (out != 0) {
+ if (ob != 0) {
/* Write to the output stream */
int r = AcrWriteToOutputStream(env, out, ob->buf, ob->len);
if (r != 0) {
@@ -576,7 +576,7 @@ ACR_WIN_EXPORT(jlong, WindowsExec, run0)
goto cleanup;
}
}
- if (err != 0 && err != out) {
+ if (eb != 0) {
/* Write to the error stream */
int r = AcrWriteToOutputStream(env, err, eb->buf, eb->len);
if (r != 0) {
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/baos.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/baos.c?rev=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/baos.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/baos.c Fri Apr 29
12:56:13 2011
@@ -56,7 +56,7 @@ AcrWriteToOutputStream(JNI_STDARGS, cons
if (data == 0 || len < 1)
return 0;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return ACR_EINVAL;
if (CLAZZ_LOADED) {
jbyteArray ba = (*env)->NewByteArray(env, len);
@@ -64,12 +64,13 @@ AcrWriteToOutputStream(JNI_STDARGS, cons
return ACR_ENOMEM;
(*env)->SetByteArrayRegion(env, ba, 0, len, (jbyte *)data);
CALL_VMETHOD1(0000, obj, ba);
- if ((*env)->ExceptionCheck(env)) {
+ if (IS_EXCEPTION_PENDING(env)) {
(*env)->ExceptionClear(env);
rc = ACR_ENOMEM;
}
else
rc = 0;
+ (*env)->DeleteLocalRef(env, ba);
}
return rc;
}
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=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Fri Apr 29
12:56:13 2011
@@ -351,7 +351,7 @@ int
AcrClassGetFlags(JNI_STDARGS)
{
int flags = 0;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return 0;
if (CLAZZ_LOADED) {
@@ -381,7 +381,8 @@ char *
AcrClassGetName(JNI_STDARGS, int simple)
{
char *name = 0;
- if (IS_JOBJECT_NULL(env, obj))
+
+ if (IS_JOBJECT_NULL(obj))
return 0;
if (CLAZZ_LOADED) {
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Fri Apr 29
12:56:13 2011
@@ -18,36 +18,20 @@
#include "acr/pointer.h"
#include "acr/clazz.h"
-/*
- * A function that is called when allocation fails.
- * If the handler returns 0 the program will continue.
- */
-typedef int (*_mem_abortfunc_t)(int retcode, size_t required,
- const char *filename, const char *funcname,
- int lineno);
-
-static int _default_abort_fn(int retcode, size_t required,
- const char *filename, const char *funcname,
- int lineno)
-{
- ACR_SET_OS_ERROR(retcode);
#if defined(DEBUG) || defined(_DEBUG)
- return retcode;
+# define _FATAL_MODE JNI_TRUE
#else
- return 0;
+# define _FATAL_MODE JNI_FALSE
#endif
-}
-
-static _mem_abortfunc_t _memory_abort_fn = _default_abort_fn;
+static jboolean _memory_fatal_error = _FATAL_MODE;
void
-AcrMemoryAbort(JNI_STDENV, int retcode, size_t required, const char *filename,
+AcrMemoryAbort(JNI_STDENV, int exclass, size_t required, const char *filename,
const char *funcname, int lineno)
{
- AcrDebugThrowException(env, filename, funcname, lineno, ACR_EX_ENOMEM,
retcode);
- if ((retcode = (*_memory_abort_fn)(retcode, required,
- filename, funcname, lineno))) {
- AcrFatalError(env, filename, funcname, lineno, retcode,
+ AcrDebugThrowException(env, filename, funcname, lineno, exclass, 0);
+ if (_memory_fatal_error == JNI_TRUE) {
+ AcrFatalError(env, filename, funcname, lineno, ACR_ENOMEM,
"Failed allocating %" ACR_SIZE_T_FMT " bytes", required);
}
}
@@ -71,11 +55,11 @@ AcrDebugMalloc(JNI_STDENV, size_t size,
if (size > 0 && size < SIZE_T_MAX) {
void *rv = malloc(size);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, size, filename, funcname, lineno);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, size, filename, funcname,
lineno);
return rv;
}
else {
- AcrMemoryAbort(env, ACR_ERANGE, size, filename, funcname, lineno);
+ AcrMemoryAbort(env,ACR_EX_ERANGE, size, filename, funcname, lineno);
return 0;
}
}
@@ -87,11 +71,11 @@ AcrDebugCalloc(JNI_STDENV, size_t size,
if (size > 0 && size < SIZE_T_MAX) {
void *rv = calloc(1, size);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, size, filename, funcname, lineno);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, size, filename, funcname,
lineno);
return rv;
}
else {
- AcrMemoryAbort(env, ACR_ERANGE, size, filename, funcname, lineno);
+ AcrMemoryAbort(env, ACR_EX_ERANGE, size, filename, funcname, lineno);
return 0;
}
}
@@ -107,13 +91,13 @@ AcrDebugRealloc(JNI_STDENV, void *ptr, s
else if (size > 0 && size < SIZE_T_MAX) {
void *rv = realloc(ptr, size);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, size, filename, funcname, lineno);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, size, filename, funcname,
lineno);
return rv;
}
else if (size == 0)
AcrFree(ptr);
else
- AcrMemoryAbort(env, ACR_ERANGE, size, filename, funcname, lineno);
+ AcrMemoryAbort(env, ACR_EX_ERANGE, size, filename, funcname, lineno);
return 0;
}
@@ -123,11 +107,11 @@ AcrMalloc(JNI_STDENV, size_t size)
if (size > 0 && size < SIZE_T_MAX) {
void *rv = malloc(size);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, size, 0, 0, 0);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, size, 0, 0, 0);
return rv;
}
else {
- AcrMemoryAbort(env, ACR_ERANGE, size, 0, 0, 0);
+ AcrMemoryAbort(env, ACR_EX_ERANGE, size, 0, 0, 0);
return 0;
}
}
@@ -138,11 +122,11 @@ AcrCalloc(JNI_STDENV, size_t size)
if (size > 0 && size < SIZE_T_MAX) {
void *rv = calloc(1, size);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, size, 0, 0, 0);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, size, 0, 0, 0);
return rv;
}
else {
- AcrMemoryAbort(env, ACR_ERANGE, size, 0, 0, 0);
+ AcrMemoryAbort(env,ACR_EX_ERANGE, size, 0, 0, 0);
return 0;
}
}
@@ -157,13 +141,13 @@ AcrRealloc(JNI_STDENV, void *ptr, size_t
else if (size > 0 && size < SIZE_T_MAX) {
void *rv = realloc(ptr, size);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, size, 0, 0, 0);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, size, 0, 0, 0);
return rv;
}
else if (size == 0)
AcrFree(ptr);
else
- AcrMemoryAbort(env, ACR_ERANGE, size, 0, 0, 0);
+ AcrMemoryAbort(env, ACR_EX_ERANGE, size, 0, 0, 0);
return 0;
}
@@ -198,7 +182,7 @@ AcrMemdup(JNI_STDENV, const void *src, i
return acr_zero_string_ptr;
rv = malloc(len);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, len, 0, 0, 0);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, len, 0, 0, 0);
else
memcpy(rv, src, len);
return rv;
@@ -215,7 +199,7 @@ AcrStrdup(JNI_STDENV, const char *str)
else
rv = strdup(str);
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, strlen(str), 0, 0, 0);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, strlen(str), 0, 0, 0);
return rv;
}
@@ -238,7 +222,7 @@ AcrWcsdup(JNI_STDENV, const wchar_t *str
#endif
}
if (rv == 0)
- AcrMemoryAbort(env, ACR_ENOMEM, wcslen(str) * sizeof(wchar_t), 0, 0,
0);
+ AcrMemoryAbort(env, ACR_EX_ENOMEM, wcslen(str) * sizeof(wchar_t), 0,
0, 0);
return rv;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/object.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/object.c?rev=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Fri Apr 29
12:56:13 2011
@@ -103,7 +103,7 @@ AcrObjectNotify(JNI_STDARGS)
{
int rc = ACR_ENOENT;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return ACR_EINVAL;
if (CLAZZ_LOADED) {
CALL_VMETHOD0(0001, obj);
@@ -122,7 +122,7 @@ AcrObjectNotifyAll(JNI_STDARGS)
{
int rc = ACR_ENOENT;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return ACR_EINVAL;
if (CLAZZ_LOADED) {
CALL_VMETHOD0(0002, obj);
@@ -141,7 +141,7 @@ AcrObjectWait0(JNI_STDARGS)
{
int rc = ACR_ENOENT;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return ACR_EINVAL;
if (CLAZZ_LOADED) {
CALL_VMETHOD0(0005, obj);
@@ -160,7 +160,7 @@ AcrObjectWait1(JNI_STDARGS, jlong ms)
{
int rc = ACR_ENOENT;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return ACR_EINVAL;
if (CLAZZ_LOADED) {
CALL_VMETHOD1(0003, obj, ms);
@@ -179,7 +179,7 @@ AcrObjectWait2(JNI_STDARGS, jlong ms, ji
{
int rc = ACR_ENOENT;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return ACR_EINVAL;
if (CLAZZ_LOADED) {
CALL_VMETHOD2(0004, obj, ms, ns);
@@ -196,7 +196,7 @@ AcrObjectWait2(JNI_STDARGS, jlong ms, ji
void
AcrObjectFinalize(JNI_STDARGS)
{
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return;
if (CLAZZ_LOADED) {
CALL_VMETHOD0(0006, obj);
@@ -209,7 +209,7 @@ AcrGetObjectMethod(JNI_STDARGS, const ch
jmethodID id;
jclass clazz;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return 0;
clazz = (*env)->GetObjectClass(env, obj);
if (!clazz)
@@ -226,7 +226,7 @@ AcrGetObjectClass(JNI_STDARGS)
{
jobject c = 0;
- if (IS_JOBJECT_NULL(env, obj))
+ if (IS_JOBJECT_NULL(obj))
return c;
if (CLAZZ_LOADED) {
c = CALL_METHOD0(Object, 0007, obj);
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=1097804&r1=1097803&r2=1097804&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Fri Apr 29
12:56:13 2011
@@ -926,7 +926,7 @@ AcrGetJavaStringW(JNIEnv *env, jstring s
const jchar *sr;
wchar_t *rv = 0;
- if (str == 0) {
+ if (IS_JOBJECT_NULL(str)) {
return 0;
}
sl = (*env)->GetStringLength(env, str);
@@ -969,7 +969,7 @@ AcrGetJavaStringA(JNIEnv *env, jstring s
{
char *rv = 0;
- if (str == 0) {
+ if (IS_JOBJECT_NULL(str)) {
return 0;
}
switch (acr_native_codepage) {
@@ -989,7 +989,7 @@ AcrGetJavaStringA(JNIEnv *env, jstring s
char *
AcrGetJavaStringU(JNIEnv *env, jstring str, char *b)
{
- if (str == 0)
+ if (IS_JOBJECT_NULL(str))
return 0;
else
return get_string_utf_8(env, str, b);
@@ -1083,7 +1083,7 @@ AcrGetJavaStringArrayA(JNI_STDENV, jobje
jsize cnt;
jsize i;
- if (arr == 0)
+ if (IS_JOBJECT_NULL(arr))
return 0;
cnt = (*env)->GetArrayLength(env, arr);
@@ -1110,7 +1110,7 @@ AcrGetJavaStringArrayW(JNI_STDENV, jobje
jsize cnt;
jsize i;
- if (arr == 0)
+ if (IS_JOBJECT_NULL(arr))
return 0;
cnt = (*env)->GetArrayLength(env, arr);
@@ -1133,7 +1133,7 @@ AcrGetJavaStringArrayW(JNI_STDENV, jobje
ACR_UTIL_EXPORT(jcharArray, Array, get)(JNI_STDARGS,
jstring str)
{
- if (str != 0)
+ if (IS_JOBJECT_VALID(str))
return GET_IFIELD_O(0000, str);
else
return 0;