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/17 13:53:24 UTC
svn commit: r765957 - in /commons/sandbox/runtime/trunk/src:
main/native/include/ main/native/shared/ main/native/test/
test/org/apache/commons/runtime/
Author: mturk
Date: Fri Apr 17 11:53:24 2009
New Revision: 765957
URL: http://svn.apache.org/viewvc?rev=765957&view=rev
Log:
Add setter API for Pointer and Descriptor classes
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
commons/sandbox/runtime/trunk/src/main/native/shared/pointer.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/native/include/acr_descriptor.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h?rev=765957&r1=765956&r2=765957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h Fri Apr 17 11:53:24 2009
@@ -63,7 +63,7 @@
ACR_DECLARE(int) ACR_DescriptorCleanup(JNIEnv *env, jobject obj);
/**
- * Get the native pointer from the Pointer object.
+ * Get the native int descriptor from the Descriptor object.
* @param env Current JNI environment
* @param obj Java Descriptor object use.
* @return Underlying wrapped integer descriptor.
@@ -71,13 +71,31 @@
ACR_DECLARE(int) ACR_DescriptorGetInt(JNIEnv *env, jobject obj);
/**
- * Get the native pointer from the Pointer object.
+ * Get the native pointer descriptor from the Descriptor object.
* @param env Current JNI environment
* @param obj Java Descriptor object use.
* @return Underlying wrapped pointer descriptor.
*/
ACR_DECLARE(void *) ACR_DescriptorGetPtr(JNIEnv *env, jobject obj);
+/**
+ * Set the native pointer descriptor to the Descriptor object.
+ * @param env Current JNI environment
+ * @param obj Java Descriptor object use.
+ * @param val Value to set.
+ * @return ACR error code on failure.
+ */
+ACR_DECLARE(int) ACR_DescriptorSetPtr(JNIEnv *env, jobject obj, void *val);
+
+/**
+ * Set the native int descriptor to the Descriptor object.
+ * @param env Current JNI environment
+ * @param obj Java Descriptor object use.
+ * @param val Value to set.
+ * @return ACR error code on failure.
+ */
+ACR_DECLARE(int) ACR_DescriptorSetInt(JNIEnv *env, jobject obj, int val);
+
#ifdef __cplusplus
}
#endif
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h?rev=765957&r1=765956&r2=765957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h Fri Apr 17 11:53:24 2009
@@ -64,6 +64,15 @@
*/
ACR_DECLARE(void *) ACR_PointerGet(JNIEnv *env, jobject ptr);
+/**
+ * Set the native pointer to the Pointer object.
+ * @param env Current JNI environment
+ * @param ptr Java Pointer object use.
+ * @param val Value to set.
+ * @return ACR error code on failure.
+ */
+ACR_DECLARE(int) ACR_PointerSet(JNIEnv *env, jobject ptr, void *val);
+
#ifdef __cplusplus
}
#endif
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=765957&r1=765956&r2=765957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Fri Apr 17 11:53:24 2009
@@ -258,3 +258,37 @@
return -1;
}
}
+
+ACR_DECLARE(int) ACR_DescriptorSetPtr(ACR_JNISTDARGS, void *p)
+{
+ if (_clazzn.i && _m0000n.i) {
+#if CC_SIZEOF_VOIDP == 8
+ SET_IFIELD_J(0001, _O, (jlong)((acr_ptr_t)p));
+#else
+ SET_IFIELD_I(0001, _O, (jint)((acr_ptr_t)p));
+#endif
+ if ((*_E)->ExceptionCheck(_E)) {
+ return ACR_EGENERAL;
+ }
+ else
+ return ACR_SUCCESS;
+ }
+ else {
+ return ACR_ECLASSNOTFOUND;
+ }
+}
+
+ACR_DECLARE(int) ACR_DescriptorSetInt(ACR_JNISTDARGS, int i)
+{
+ if (_clazzn.i && _m0000n.i) {
+ SET_IFIELD_I(0000, _O, i);
+ if ((*_E)->ExceptionCheck(_E)) {
+ return ACR_EGENERAL;
+ }
+ else
+ return ACR_SUCCESS;
+ }
+ else {
+ return ACR_ECLASSNOTFOUND;
+ }
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=765957&r1=765956&r2=765957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Apr 17 11:53:24 2009
@@ -199,3 +199,22 @@
return NULL;
}
}
+
+ACR_DECLARE(int) ACR_PointerSet(ACR_JNISTDARGS, void *p)
+{
+ if (_clazzn.i && _m0000n.i) {
+#if CC_SIZEOF_VOIDP == 8
+ SET_IFIELD_J(0000, _O, (jlong)((acr_ptr_t)p));
+#else
+ SET_IFIELD_I(0000, _O, (jint)((acr_ptr_t)p));
+#endif
+ if ((*_E)->ExceptionCheck(_E)) {
+ return ACR_EGENERAL;
+ }
+ else
+ return ACR_SUCCESS;
+ }
+ else {
+ return ACR_ECLASSNOTFOUND;
+ }
+}
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=765957&r1=765956&r2=765957&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Fri Apr 17 11:53:24 2009
@@ -273,3 +273,13 @@
{
return ACR_DescriptorGetInt(_E, d);
}
+
+ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test025)(ACR_JNISTDARGS, jobject d, int v)
+{
+ return ACR_DescriptorSetPtr(_E, d, (void *)v);
+}
+
+ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test026)(ACR_JNISTDARGS, jobject d, int v)
+{
+ return ACR_DescriptorSetInt(_E, d, v);
+}
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=765957&r1=765956&r2=765957&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 Apr 17 11:53:24 2009
@@ -68,6 +68,8 @@
private static native int test022(Descriptor p);
private static native int test023(Descriptor p);
private static native int test024(Descriptor p);
+ private static native int test025(Descriptor p, int i);
+ private static native int test026(Descriptor p, int i);
protected void setUp()
@@ -429,4 +431,53 @@
Thread.sleep(200);
}
+ public void testDescriptorNativePtrSet()
+ throws Throwable
+ {
+ Descriptor d = test021(-1, 0xcafebabe);
+ assertNotNull("Descriptor", d);
+ assertFalse("Closed", d.isClosed());
+ int r = test023(d);
+ assertEquals("Result ", 1, r);
+ int s = test025(d, 0xdeadbeef);
+ assertEquals("Result ", 0, s);
+ int n = test023(d);
+ assertEquals("Result ", 1, n);
+ d.close();
+ int c = test023(d);
+ // Second call must return NULL
+ assertEquals("Result ", 0, c);
+
+ d = null;
+ System.gc();
+ // This should be enough for a gc
+ // from Pointer.finalize()
+ Thread.sleep(200);
+ }
+
+ public void testDescriptorNativeIntSet()
+ throws Throwable
+ {
+ Descriptor d = test021(2303, 0);
+ assertNotNull("Descriptor", d);
+ assertFalse("Closed", d.isClosed());
+ int r = test024(d);
+ assertEquals("Result ", 2303, r);
+ int s = test026(d, 1964);
+ assertEquals("Result ", 0, s);
+ int n = test024(d);
+ assertEquals("Result ", 1964, n);
+ d.close();
+ int c = test024(d);
+ // Second call must return -1
+ assertEquals("Result ", -1, c);
+
+ d = null;
+ System.gc();
+ // This should be enough for a gc
+ // from Pointer.finalize()
+ Thread.sleep(200);
+ }
+
+
}