commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1098048 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/string.h os/win32/exec.c shared/string.c
Date Sat, 30 Apr 2011 06:55:29 GMT
Author: mturk
Date: Sat Apr 30 06:55:28 2011
New Revision: 1098048

URL: http://svn.apache.org/viewvc?rev=1098048&view=rev
Log:
Use char array to string api

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
    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=1098048&r1=1098047&r2=1098048&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:55:28
2011
@@ -46,7 +46,7 @@
 #define WITH_WCHR(V)                                                        \
     do {                                                                    \
     wchar_t  _b##V[ACR_MBUFF_SIZ];                                          \
-    wchar_t *_s##V = AcrGetJavaStringC(env, V, n##V, _b##V);                \
+    wchar_t *_s##V = AcrGetJavaStringC(env, V, _b##V);                      \
     if (_s##V == 0 && V != 0) goto _e##V;
 
 #define WITH_CSTR(V)                                                        \
@@ -130,7 +130,7 @@ AcrGetJavaStringU(JNI_STDENV, jstring s,
  * @remark When done use AcrFree to free the allocated memory.
  */
 wchar_t *
-AcrGetJavaStringC(JNI_STDENV, jcharArray s, jint l, wchar_t *b);
+AcrGetJavaStringC(JNI_STDENV, jcharArray s, wchar_t *b);
 
 /** Convert java string array to platform char string array.
  * @param env Current JNI environment.

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=1098048&r1=1098047&r2=1098048&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 Sat Apr 30 06:55:28 2011
@@ -533,7 +533,7 @@ ACR_JNI_EXPORT(jobject, ExecImpl, init0)
 }
 
 ACR_WIN_EXPORT(jlong, WindowsExec, run0)(JNI_STDARGS, jstring executable,
-                                         jstring args, jcharArray envs,
+                                         jstring args, jcharArray envb,
                                          jstring cwd, jbyteArray inp,
                                          jobject out, jobject err,
                                          jint timeout)
@@ -544,11 +544,11 @@ ACR_WIN_EXPORT(jlong, WindowsExec, run0)
     acr_buf_t *ib = 0;
     acr_buf_t *ob = 0;
     acr_buf_t *eb = 0;
-    wchar_t *envb = 0;
 
     WITH_WSTR(executable) {
     WITH_WSTR(args) {
     WITH_WSTR(cwd) {
+    WITH_WCHR(envb) {
         if (IS_JOBJECT_VALID(inp)) {
             ib = &bb[0];
             ib->len = (*env)->GetArrayLength(env, inp);
@@ -558,16 +558,12 @@ ACR_WIN_EXPORT(jlong, WindowsExec, run0)
             ob = &bb[1];
         if (IS_JOBJECT_VALID(err) && JOBJECTS_NOTEQUAL(err, out))
             eb = &bb[2];
-        if (IS_JOBJECT_VALID(envs))
-            envb = (*env)->GetPrimitiveArrayCritical(env, envs, 0);
         /* Call actual execute
          */
-        rv = _run_exec(J2S(executable), J2S(args), 0, J2S(cwd),
+        rv = _run_exec(J2S(executable), J2S(args), J2S(envb), J2S(cwd),
                        ob, eb, ib, timeout, &rc);
         if (ib != 0)
             (*env)->ReleasePrimitiveArrayCritical(env, inp, ib->buf, 0);
-        if (envb != 0)
-            (*env)->ReleasePrimitiveArrayCritical(env, envs, envb, 0);
         if (rv != ACR_PARENT_ERROR) {
             if (ob != 0) {
                 /* Write to the output stream */
@@ -592,6 +588,7 @@ cleanup:
             AcrFree(ob->buf);
         if (eb != 0)
             AcrFree(eb->buf);
+    } DONE_WITH_STR(envb);
     } DONE_WITH_STR(cwd);
     } DONE_WITH_STR(args);
     } DONE_WITH_STR(executable);

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=1098048&r1=1098047&r2=1098048&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:55:28 2011
@@ -996,16 +996,15 @@ AcrGetJavaStringU(JNIEnv *env, jstring s
 }
 
 wchar_t *
-AcrGetJavaStringC(JNI_STDENV, jcharArray str, jint len, wchar_t *b)
+AcrGetJavaStringC(JNI_STDENV, jcharArray str, wchar_t *b)
 {
     wchar_t *rv = b;
     jchar   *chr;
+    jint     len;
 
     if (IS_JOBJECT_NULL(str))
         return 0;
-    if (len < 0)
-        len = (*env)->GetArrayLength(env, str);
-    if (len < 1)
+    if ((len = (*env)->GetArrayLength(env, str)) < 1)
         return 0;
     chr = (jchar *)(*env)->GetPrimitiveArrayCritical(env, str, 0);
     if (chr == 0)
@@ -1013,8 +1012,8 @@ AcrGetJavaStringC(JNI_STDENV, jcharArray
     if (len > ACR_MBUFF_LEN) {
         rv = ACR_MALLOC(wchar_t, len);
         if (rv == 0) {
-            (*env)->ReleasePrimitiveArrayCritical(env, str, chr, 0);
-            return 0;
+            /* Exception was already thrown */
+            goto cleanup;
         }
     }
 #if CC_SIZEOF_WCHAR_T == 2
@@ -1026,6 +1025,8 @@ AcrGetJavaStringC(JNI_STDENV, jcharArray
             rv[i] = chr[i];
     }
 #endif
+cleanup:
+    (*env)->ReleasePrimitiveArrayCritical(env, str, chr, 0);
     return rv;
 }
 



Mime
View raw message