[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: libclasspath const/non-const warnings
From: |
Steven Augart |
Subject: |
Re: libclasspath const/non-const warnings |
Date: |
Mon, 21 Jun 2004 17:48:13 -0400 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007 |
Michael Koch wrote:
-JCL_free_cstring (JNIEnv * env, jstring s, const char *cstr)
+JCL_free_cstring (JNIEnv * env, jstring s, char *cstr)
{
(*env)->ReleaseStringUTFChars (env, s, cstr);
}
I would think "cstr" stands for "constant string" but you removed
"const". Perhaps you should rename "cstr" to "str".
Logically, you'd think so. But it's just the counter-part of
JCL_jstring_to_cstring, which converts a Java string into a C
string. Thus the "cstr".
I converted it to take a non-const pointer because the underlying
ReleaseStringUTFChars may call free() to release the memory.
I am looking this over more carefully, though, and I see that the JNI
spec defines GetStringUTFChars as returning a "const char *", and
ReleaseStringUTFChars as taking a "const char *" -- presumably,
because the designers thought there might be some VM out there that
natively stores strings as UTF?
So, that change was not appropriate, and I have backed it out. Thanks
for catching this.
--Steven
--
Steven Augart
Jikes RVM, a free, open source, Virtual Machine:
http://oss.software.ibm.com/jikesrvm
ChangeLog entry:
2004-06-21 Steven Augart <address@hidden>
* native/jni/classpath/jcl.h, native/jni/classpath/jcl.c
(JCL_free_cstring): "cstr" argument back to const.
Index: native/jni/classpath/jcl.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/classpath/jcl.c,v
retrieving revision 1.10
diff -I*.class -u -r1.10 jcl.c
--- native/jni/classpath/jcl.c 21 Jun 2004 19:39:41 -0000 1.10
+++ native/jni/classpath/jcl.c 21 Jun 2004 21:45:19 -0000
@@ -139,7 +139,7 @@
}
JNIEXPORT void JNICALL
-JCL_free_cstring (JNIEnv * env, jstring s, char *cstr)
+JCL_free_cstring (JNIEnv * env, jstring s, const char *cstr)
{
(*env)->ReleaseStringUTFChars (env, s, cstr);
}
Index: native/jni/classpath/jcl.h
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/classpath/jcl.h,v
retrieving revision 1.8
diff -I*.class -u -r1.8 jcl.h
--- native/jni/classpath/jcl.h 21 Jun 2004 19:39:41 -0000 1.8
+++ native/jni/classpath/jcl.h 21 Jun 2004 21:45:19 -0000
@@ -51,7 +51,8 @@
JNIEXPORT void JNICALL JCL_free (JNIEnv * env, void *p);
JNIEXPORT const char *JNICALL JCL_jstring_to_cstring (JNIEnv * env,
jstring s);
-JNIEXPORT void JNICALL JCL_free_cstring (JNIEnv * env, jstring s, char *cstr);
+JNIEXPORT void JNICALL JCL_free_cstring (JNIEnv * env, jstring s,
+ const char *cstr);
JNIEXPORT jint JNICALL JCL_MonitorEnter (JNIEnv * env, jobject o);
JNIEXPORT jint JNICALL JCL_MonitorExit (JNIEnv * env, jobject o);