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/04/20 09:30:22 UTC
svn commit: r766604 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/
main/java/org/apache/commons/runtime/io/ main/native/ main/native/include/
main/native/os/darwin/ main/native/os/hpux/ main/native/os/solaris/
main/nativ...
Author: mturk
Date: Mon Apr 20 07:30:22 2009
New Revision: 766604
URL: http://svn.apache.org/viewvc?rev=766604&view=rev
Log:
Get rid of some macros and use Tomcat Native platform strings instead UTF-8
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
commons/sandbox/runtime/trunk/src/main/native/configure
commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
commons/sandbox/runtime/trunk/src/main/native/shared/version.c
commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java Mon Apr 20 07:30:22 2009
@@ -110,7 +110,7 @@
* Compares this {@code Descriptor} to the specified object.
*
* @param other a {@code Descriptor}
- * @return true if the class of this {@code Descriptor}} object and the
+ * @return true if the class of this {@code Descriptor} object and the
* class of {@code other} are exactly equal, and the C/C++
* descriptors being pointed to by these objects are also
* equal. Returns false otherwise.
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Mon Apr 20 07:30:22 2009
@@ -144,6 +144,13 @@
* Returns the {@link FileType} of the file denoted by this abstract
* pathname.
*
+ * <p>
+ * This method first checks if the pathname this {@code File} points to
+ * is symbolic link or not. This means that it will always return the
+ * {@link FileType#LNK} for any symbolic link regardless of the type
+ * the link itself points to.
+ * </p>
+ *
* @return {@link FileType} representing the type of the file.
* @throws IOException If an I/O error occured.
* @see FileType
Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Mon Apr 20 07:30:22 2009
@@ -504,7 +504,7 @@
#define HAVE_LIMITS_H `have_include limits`
#define HAVE_CTYPE_H `have_include ctype`
#define HAVE_WCHAR_H `have_include wchar`
-#define HAVE_WTYPE_H `have_include wctype`
+#define HAVE_WCTYPE_H `have_include wctype`
#define HAVE_AIO_H `have_include aio`
#define HAVE_NETDB_H `have_include netdb`
#define HAVE_NETINET_IN_H `have_include netinet/in`
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=766604&r1=766603&r2=766604&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 Mon Apr 20 07:30:22 2009
@@ -72,66 +72,49 @@
#define ACR_GB (ACR_MB * ACR_KB)
#define ACR_TB (ACR_GB * ACR_KB)
-#define CSTR_TO_JSTRING(V) (*_E)->NewStringUTF(_E, (const char *)(V))
-#define WSTR_TO_JSTRING(V) (*_E)->NewString(_E, (const jchar *)(V), (jsize)wcslen((V)))
-#define ZSTR_TO_JSTRING(V, L) (*_E)->NewString(_E, (const jchar *)(V), (L))
-
-#define CSTR_DECLARE(V) \
- const char *_c##V = V ? (const char *)((*_E)->GetStringUTFChars(_E, V, NULL)) : NULL
+#define CSTR_TO_JSTRING(V) ACR_NewJavaStringA(_E, (const char *)(V))
+#define WSTR_TO_JSTRING(V) ACR_NewJavaStringW(_E, (const wchar_t *)(V))
-#define CSTR_RELEASE(V) \
- if (_c##V) (*_E)->ReleaseStringUTFChars(_E, V, _c##V)
-
-#define WSTR_DECLARE(V) \
- jsize _wl##V = V ? (*_E)->GetStringLength(_E, V) : 0; \
- const jchar *_ws##V = V ? (const jchar *)((*_E)->GetStringChars(_E, V, NULL)) : NULL; \
- wchar_t *_w##V = NULL
-
-#if CC_SIZEOF_WCHAR_T == 2
-/* wchat_t matches jchar */
-#define WPTR_DECLARE(V) \
- _w##V = (wchar_t *)malloc((_wl##V + 1) * sizeof(wchar_t)); \
- if (_wl##V) memcpy(_w##V, _ws##V, _wl##V * sizeof(wchar_t)); \
- _w##V[_wl##V] = 0
-
-#elif CC_SIZEOF_WCHAR_T == 4
-/* Presume utf16 matches utf32.
- * TODO: Figure out more optimised way of doing this.
- */
-#define WPTR_DECLARE(V) \
- _w##V = (wchar_t *)malloc((_wl##V + 1) * sizeof(wchar_t)); \
- if (_wl##V) { \
- jsize _wi##V; \
- for (_wi##V = 0; _wi##V < _wl##V; _wi##V ++) \
- _w##V[_wi##V] = _ws##V[_wi##V]; \
- } _w##V[_wl##V] = 0
-
-#else
-#error "Unsupported wchat_t size"
-#endif
+#define USTR_TO_JSTRING(V) (*_E)->NewStringUTF(_E, (const char *)(V))
+#define JSTR_TO_JSTRING(V) (*_E)->NewString(_E, (const jchar *)(V), (jsize)wcslen((V)))
+#define ZSTR_TO_JSTRING(V, L) (*_E)->NewString(_E, (const jchar *)(V), (L))
-#define WSTR_RELEASE(V) \
- if (_ws##V) (*_E)->ReleaseStringChars(_E, V, _ws##V); \
- if (_w##V) free (_w##V)
+#define WITH_USTR(V) \
+ if ((V)) { \
+ const char *_c##V; \
+ _c##V = (const char *)((*_E)->GetStringUTFChars(_E, V, NULL)); \
+ if (_c##V) { \
+
+#define END_WITH_USTR(V) \
+ (*_E)->ReleaseStringUTFChars(_E, V, _c##V); \
+ } } else ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL, 0)
+
+#define WITH_WSTR(V) \
+ if ((V)) { \
+ wchar_t *_w##V = ACR_GetJavaStringW(_E, (V)); \
+ if (!_w##V) goto _cw##V;
+
+#define END_WITH_WSTR(V) \
+ _cw##V : \
+ if (_w##V) free (_w##V); \
+ } else ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL, 0)
+
+#define WITH_CSTR(V) \
+ if ((V)) { \
+ char *_c##V = ACR_GetJavaStringA(_E, (V)); \
+ if (!_c##V) goto _ca##V;
+
+#define END_WITH_CSTR(V) \
+ _ca##V : \
+ if (_c##V) free (_c##V); \
+ } else ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL, 0)
-#define RETURN_JCSTR(V) \
+#define RETURN_UCSTR(V) \
if ((V)) return (*_E)->NewStringUTF((_E), (const char *)(V)); \
else return NULL
-#if CC_SIZEOF_WCHAR_T == 2
-/* wchat_t matches jchar */
-#define RETURN_JWSTR(V) \
- if ((V)) return (*_E)->NewString((_E), (const jchar *)(V), \
- (jsize)wcslen((V))); \
- else return NULL
-
-#else
-/* Presume utf32 fits into utf16.
- * TODO: Figure out more optimised way of doing this.
- */
#define RETURN_JWSTR(V) return ACR_NewJavaStringW(_E, (V))
-
-#endif
+#define RETURN_JCSTR(V) return ACR_NewJavaStringA(_E, (V))
#define ACR_OS_WINDOWS 0x1000
#define ACR_OS_WIN64 0x1001
@@ -242,7 +225,6 @@
#define V2Z(V) ((V) ? JNI_TRUE : JNI_FALSE)
#define J2W(V) _w##V
#define J2S(V) _c##V
-#define W2L(V) _wl##V
#if CC_SIZEOF_VOIDP == 8
typedef jlong jniptr;
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Mon Apr 20 07:30:22 2009
@@ -94,6 +94,42 @@
*/
ACR_DECLARE(jstring) ACR_NewJavaStringW(JNIEnv *_E, const wchar_t *s);
+/** Convert java string to platform char string.
+ * @param env Current JNI environment.
+ * @param s String to convert.
+ * @remark When done use ACR_Free to free the allocated memory.
+ */
+ACR_DECLARE(char *)ACR_GetJavaStringA(JNIEnv *_E, jstring s);
+
+/** Convert platform string to java string
+ * @param env Current JNI environment.
+ * @param s String to convert.
+ */
+ACR_DECLARE(jstring) ACR_NewJavaStringA(JNIEnv *_E, const char *s);
+
+/** Match ascii string to the pattern.
+ * Based loosely on sections of wildmat.c by Rich Salz
+ * @param str String to match.
+ * @param exp Expression to match with.
+ * @param match Offset to the end pf the match sequence.
+ * @param icase If non-zero, do case insensitive match.
+ * @return Match = 0, NoMatch = 1, Abort = -1
+ */
+ACR_DECLARE(int) ACR_StrMatchA(const char *str, const char *exp,
+ size_t *match, int icase);
+
+/** Match unicode string to the pattern.
+ * Based loosely on sections of wildmat.c by Rich Salz
+ * @param str String to match.
+ * @param exp Expression to match with.
+ * @param match Offset to the end pf the match sequence.
+ * @param icase If non-zero, do case insensitive match.
+ * @return Match = 0, NoMatch = 1, Abort = -1
+ */
+ACR_DECLARE(int) ACR_StrMatchW(const wchar_t *str, const wchar_t *exp,
+ size_t *match, int icase);
+
+
#ifdef __cplusplus
}
#endif
Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c Mon Apr 20 07:30:22 2009
@@ -16,6 +16,7 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_arch.h"
#include "acr_string.h"
#include <sys/utsname.h>
#include <sys/sysctl.h>
Modified: commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c Mon Apr 20 07:30:22 2009
@@ -17,6 +17,7 @@
#include "acr.h"
#include "acr_private.h"
#include "acr_arch.h"
+#include "acr_string.h"
#include <sys/utsname.h>
#define MAXSIZESYSSTRING 256
Modified: commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c Mon Apr 20 07:30:22 2009
@@ -16,6 +16,8 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_string.h"
#include <sys/systeminfo.h>
#define MAXSIZESYSSTRING 256
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Mon Apr 20 07:30:22 2009
@@ -17,6 +17,7 @@
#include "acr.h"
#include "acr_private.h"
#include "acr_error.h"
+#include "acr_string.h"
#include "acr_file.h"
/**
@@ -39,7 +40,7 @@
{
struct_stat info;
- if (stat(fname, &info) == 0) {
+ if (lstat(fname, &info) == 0) {
int type;
switch (info.st_mode & S_IFMT) {
@@ -106,12 +107,12 @@
ACR_JNI_EXPORT_DECLARE(int, io_File, ftype0)(ACR_JNISTDARGS, jstring pathname)
{
- int type;
- CSTR_DECLARE(pathname);
+ int type = ACR_FT_UNKFILE;
UNREFERENCED_O;
- type = ACR_FileTypeGet(_E, J2S(pathname));
- CSTR_RELEASE(pathname);
+ WITH_CSTR(pathname) {
+ type = ACR_FileTypeGet(_E, J2S(pathname));
+ } END_WITH_CSTR(pathname);
return type;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Mon Apr 20 07:30:22 2009
@@ -17,6 +17,7 @@
#include "acr.h"
#include "acr_private.h"
#include "acr_error.h"
+#include "acr_string.h"
#include "acr_file.h"
/**
@@ -40,18 +41,18 @@
type = ACR_FT_CHR;
else if (!info.ftLastWriteTime.dwLowDateTime &&
!info.ftLastWriteTime.dwHighDateTime &&
- !(info.nFileSizeLow | info.nFileSizeHigh)) {
+ !info.nFileSizeLow &&
+ !info.nFileSizeHigh)) {
/* XXX: Use malloc and 32K instead APR's 8K limit?
*/
- wchar_t tmpname[ACR_HBUFF_SIZ];
+ wchar_t tmpname[ACR_HBUFF_SIZ];
wchar_t *tmpoff = NULL;
- if (GetFullPathNameW(fname, ACR_HBUFF_LEN,
- tmpname, &tmpoff)) {
+ if (!ACR_StrMatchW(fname, L"\\\\*\\PIPE\\*", NULL, 1))
+ type = ACR_FT_PIPE;
+ else if (GetFullPathNameW(fname, ACR_HBUFF_LEN,
+ tmpname, &tmpoff)) {
if (!wcsncmp(tmpname, L"\\\\.\\", 4)) {
- if (!wcsnicmp(tmpname + 4, L"pipe\\", 5)) {
- type = ACR_FT_PIPE;
- }
- else if (tmpoff == tmpname + 4) {
+ if (tmpoff == tmpname + 4) {
type = ACR_FT_CHR;
}
/* For WHATEVER reason, CHR devices such as \\.\con
@@ -87,13 +88,12 @@
ACR_JNI_EXPORT_DECLARE(int, io_File, ftype0)(ACR_JNISTDARGS, jstring pathname)
{
- int type;
- WSTR_DECLARE(pathname);
+ int type = ACR_FT_UNKFILE;
UNREFERENCED_O;
- WPTR_DECLARE(pathname);
- type = ACR_FileTypeGet(_E, J2W(pathname));
- WSTR_RELEASE(pathname);
+ WITH_WSTR(pathname) {
+ type = ACR_FileTypeGet(_E, J2W(pathname));
+ } END_WITH_WSTR(pathname);
return type;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c Mon Apr 20 07:30:22 2009
@@ -16,6 +16,7 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_string.h"
#define ACR_WANT_LATE_DLL
#include "acr_arch.h"
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c Mon Apr 20 07:30:22 2009
@@ -16,6 +16,7 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_string.h"
#define ACR_WANT_LATE_DLL
#include "acr_arch.h"
@@ -97,23 +98,18 @@
ACR_JNI_EXPORT_DECLARE(void, Syslog, init1)(ACR_JNISTDARGS, jstring domain)
{
- CSTR_DECLARE(domain);
-
UNREFERENCED_O;
-
- acr_init_log_source(J2S(domain));
-
- CSTR_RELEASE(domain);
+ WITH_CSTR(domain) {
+ acr_init_log_source(J2S(domain));
+ } END_WITH_CSTR(domain);
}
ACR_JNI_EXPORT_DECLARE(void, Syslog, log0)(ACR_JNISTDARGS,
jint level,
jstring msg)
{
- WSTR_DECLARE(msg);
-
UNREFERENCED_O;
- WPTR_DECLARE(msg);
- do_syslog(level, J2W(msg), 0);
- WSTR_RELEASE(msg);
+ WITH_WSTR(msg) {
+ do_syslog(level, J2W(msg), 0);
+ } END_WITH_WSTR(msg);
}
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=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Mon Apr 20 07:30:22 2009
@@ -64,6 +64,20 @@
}
static jmethodID fo_cc_init;
+static jmethodID so_cc_init;
+static jmethodID so_gb_func;
+
+static ACR_INLINE jmethodID init_cfuncbyname(JNIEnv *_E, jclass c,
+ const char *name,
+ const char *sig)
+{
+ jmethodID m = (*_E)->GetMethodID(_E, c, name, sig);
+
+ if (m == NULL || (*_E)->ExceptionCheck(_E))
+ return NULL;
+ else
+ return m;
+}
static ACR_INLINE jmethodID init_constructor(JNIEnv *_E, jclass c, const char *sig)
{
@@ -105,8 +119,13 @@
}
i++;
}
+ /* Init some core Objects and it's methods */
fo_cc_init = init_constructor(_E, core_classes[ACR_CC_IOFILE].clazz,
"(Ljava/lang/String;)V");
+ so_cc_init = init_constructor(_E, core_classes[ACR_CC_STRING].clazz,
+ "([B)V");
+ so_gb_func = init_cfuncbyname(_E, core_classes[ACR_CC_STRING].clazz,
+ "getBytes", "()[B");
return ACR_SUCCESS;
}
@@ -195,6 +214,66 @@
fo_cc_init, p);
}
+/* This function is here because of reference to
+ * static catched method id's
+ */
+ACR_DECLARE(char *) ACR_GetJavaStringA(JNIEnv *_E, jstring str)
+{
+ jbyteArray sb = NULL;
+ jthrowable ee;
+ char *rs = NULL;
+
+ if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
+ /* JNI out of memory error */
+ return NULL;
+ }
+ sb = (*_E)->CallObjectMethod(_E, str, so_gb_func);
+ ee = (*_E)->ExceptionOccurred(_E);
+ if (!ee) {
+ jint len = (*_E)->GetArrayLength(_E, sb);
+ rs = (char *)ACR_Malloc(_E, THROW_FMARK, len + 1);
+ if (rs == NULL) {
+ (*_E)->DeleteLocalRef(_E, sb);
+ return NULL;
+ }
+ (*_E)->GetByteArrayRegion(_E, sb, 0, len, (jbyte *)rs);
+ rs[len] = '\0'; /* NUL-terminate */
+ }
+ else {
+ (*_E)->DeleteLocalRef(_E, ee);
+ }
+ (*_E)->DeleteLocalRef(_E, sb);
+
+ return rs;
+}
+
+/* This function is here because of reference to
+ * static catched method id's
+ */
+ACR_DECLARE(jstring) ACR_NewJavaStringA(JNIEnv *_E, const char *str)
+{
+ jstring rs;
+ jbyteArray ba;
+ jsize sl;
+ if (!str)
+ return NULL;
+ if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
+ /* JNI out of memory error */
+ return NULL;
+ }
+ sl = (jsize)strlen(str);
+ ba = (*_E)->NewByteArray(_E, sl);
+ if (ba != NULL) {
+ (*_E)->SetByteArrayRegion(_E, ba, 0, sl, (jbyte *)str);
+ rs = (*_E)->NewObject(_E, core_classes[ACR_CC_STRING].clazz,
+ so_cc_init, ba);
+ (*_E)->DeleteLocalRef(_E, ba);
+ return rs;
+ }
+ return NULL;
+
+}
+
ACR_DECLARE(int) ACR_LoadClass(JNIEnv *_E, JAVA_C_ID *clazz, int init_array)
{
int rv = 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=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon Apr 20 07:30:22 2009
@@ -166,26 +166,68 @@
return src;
}
-ACR_DECLARE(wchar_t *) ACR_GetJavaStringW(JNIEnv *_E, jstring s)
+ACR_DECLARE(wchar_t *) ACR_GetJavaStringW(JNIEnv *_E, jstring str)
{
- wchar_t *rv;
- WSTR_DECLARE(s);
+ jsize sl;
+ const jchar *sr;
+ wchar_t *rv = NULL;
- WPTR_DECLARE(s);
- rv = J2W(s);
- J2W(s) = NULL;
- WSTR_RELEASE(s);
+ if (!str) {
+ return NULL;
+ }
+ if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
+ /* JNI out of memory error */
+ return NULL;
+ }
+ sl = (*_E)->GetStringLength(_E, str);
+ rv = (wchar_t *)ACR_Malloc(_E, THROW_FMARK, (sl + 1) * sizeof(wchar_t));
+ if (!rv) {
+ /* Exception has already neen throw from ACR_Malloc
+ */
+ return NULL;
+ }
+ sr = (*_E)->GetStringCritical(_E, str, NULL);
+ if (!sr) {
+ free(rv);
+ return NULL;
+ }
+ else {
+#if CC_SIZEOF_WCHAR_T == 2
+ memcpy(rv, sr, sl * sizeof(wchar_t));
+#else
+ jsize i;
+ for (i = 0; i < sl; i++)
+ rv[i] = sr[i];
+#endif
+ }
+ rv[sl] = L'\0';
+ (*_E)->ReleaseStringCritical(_E, str, sr);
return rv;
}
-ACR_DECLARE(char *) ACR_GetJavaStringU(JNIEnv *_E, jstring s)
+ACR_DECLARE(char *) ACR_GetJavaStringU(JNIEnv *_E, jstring str)
{
+ const char *sr;
char *rv = NULL;
- CSTR_DECLARE(s);
- if (J2S(s))
- rv = strdup(J2S(s));
- CSTR_RELEASE(s);
+ if (!str) {
+ return NULL;
+ }
+ if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
+ /* JNI out of memory error */
+ return NULL;
+ }
+ sr = (const char *)(*_E)->GetStringUTFChars(_E, str, NULL);
+ if (!sr) {
+ return NULL;
+ }
+ if (!(rv = strdup(sr))) {
+ /* Throw OutOfMemoryError
+ */
+ ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENOMEM,
+ ACR_GET_OS_ERROR());
+ }
+ (*_E)->ReleaseStringUTFChars(_E, str, sr);
return rv;
}
@@ -211,3 +253,76 @@
}
return r;
}
+
+/* Match = 0, NoMatch = 1, Abort = -1
+ * Based loosely on sections of wildmat.c by Rich Salz
+ */
+ACR_DECLARE(int) ACR_StrMatchA(const char *str, const char *exp,
+ size_t *match, int icase)
+{
+ int x, y;
+
+ for (x = 0, y = 0; exp[y]; ++y, ++x) {
+ if (!str[x] && exp[y] != '*')
+ return -1;
+ if (exp[y] == '*') {
+ while (exp[++y] == '*');
+ if (!exp[y])
+ return 0;
+ while (str[x]) {
+ int ret;
+ if (match)
+ *match = (size_t)x;
+ if ((ret = ACR_StrMatchA(&str[x++], &exp[y], match, icase)) != 1)
+ return ret;
+ }
+ if (match)
+ *match = 0;
+ return -1;
+ }
+ else if (exp[y] != '?') {
+ if (icase) {
+ if (acr_tolower(str[x]) != acr_tolower(exp[y]))
+ return 1;
+ }
+ else if (str[x] != exp[y])
+ return 1;
+ }
+ }
+ return (str[x] != '\0');
+}
+
+ACR_DECLARE(int) ACR_StrMatchW(const wchar_t *str, const wchar_t *exp,
+ size_t *match, int icase)
+{
+ int x, y;
+
+ for (x = 0, y = 0; exp[y]; ++y, ++x) {
+ if (!str[x] && exp[y] != L'*')
+ return -1;
+ if (exp[y] == L'*') {
+ while (exp[++y] == L'*');
+ if (!exp[y])
+ return 0;
+ while (str[x]) {
+ int ret;
+ if (match)
+ *match = (size_t)x;
+ if ((ret = ACR_StrMatchW(&str[x++], &exp[y], match, icase)) != 1)
+ return ret;
+ }
+ if (match)
+ *match = 0;
+ return -1;
+ }
+ else if (exp[y] != L'?') {
+ if (icase) {
+ if (towlower(str[x]) != towlower(exp[y]))
+ return 1;
+ }
+ else if (str[x] != exp[y])
+ return 1;
+ }
+ }
+ return (str[x] != L'\0');
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/version.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/version.c?rev=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/version.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/version.c Mon Apr 20 07:30:22 2009
@@ -16,6 +16,7 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_string.h"
#include "acr_version.h"
ACR_JNI_EXPORT_DECLARE(jint, Version, get0)(ACR_JNISTDARGS, jint what)
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=766604&r1=766603&r2=766604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Mon Apr 20 07:30:22 2009
@@ -37,9 +37,9 @@
ACR_JNI_EXPORT_DECLARE(void, TestPrivate, test001)(ACR_JNISTDARGS, jstring msg)
{
- CSTR_DECLARE(msg);
- ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_EINVAL, J2S(msg));
- CSTR_RELEASE(msg);
+ WITH_CSTR(msg) {
+ ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_EINVAL, J2S(msg));
+ } END_WITH_CSTR(msg);
}
ACR_JNI_EXPORT_DECLARE(void, TestPrivate, test002)(ACR_JNISTDARGS, jint err)
@@ -72,20 +72,19 @@
ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test005)(ACR_JNISTDARGS, jstring s)
{
- WSTR_DECLARE(s);
- WPTR_DECLARE(s);
- WSTR_RELEASE(s);
-
- return W2L(s);
+ jint l = 0;
+ WITH_WSTR(s) {
+ l = wcslen(J2W(s));
+ } END_WITH_WSTR(s);
+ return l;
}
ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test006)(ACR_JNISTDARGS, jstring s)
{
- jint l;
- CSTR_DECLARE(s);
-
- l = (jint)strlen(J2S(s));
- CSTR_RELEASE(s);
+ jint l = 0;
+ WITH_CSTR(s) {
+ l = (jint)strlen(J2S(s));
+ } END_WITH_CSTR(s);
return l;
}
@@ -112,7 +111,8 @@
void *d;
acr_size_t l;
jint rc = 0;
- CSTR_DECLARE(s);
+
+ WITH_CSTR(s) {
t = ACR_TableMake(_E, THROW_FMARK, 1);
ACR_TableSet(_E, THROW_FMARK, t, J2S(s), J2S(s), 0);
@@ -135,7 +135,7 @@
rc = 0;
}
ACR_TableFree(_E, THROW_FMARK, t);
- CSTR_RELEASE(s);
+ } END_WITH_CSTR(s);
return rc;
}
@@ -161,12 +161,11 @@
ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test011)(ACR_JNISTDARGS, jstring s)
{
- jclass c;
- CSTR_DECLARE(s);
-
- c = ACR_AddClassToGlobalCache(_E, _O, J2S(s));
+ jclass c = NULL;
- CSTR_RELEASE(s);
+ WITH_CSTR(s) {
+ c = ACR_AddClassToGlobalCache(_E, _O, J2S(s));
+ } END_WITH_CSTR(s);
if (c != NULL)
return 1;
else
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=766604&r1=766603&r2=766604&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 Mon Apr 20 07:30:22 2009
@@ -104,7 +104,7 @@
throws Exception
{
try {
- test001(null);
+ test001("foo");
fail("Exception not thrown");
} catch (Throwable t) {
assertSame("Wrong Exception class",