commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r791069 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/ main/native/include/ main/native/include/arch/unix/ main/native/shared/ main/native/test/ test/org/apache/commons/runtime/
Date Sat, 04 Jul 2009 07:06:32 GMT
Author: mturk
Date: Sat Jul  4 07:06:31 2009
New Revision: 791069

URL: http://svn.apache.org/viewvc?rev=791069&view=rev
Log:
Add ConstPointer implementation. Check for suitable high level API

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java   (with
props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer32.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer64.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/constp.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/AbstractPointer.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/db.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.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/java/org/apache/commons/runtime/AbstractPointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/AbstractPointer.java?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/AbstractPointer.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/AbstractPointer.java
Sat Jul  4 07:06:31 2009
@@ -25,6 +25,7 @@
 abstract class AbstractPointer implements Pointer
 {
 
+	protected boolean ISCONST;
     /**
      * Create new {@code null} Pointer instance.
      * <p>

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ByReference.java
Sat Jul  4 07:06:31 2009
@@ -24,8 +24,8 @@
  * </p>
  * @since Runtime 1.0
  */
-@Retention(RetentionPolicy.SOURCE)
-@Target(ElementType.PARAMETER)
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER, ElementType.TYPE})
 public @interface ByReference
 {
 

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java?rev=791069&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java Sat
Jul  4 07:06:31 2009
@@ -0,0 +1,33 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+import java.lang.annotation.*;
+
+/**
+ * Annotation that represents the const type.
+ * <p>
+ * TODO: Describe Const usage
+ * </p>
+ * @since Runtime 1.0
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER, ElementType.TYPE})
+public @interface Const
+{
+
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer32.java?rev=791069&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer32.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer32.java
Sat Jul  4 07:06:31 2009
@@ -0,0 +1,48 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import org.apache.commons.runtime.util.Utils;
+
+/**
+ * Represents the Operating System 32-bit C/C++ const pointer.
+ *
+ * @since Runtime 1.0
+ */
+ @Const
+final class ConstPointer32 extends Pointer32
+{
+
+    private ConstPointer32()
+    {
+        // No instance
+        ISCONST = true;
+    }
+
+    /*
+     * Only created from JNI code.
+     */
+    private ConstPointer32(int ptr, int clr, int len)
+    {
+        POINTER = ptr;
+        CLEANUP = clr;
+        PLENGTH = len;
+        ISCONST = true;
+    }
+
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer32.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer64.java?rev=791069&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer64.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer64.java
Sat Jul  4 07:06:31 2009
@@ -0,0 +1,48 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import org.apache.commons.runtime.util.Utils;
+
+/**
+ * Represents the Operating System 64-bit C/C++ const pointer.
+ *
+ * @since Runtime 1.0
+ */
+@Const
+final class ConstPointer64 extends Pointer64
+{
+
+    private ConstPointer64()
+    {
+        // No instance
+        ISCONST = true;
+    }
+
+    /*
+     * Only created from JNI code.
+     */
+    private ConstPointer64(long ptr, long clr, long len)
+    {
+        POINTER = ptr;
+        CLEANUP = clr;
+        PLENGTH = len;
+        ISCONST = true;
+    }
+
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer64.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
Sat Jul  4 07:06:31 2009
@@ -44,6 +44,7 @@
         POINTER = ptr;
         CLEANUP = clr;
         PLENGTH = len;
+        ISCONST = false;
     }
 
     public boolean equals(Object other)
@@ -92,6 +93,8 @@
             throw new NullPointerException();
         else if (index < 0 || index >= PLENGTH)
             throw new IndexOutOfBoundsException();
+        else if (ISCONST)
+            throw new UnsupportedOperationException();
         poke0(POINTER + index, value);
     }
 
@@ -112,6 +115,8 @@
             throw new IndexOutOfBoundsException();
         else if ((int)(dstPos + length) > d32.PLENGTH)
             throw new IndexOutOfBoundsException();
+        else if (d32.ISCONST)
+            throw new UnsupportedOperationException();
         copy0(POINTER + (int)srcPos, d32.POINTER + (int)dstPos, (int)length);
     }
 
@@ -129,6 +134,8 @@
             throw new IndexOutOfBoundsException();
         else if ((int)(srcPos + length) > s32.PLENGTH)
             throw new IndexOutOfBoundsException();
+        else if (ISCONST)
+            throw new UnsupportedOperationException();
         move0(s32.POINTER + (int)dstPos, POINTER + (int)srcPos, (int)length);
     }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
Sat Jul  4 07:06:31 2009
@@ -91,6 +91,8 @@
             throw new NullPointerException();
         else if (index < 0L || index >= PLENGTH)
             throw new IndexOutOfBoundsException();
+        else if (ISCONST)
+            throw new UnsupportedOperationException();
         poke0(POINTER + index, value);
     }
 
@@ -111,6 +113,8 @@
             throw new IndexOutOfBoundsException();
         else if (dstPos + length > d64.PLENGTH)
             throw new IndexOutOfBoundsException();
+        else if (d64.ISCONST)
+            throw new UnsupportedOperationException();
         copy0(POINTER + srcPos, d64.POINTER + dstPos, length);
     }
 
@@ -128,6 +132,8 @@
             throw new IndexOutOfBoundsException();
         else if (srcPos + length > s64.PLENGTH)
             throw new IndexOutOfBoundsException();
+        else if (ISCONST)
+            throw new UnsupportedOperationException();
         move0(s64.POINTER + dstPos, POINTER + srcPos, length);
     }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Sat Jul  4 07:06:31 2009
@@ -75,6 +75,7 @@
 COMMON_OBJS=\
 	$(SRCDIR)/shared/buildmark.$(OBJ) \
 	$(SRCDIR)/shared/clazz.$(OBJ) \
+	$(SRCDIR)/shared/constp.$(OBJ) \
 	$(SRCDIR)/shared/descriptor.$(OBJ) \
 	$(SRCDIR)/shared/db.$(OBJ) \
 	$(SRCDIR)/shared/error.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sat Jul  4 07:06:31 2009
@@ -69,6 +69,7 @@
 COMMON_OBJS=\
 	$(SRCDIR)/shared/buildmark.$(OBJ) \
 	$(SRCDIR)/shared/clazz.$(OBJ) \
+	$(SRCDIR)/shared/constp.$(OBJ) \
 	$(SRCDIR)/shared/descriptor.$(OBJ) \
 	$(SRCDIR)/shared/db.$(OBJ) \
 	$(SRCDIR)/shared/error.$(OBJ) \

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=791069&r1=791068&r2=791069&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 Sat Jul  4 07:06:31
2009
@@ -106,14 +106,22 @@
                                    size_t len, acr_pointer_cleanup_fn_t *cb);
 
 /**
+ * Create new DirectBuffer class instance and allocate memory.
+ * @param env Current JNI environment
+ * @param len Number of bytes to allocate. The allocated memory is set to zero.
+ * @return NULL on failure and errno set to ACR error code.
+ */
+ACR_DECLARE(jobject) ACR_NewDirectBuffer(JNIEnv *env, size_t len);
+
+/**
  * Create new DirectBuffer class instance
  * @param env Current JNI environment
  * @param p Native pointer to wrap into Pointer class
  * @param len Length of the pointer.
  * @param cb callback function to use on Pointer.finalize()
  */
-ACR_DECLARE(jobject) ACR_NewDirectBuffer(JNIEnv *env, void *p, size_t len,
-                                         acr_pointer_cleanup_fn_t *cb);
+ACR_DECLARE(jobject) ACR_NewDirectBufferEx(JNIEnv *env, void *p, size_t len,
+                                           acr_pointer_cleanup_fn_t *cb);
 
 /**
  * Create new DirectBuffer array
@@ -122,6 +130,22 @@
  */
 ACR_DECLARE(jobjectArray) ACR_NewDirectBufferArray(JNIEnv *env, jsize len);
 
+/**
+ * Create new ConstPointer array
+ * @param env Current JNI environment
+ * @param len Size of the new ConstPointer array
+ */
+ACR_DECLARE(jobjectArray) ACR_NewConstPointerArray(JNIEnv *env, jsize len);
+
+/**
+ * Create new ConstPointer class instance
+ * @param env Current JNI environment
+ * @param p Native pointer to wrap into ConstPointer class
+ * @param len Length of the pointer.
+ * @note ConstPointer does not have callback function.
+ */
+ACR_DECLARE(jobject) ACR_NewConstPointer(JNIEnv *env, const void *p,
+                                         size_t len);
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Sat Jul  4
07:06:31 2009
@@ -35,7 +35,8 @@
 
 #define ACR_MIN_FREAD_LEN    4096
 #define ACR_MAX_FREAD_LEN    65536
-#define INVALID_HANDLE_VALUE ((void *)-1)
+#define INVALID_HANDLE_VALUE ((void *)(ptrdiff_t)-1)
+#define IS_INVALID_HANDLE(h) (((h) == NULL || (h) == INVALID_HANDLE_VALUE))
 
 typedef struct acr_ioh {
     void           *h;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sat Jul  4 07:06:31 2009
@@ -372,6 +372,7 @@
 /* Forward class loading declarations */
 ACR_CLASS_LDEC(Descriptor);
 ACR_CLASS_LDEC(AbstractPointer);
+ACR_CLASS_LDEC(ConstPointer);
 ACR_CLASS_LDEC(DirectBuffer);
 ACR_CLASS_LDEC(MbString);
 ACR_CLASS_LDEC(Group);
@@ -383,6 +384,7 @@
 
     ACR_CLASS_LRUN(Descriptor);
     ACR_CLASS_LRUN(AbstractPointer);
+    ACR_CLASS_LRUN(ConstPointer);
     ACR_CLASS_LRUN(DirectBuffer);
     ACR_CLASS_LRUN(MbString);
     ACR_CLASS_LRUN(Group);
@@ -400,6 +402,7 @@
 
     ACR_CLASS_URUN(Descriptor);
     ACR_CLASS_URUN(AbstractPointer);
+    ACR_CLASS_URUN(ConstPointer);
     ACR_CLASS_URUN(DirectBuffer);
     ACR_CLASS_URUN(MbString);
     ACR_CLASS_URUN(Group);

Added: commons/sandbox/runtime/trunk/src/main/native/shared/constp.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/constp.c?rev=791069&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/constp.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/constp.c Sat Jul  4 07:06:31 2009
@@ -0,0 +1,107 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_clazz.h"
+#include "acr_memory.h"
+#include "acr_pointer.h"
+#include "acr_vm.h"
+
+#define  ACR_WANT_MEMPROTECT
+#include "acr_error.h"
+
+/**
+ * ConstPointer utilities
+ */
+/**
+ * Pointer class utilities
+ */
+#if CC_SIZEOF_VOIDP == 8
+#define ACR_CPT_EXPORT_DECLARE(RT, FN)  \
+    JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_ConstPointer64_##FN
+
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    ACR_CLASS_PATH "ConstPointer64"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(JJJ)V"
+};
+
+#else
+#define ACR_DBB_EXPORT_DECLARE(RT, FN)  \
+    JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_ConstPointer32_##FN
+
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    ACR_CLASS_PATH "ConstPointer32"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(III)V"
+};
+
+#endif
+
+ACR_CLASS_LDEF(ConstPointer)
+{
+    int rv;
+
+    if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_METHOD(0000);
+
+    return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(ConstPointer)
+{
+    ACR_UnloadClass(_E, &_clazzn);
+}
+
+ACR_DECLARE(jobjectArray) ACR_NewConstPointerArray(JNIEnv *_E, jsize len)
+{
+    if (_clazzn.i)
+        return (*_E)->NewObjectArray(_E, len, _clazzn.i, NULL);
+    else
+        return NULL;
+}
+
+ACR_DECLARE(jobject) ACR_NewConstPointer(JNIEnv *_E, const void *p, size_t len)
+{
+    if (_clazzn.i && J4MID(0000)) {
+         return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000),
+                                 P2N(p), 0, (acr_ptr_t)len);
+    }
+    else {
+        ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
+        return NULL;
+    }
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/constp.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/db.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/db.c?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/db.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/db.c Sat Jul  4 07:06:31 2009
@@ -93,12 +93,56 @@
         return NULL;
 }
 
-ACR_DECLARE(jobject) ACR_NewDirectBuffer(JNIEnv *_E, void *p, size_t len,
-                                         acr_pointer_cleanup_fn_t *cb)
+/*
+ * Default DirectBuffer cleanup
+ */
+static int direct_buffer_cleanup(void *mem, size_t unused)
 {
-    if (_clazzn.i && J4MID(0000))
+    if (mem) {
+        free(mem);
+        return 0;
+    }
+    else {
+        return ACR_EISNULL;
+    }
+}
+
+ACR_DECLARE(jobject) ACR_NewDirectBuffer(JNIEnv *_E, size_t len)
+{
+    if (_clazzn.i && J4MID(0000)) {
+        jobject ptr = NULL;
+        void   *mem;
+        acr_size_t siz = (acr_size_t)ACR_ALIGN_DEFAULT(len);
+
+        if (len < 1) {
+            ACR_SET_OS_ERROR(ACR_EISNULL);
+            return NULL;
+        }
+        mem = ACR_Calloc(_E, THROW_NMARK, siz);
+        if (mem) {
+            /* Create the DirectBuffer class with default cleanup.
+             */
+            ptr = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000),
+                                   P2N(mem), P2N(direct_buffer_cleanup),
+                                   (acr_ptr_t)len);
+            if (!ptr)
+                free(mem);
+        }
+        return ptr;
+    }
+    else {
+        ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
+        return NULL;
+    }
+}
+
+ACR_DECLARE(jobject) ACR_NewDirectBufferEx(JNIEnv *_E, void *p, size_t len,
+                                           acr_pointer_cleanup_fn_t *cb)
+{
+    if (_clazzn.i && J4MID(0000)) {
         return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000),
                                 P2N(p), P2N(cb), (acr_ptr_t)len);
+    }
     else {
         ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
         return NULL;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sat Jul  4 07:06:31 2009
@@ -55,11 +55,11 @@
 {
     jclass ec;
 
-    if (!env)
+    if (env == NULL)
         env = ACR_GetJNIEnv();
-    if (!env) {
+    if (IS_INVALID_HANDLE(env)) {
 #ifdef DEBUG
-        fprintf(stderr, "[ERROR]  Cannot allocate JNI Environment\n");
+        fprintf(stderr, "[ERROR]  Missing JNI Environment\n");
         if (msg)
             fprintf(stderr, "[ERROR]  %s\n", msg);
         fflush(stderr);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Sat Jul  4 07:06:31 2009
@@ -16,6 +16,7 @@
 
 #include "acr.h"
 #include "acr_private.h"
+#include "acr_arch.h"
 #include "acr_memory.h"
 #define  ACR_WANT_MEMPROTECT
 #include "acr_error.h"
@@ -41,7 +42,7 @@
         int err = ACR_GET_OS_ERROR();
         if (_E == NULL)
             _E = ACR_GetJNIEnv();
-        if (_E != NULL)
+        if (!IS_INVALID_HANDLE(_E))
             ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, err);
     }
     return mem;
@@ -56,7 +57,7 @@
         int err = ACR_GET_OS_ERROR();
         if (_E == NULL)
             _E = ACR_GetJNIEnv();
-        if (_E != NULL)
+        if (!IS_INVALID_HANDLE(_E))
             ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, err);
     }
     return mem;
@@ -71,7 +72,7 @@
         int err = ACR_GET_OS_ERROR();
         if (_E == NULL)
             _E = ACR_GetJNIEnv();
-        if (_E != NULL)
+        if (!IS_INVALID_HANDLE(_E))
             ACR_ThrowException(_E, file, line, ACR_EX_ENOMEM, err);
     }
     return mem;
@@ -80,10 +81,10 @@
 ACR_DECLARE(void) ACR_Free(JNIEnv *_E, const char *file, int line,
                            void *mem)
 {
-    if (!mem) {
+    if (IS_INVALID_HANDLE(mem)) {
         if (_E == NULL)
             _E = ACR_GetJNIEnv();
-        if (_E != NULL)
+        if (!IS_INVALID_HANDLE(_E))
             ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                                ACR_EISNULL);
     }
@@ -167,7 +168,7 @@
     if (!sbh) {
         if (_E == NULL)
             _E = ACR_GetJNIEnv();
-        if (_E != NULL)
+        if (!IS_INVALID_HANDLE(_E))
             ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                                ACR_EISNULL);
         return NULL;
@@ -202,7 +203,7 @@
     if (!sbh) {
         if (_E == NULL)
             _E = ACR_GetJNIEnv();
-        if (_E != NULL)
+        if (!IS_INVALID_HANDLE(_E))
         ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                            ACR_EISNULL);
         return;
@@ -224,7 +225,7 @@
     if (!sbh) {
         if (_E == NULL)
             _E = ACR_GetJNIEnv();
-        if (_E != NULL)
+        if (!IS_INVALID_HANDLE(_E))
             ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
                                ACR_EISNULL);
         return;
@@ -313,7 +314,7 @@
 	    /* Trying to realloc on something we didn't alloc first.
 	     */
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, ACR_EFAULT);
-		return;	
+		return;
 	}
     np = ACR_Realloc(_E, THROW_NMARK, op, ss);
     if (!np) {

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=791069&r1=791068&r2=791069&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Sat Jul  4 07:06:31 2009
@@ -55,6 +55,11 @@
     ACR_Free(NULL, THROW_FMARK, NULL);
 }
 
+ACR_JNI_EXPORT_DECLARE(void, TestPrivate, test040)(ACR_JNISTDARGS, jint d)
+{
+    ACR_Free(INVALID_HANDLE_VALUE, THROW_FMARK, NULL);
+}
+
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test004)(ACR_JNISTDARGS, jint d)
 {
     int i, j;
@@ -236,7 +241,19 @@
 ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test038)(ACR_JNISTDARGS, jint d)
 {
 
-    return  ACR_NewDirectBuffer(_E, I2P(d, void *), 0, dbbcallback);
+    return  ACR_NewDirectBufferEx(_E, I2P(d, void *), 0, dbbcallback);
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test039)(ACR_JNISTDARGS, jint d)
+{
+
+    return  ACR_NewDirectBuffer(_E, (size_t)d);
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test041)(ACR_JNISTDARGS, jint d)
+{
+
+    return  ACR_NewConstPointer(_E, "Hello World", sizeof("Hello World"));
 }
 
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test018)(ACR_JNISTDARGS, jobject p)

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=791069&r1=791068&r2=791069&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 Sat
Jul  4 07:06:31 2009
@@ -48,6 +48,7 @@
     private static native void  test001(String msg);
     private static native void  test002(int err);
     private static native void  test003(int d);
+    private static native void  test040(int d);
     private static native int   test004(int d);
     private static native int   test005(String msg);
     private static native int   test006(String msg);
@@ -64,6 +65,8 @@
     private static native int   test016(int d);
     private static native Pointer test017(int d);
     private static native DirectBuffer test038(int d);
+    private static native DirectBuffer test039(int d);
+    private static native Pointer test041(int d);
     private static native int   test018(Pointer p);
     private static native int   test019(Pointer p);
 
@@ -158,6 +161,16 @@
         }
     }
 
+    public void testFreeNullNoEx()
+        throws Exception
+    {
+        try {
+            test040(0);
+        } catch (Throwable t) {
+            fail("Exception thrown");
+        }
+    }
+
     public void testSbh()
         throws Exception
     {
@@ -310,6 +323,43 @@
         Thread.sleep(200);
     }
 
+    public void testDirectBufferStd()
+        throws Throwable
+    {
+        DirectBuffer b = test039(1000);
+        assertNotNull("DirectBuffer", b);
+        b.free();
+        b = null;
+        System.gc();
+        // This should be enough for a gc
+        // from Pointer.finalize()
+        Thread.sleep(200);
+    }
+
+    public void testConstPtr()
+        throws Throwable
+    {
+        Pointer c = test041(0);
+        assertNotNull("ConstPointer", c);
+        try {
+            c.poke(0, 1);
+            fail("Missing UnsupportedOperationException");
+
+        } catch (UnsupportedOperationException ux) {
+            // OK
+        } catch (Exception ex) {
+            fail("Expecting UnsupportedOperationException but was " + ex);
+        }
+
+
+        c.free();
+        c = null;
+        System.gc();
+        // This should be enough for a gc
+        // from Pointer.finalize()
+        Thread.sleep(200);
+    }
+
     public void testPointerGc()
         throws Throwable
     {
@@ -389,7 +439,7 @@
         DirectBuffer b = test038(0);
         assertNotNull("Buffer", b);
 
-		int r = a.compareTo(b);
+        int r = a.compareTo(b);
         assertEquals("Compare", -1, r);
         a.free();
         b.free();



Mime
View raw message