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/09/04 10:15:18 UTC
svn commit: r811255 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/ main/native/ main/native/include/
main/native/shared/ test/org/apache/commons/runtime/
Author: mturk
Date: Fri Sep 4 08:15:17 2009
New Revision: 811255
URL: http://svn.apache.org/viewvc?rev=811255&view=rev
Log:
Limit the SEH code to DEBUG mode
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
commons/sandbox/runtime/trunk/src/main/native/configure
commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
commons/sandbox/runtime/trunk/src/main/native/shared/native.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java?rev=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java Fri Sep 4 08:15:17 2009
@@ -35,8 +35,12 @@
private static boolean initialized = false;
private static native boolean init0()
throws Throwable;
- private static native boolean sseh0();
- private static native boolean sseh1(boolean on);
+ private static native boolean isdbg0();
+
+ /**
+ * True if the native code compiled with debugging support.
+ */
+ public static final boolean HAS_MAINTAINER_MODE = isdbg0();
/**
* Initialize Apache Commons Runtime native library.
@@ -67,21 +71,4 @@
}
return initialized;
}
-
- public static boolean isExceptionHandlerEnabled()
- {
- return sseh0();
- }
-
- public static boolean enableExceptionHandler()
- {
- return sseh1(true);
- }
-
- public static boolean disableExceptionHandler()
- {
- sseh1(false);
- // Disable is always success.
- return true;
- }
}
Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Fri Sep 4 08:15:17 2009
@@ -86,7 +86,6 @@
has_jni=yes
has_64_bit=no
has_test=no
-has_memprotect=no
has_maintainer_mode=no
has_native_threads=no
has_sysv_mutex=no
@@ -539,9 +538,6 @@
else
varadds cppopts -DNDEBUG
fi
-if [ ".$has_memprotect" = .yes ]; then
- varadds cppopts -DACR_ENABLE_SEH
-fi
if [ ".$has_sysv_mutex" = .yes ]; then
varadds cppopts -DACR_USE_SYSV_MUTEX
fi
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Fri Sep 4 08:15:17 2009
@@ -61,24 +61,10 @@
ACR_EX_LEN
} acr_trowclass_e;
-typedef enum {
- ACR_SEH_NONE = 0,
- ACR_SEH_CONTINUE,
- ACR_SEH_THROW
-} acr_seh_e;
-
-#if defined(ACR_WANT_MEMPROTECT) && defined(ACR_ENABLE_SEH)
-extern acr_seh_e __acr_seh_mode;
+#if defined(ACR_WANT_MEMPROTECT) && defined(DEBUG)
#ifdef _MSC_VER
-static int _seh_error = 0;
-#define ACR_TRY \
- if (__acr_seh_mode != ACR_SEH_NONE) \
- _seh_error = 1; \
- __try
-
-#define ACR_CATCH() \
- __except(_seh_error ? EXCEPTION_EXECUTE_HANDLER : \
- EXCEPTION_CONTINUE_SEARCH)
+#define ACR_TRY __try
+#define ACR_CATCH() __except(EXCEPTION_EXECUTE_HANDLER)
#else
#include <signal.h>
@@ -104,23 +90,16 @@
#define ACR_TRY \
int _seh_error = 0; \
{ \
- void* _org_sigseg_handler = NULL; \
- void* _org_sigbus_handler = NULL; \
- int _org_setjmp_handler = 0; \
- if (__acr_seh_mode != ACR_SEH_NONE) { \
- _org_sigseg_handler = signal(SIGSEGV, _seh_handler); \
- _org_sigbus_handler = signal(SIGBUS, _seh_handler); \
- _org_setjmp_handler = 1; \
- if ((_seh_error = SEH_SETJMP(_seh_catch))) \
- goto _seh_catch_block; \
- }
+ void* _org_sigseg_handler = signal(SIGSEGV, _seh_handler); \
+ void* _org_sigbus_handler = signal(SIGBUS, _seh_handler); \
+ if ((_seh_error = SEH_SETJMP(_seh_catch))) \
+ goto _seh_catch_block;
#define ACR_CATCH() \
_seh_catch_block: \
- if (_org_setjmp_handler) { \
- signal(SIGSEGV, _org_sigseg_handler); \
- signal(SIGBUS, _org_sigbus_handler); \
- } } if (_seh_error)
+ signal(SIGSEGV, _org_sigseg_handler); \
+ signal(SIGBUS, _org_sigbus_handler); \
+ } if (_seh_error)
#endif
#else
@@ -220,18 +199,6 @@
ACR_DECLARE(char *) ACR_GetErrorString(int statcode, char *buf,
acr_size_t bufsize);
-/**
- * Set internal memory protection exception handling mode.
- * @param mode Exception handling mode.
- */
-ACR_DECLARE(void) ACR_SetExceptionHandlerMode(acr_seh_e mode);
-
-/**
- * Get the exception handling mode.
- * @return Previously set exception handling mode.
- */
-ACR_DECLARE(acr_seh_e) ACR_GetExceptionHandlerMode(void);
-
#if defined(DOXYGEN)
/**
* @def ACR_FROM_OS_ERROR(os_err_type syserr)
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=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Sep 4 08:15:17 2009
@@ -47,16 +47,6 @@
NULL
};
-/**
- * SEH is basically usable only on Windows.
- * On other platforms default to disabled.
- */
-#if defined(ACR_ENABLE_SEH) && defined(_MSC_VER)
-acr_seh_e __acr_seh_mode = ACR_SEH_THROW;
-#else
-acr_seh_e __acr_seh_mode = ACR_SEH_NONE;
-#endif
-
/*
* Convenience function to help throw any class
*/
@@ -699,16 +689,6 @@
}
}
-ACR_DECLARE(void) ACR_SetExceptionHandlerMode(acr_seh_e mode)
-{
- __acr_seh_mode = mode;
-}
-
-ACR_DECLARE(acr_seh_e) ACR_GetExceptionHandlerMode()
-{
- return __acr_seh_mode;
-}
-
ACR_JNI_EXPORT_DECLARE(void, io_Status, init0)(ACR_JNISTDARGS,
jintArray ra)
{
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=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Fri Sep 4 08:15:17 2009
@@ -295,8 +295,8 @@
ptr++;
len++;
#if defined (DEBUG)
- if (len > (SIZE_T_MAX / 2)) {
- /* This is probably ubterminated array
+ if (len > (INT_MAX / 2)) {
+ /* This is probably unterminated array
*/
return 0;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/native.c?rev=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Fri Sep 4 08:15:17 2009
@@ -35,22 +35,9 @@
return rv;
}
-ACR_JNI_EXPORT_DECLARE(jboolean, Native, sseh0)(ACR_JNISTDARGS)
+ACR_JNI_EXPORT_DECLARE(jboolean, Native, isdbg0)(ACR_JNISTDARGS)
{
-#ifdef ACR_ENABLE_SEH
- if (ACR_GetExceptionHandlerMode() != ACR_SEH_NONE)
- return JNI_TRUE;
- else
- return JNI_FALSE;
-#else
- return JNI_FALSE;
-#endif
-}
-
-ACR_JNI_EXPORT_DECLARE(jboolean, Native, sseh1)(ACR_JNISTDARGS, jboolean on)
-{
-#ifdef ACR_ENABLE_SEH
- ACR_SetExceptionHandlerMode(on ? ACR_SEH_THROW : ACR_SEH_NONE);
+#if defined(DEBUG)
return JNI_TRUE;
#else
return JNI_FALSE;
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java?rev=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java Fri Sep 4 08:15:17 2009
@@ -86,7 +86,7 @@
assertTrue("Direct", bb.isDirect());
assertEquals("Capacity", 1000, bb.capacity());
try {
- boolean test_me = Native.enableExceptionHandler();
+ boolean test_me = Native.HAS_MAINTAINER_MODE;
ptr.free();
// This is double free. Don't do this!
// Exception handler won't help here.
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=811255&r1=811254&r2=811255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Fri Sep 4 08:15:17 2009
@@ -904,7 +904,7 @@
public void testMempotect()
throws Throwable
{
- if (Native.enableExceptionHandler()) {
+ if (Native.HAS_MAINTAINER_MODE) {
try {
test030(0);
fail("Exception not thrown");