Author: mturk
Date: Thu Apr 23 16:52:54 2009
New Revision: 767972
URL: http://svn.apache.org/viewvc?rev=767972&view=rev
Log:
Add NULL Descriptor and Pointer
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/Pointer.java
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/test/org/apache/commons/runtime/TestMemory.java
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=767972&r1=767971&r2=767972&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
Thu Apr 23 16:52:54 2009
@@ -52,6 +52,16 @@
private native void sync0()
throws SyncFailedException, IOException, InstantiationException;
+ private static native Descriptor nulld0();
+
+ /**
+ * Represents a C/C++ NULL {...@code descriptor}.
+ */
+ public static final Descriptor NULL;
+ static {
+ NULL = nulld0();
+ }
+
/**
* Called by the garbage collector when the object is destroyed.
* The class will free internal resources allocated by the Operating
system.
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=767972&r1=767971&r2=767972&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
Thu Apr 23 16:52:54 2009
@@ -39,6 +39,16 @@
private native void cleanup1()
throws Throwable;
+ private static native Pointer nullp0();
+
+ /**
+ * Represents a C/C++ NULL {...@code pointer}.
+ */
+ public static final Pointer NULL;
+ static {
+ NULL = nullp0();
+ }
+
/**
* Size in bytes of the storage needed to represent the Pointer.
*/
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=767972&r1=767971&r2=767972&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Thu Apr
23 16:52:54 2009
@@ -103,6 +103,21 @@
return NULL;
}
+static int initd0(JNIEnv *_E)
+{
+ ACR_CLASS_LRUN(Descriptor);
+ return 0;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, Descriptor, nulld0)(ACR_JNISTDARGS)
+{
+ UNREFERENCED_O;
+ if (!_clazzn.i) {
+ initd0(_E);
+ }
+ return ACR_DescriptorCreate(_E, -1, NULL, NULL);
+}
+
ACR_JNI_EXPORT_DECLARE(void, Descriptor, close0)(ACR_JNISTDARGS)
{
if (_clazzn.i && J4MID(0000)) {
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=767972&r1=767971&r2=767972&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Thu Apr 23
16:52:54 2009
@@ -108,6 +108,29 @@
return NULL;
}
+static int initp0(JNIEnv *_E)
+{
+ ACR_CLASS_LRUN(Pointer);
+ return 0;
+}
+
+#ifdef ACR_ENABLE_TEST
+/* Just for testing the cache table */
+ACR_JNI_EXPORT_DECLARE(int, TestMemory, initp0)(ACR_JNISTDARGS, jint d)
+{
+ return initp0(_E);
+}
+#endif
+
+ACR_JNI_EXPORT_DECLARE(jobject, Pointer, nullp0)(ACR_JNISTDARGS)
+{
+ UNREFERENCED_O;
+ if (!_clazzn.i) {
+ initp0(_E);
+ }
+ return ACR_PointerCreate(_E, 0, 0, NULL);
+}
+
ACR_JNI_EXPORT_DECLARE(void, Pointer, cleanup0)(ACR_JNISTDARGS)
{
if (_clazzn.i && J4MID(0000)) {
@@ -252,12 +275,3 @@
return ACR_ECLASSNOTFOUND;
}
}
-
-#ifdef ACR_ENABLE_TEST
-/* Just for testing the cache table */
-ACR_JNI_EXPORT_DECLARE(int, TestMemory, initp0)(ACR_JNISTDARGS, jint d)
-{
- ACR_CLASS_LRUN(Pointer);
- return 0;
-}
-#endif
Modified:
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=767972&r1=767971&r2=767972&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
(original)
+++
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
Thu Apr 23 16:52:54 2009
@@ -174,5 +174,13 @@
p.free();
}
+ public void testNull()
+ throws Throwable
+ {
+// Pointer p = Pointer.NULL;
+// assertNotNull("Pointer", p);
+ assertTrue("Not null", Pointer.NULL.IsNull());
+
+ }
}
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=767972&r1=767971&r2=767972&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
Thu Apr 23 16:52:54 2009
@@ -319,6 +319,14 @@
assertEquals("Value", 0, i);
}
+ public void testDescriptorNull()
+ throws Throwable
+ {
+ Descriptor d = Descriptor.NULL;
+ assertNotNull("Descriptor", d);
+ assertTrue("Closed", d.isClosed());
+ }
+
public void testDescriptorCb()
throws Throwable
{