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 2011/04/30 08:43:49 UTC

svn commit: r1098047 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/string.h shared/string.c

Author: mturk
Date: Sat Apr 30 06:43:48 2011
New Revision: 1098047

URL: http://svn.apache.org/viewvc?rev=1098047&view=rev
Log:
Use common mutex for lib locking

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c

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=1098047&r1=1098046&r2=1098047&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 Sat Apr 30 06:43:48 2011
@@ -43,6 +43,12 @@
     wchar_t *_s##V = AcrGetJavaStringW(env, V, _b##V);                      \
     if (_s##V == 0 && V != 0) goto _e##V;
 
+#define WITH_WCHR(V)                                                        \
+    do {                                                                    \
+    wchar_t  _b##V[ACR_MBUFF_SIZ];                                          \
+    wchar_t *_s##V = AcrGetJavaStringC(env, V, n##V, _b##V);                \
+    if (_s##V == 0 && V != 0) goto _e##V;
+
 #define WITH_CSTR(V)                                                        \
     do {                                                                    \
     char  _b##V[ACR_PBUFF_SIZ];                                             \
@@ -94,7 +100,7 @@ AcrGetNativeCodePage(const char *cs);
 /** Convert java string to wide char string
  * @param env Current JNI environment.
  * @param s String to convert.
- * @remark When done use ACR_Free to free the allocated memory.
+ * @remark When done use AcrFree to free the allocated memory.
  */
 wchar_t *
 AcrGetJavaStringW(JNI_STDENV, jstring s, wchar_t *b);
@@ -102,7 +108,10 @@ AcrGetJavaStringW(JNI_STDENV, jstring 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.
+ * @paman b Optional stack buffer of ACR_PBUFF_SIZ size.
+ *          If provided and string is smaller then its size
+ *          it will be used instead allocating memory.
+ * @remark When done use AcrFree to free the allocated memory.
  */
 char *
 AcrGetJavaStringA(JNI_STDENV, jstring s, char *b);
@@ -110,15 +119,23 @@ AcrGetJavaStringA(JNI_STDENV, jstring s,
 /** Convert java string to UTF-8 char string.
  * @param env Current JNI environment.
  * @param s String to convert.
- * @remark When done use ACR_Free to free the allocated memory.
+ * @remark When done use AcrFree to free the allocated memory.
  */
 char *
 AcrGetJavaStringU(JNI_STDENV, jstring s, char *b);
 
+/** Convert java string to wide char string
+ * @param env Current JNI environment.
+ * @param s String to convert.
+ * @remark When done use AcrFree to free the allocated memory.
+ */
+wchar_t *
+AcrGetJavaStringC(JNI_STDENV, jcharArray s, jint l, wchar_t *b);
+
 /** Convert java string array to platform char string array.
  * @param env Current JNI environment.
  * @param a String array to convert.
- * @remark When done use ACR_FreeStringArrayA to free the allocated memory.
+ * @remark When done use AcrFreeStringArrayA to free the allocated memory.
  */
 char **
 AcrGetJavaStringArrayA(JNI_STDENV, jobjectArray a);
@@ -126,7 +143,7 @@ AcrGetJavaStringArrayA(JNI_STDENV, jobje
 /** Convert java string array to wide char string array.
  * @param env Current JNI environment.
  * @param a String array to convert.
- * @remark When done use ACR_FreeStringArrayW to free the allocated memory.
+ * @remark When done use AcrFreeStringArrayW to free the allocated memory.
  */
 wchar_t **
 AcrGetJavaStringArrayW(JNI_STDENV, jobjectArray a);

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=1098047&r1=1098046&r2=1098047&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Sat Apr 30 06:43:48 2011
@@ -995,6 +995,40 @@ AcrGetJavaStringU(JNIEnv *env, jstring s
         return get_string_utf_8(env, str, b);
 }
 
+wchar_t *
+AcrGetJavaStringC(JNI_STDENV, jcharArray str, jint len, wchar_t *b)
+{
+    wchar_t *rv = b;
+    jchar   *chr;
+
+    if (IS_JOBJECT_NULL(str))
+        return 0;
+    if (len < 0)
+        len = (*env)->GetArrayLength(env, str);
+    if (len < 1)
+        return 0;
+    chr = (jchar *)(*env)->GetPrimitiveArrayCritical(env, str, 0);
+    if (chr == 0)
+        return 0;
+    if (len > ACR_MBUFF_LEN) {
+        rv = ACR_MALLOC(wchar_t, len);
+        if (rv == 0) {
+            (*env)->ReleasePrimitiveArrayCritical(env, str, chr, 0);
+            return 0;
+        }
+    }
+#if CC_SIZEOF_WCHAR_T == 2
+    memcpy(rv, chr, len * sizeof(wchar_t));
+#else
+    {
+        jint i;
+        for (i = 0; i < len; i++)
+            rv[i] = chr[i];
+    }
+#endif
+    return rv;
+}
+
 jstring
 AcrNewJavaStringW(JNIEnv *env, const wchar_t *s)
 {