Author: mturk
Date: Thu Apr 16 12:13:20 2009
New Revision: 765590

URL: http://svn.apache.org/viewvc?rev=765590&view=rev
Log:
Add initial Pointer(Pointer32/Pointer64) classes

Added:
    
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
   (with props)
    
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
   (with props)
    
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
   (with props)
    commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h   (with 
props)
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c   (with 
props)
Modified:
    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_clazz.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
    
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Added: 
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=765590&view=auto
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
 (added)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
 Thu Apr 16 12:13:20 2009
@@ -0,0 +1,72 @@
+/* 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;
+
+/** Represents the Operating System C/C++ pointer.
+ * <br/><br/>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * @since Runtime 1.0
+ */
+public abstract class Pointer {
+
+    /*
+     * Pointer can be only created from native code.
+     * Suppress any instantiation except form internal classes.
+     */
+    protected Pointer()
+    {
+        // No Instance
+    }
+
+    private native void cleanup0()
+        throws Throwable;
+
+
+    /** True if the Pointer is 64-bit.
+     */
+    public static final boolean IS_64_BIT = OS.getDataModel() == 64 ? true : 
false;
+
+    /** Long value of the internal pointer
+     * @return Internal pointer address casted to the <code>long</code>.
+     */
+    public abstract long longValue();
+
+    /** Integer value of the internal pointer
+     * @return Internal pointer address casted to the <code>int</code>.
+     * @throws ClassCastException if the running JVM is 64 bit.
+     */
+    public abstract int intValue()
+        throws ClassCastException;
+
+    /**
+     * Called by the garbage collector when the object is destroyed.
+     * The class will free internal resources allocated by the Operating 
system.
+     * @see java.lang.Object for datailed explanation.
+     * @throws Throwable the <code>Exception</code> raised by this method.
+     */    
+    protected final void finalize()
+        throws Throwable
+    {
+        cleanup0();
+    }
+
+    public void testCleanup()
+        throws Throwable
+    {
+        cleanup0();
+    }
+}

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

Added: 
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=765590&view=auto
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
 (added)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
 Thu Apr 16 12:13:20 2009
@@ -0,0 +1,45 @@
+/* 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;
+
+/** Represents the Operating System 32-bit pointer C/C++ pointer.
+ * <br/><br/>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * @since Runtime 1.0
+ */
+class Pointer32 extends Pointer {
+
+    private int POINTER;
+    private int CLEANUP;
+
+    private Pointer32(int ptr, int clr)
+    {
+        POINTER = ptr;
+        CLEANUP = clr;
+    }
+
+    public long longValue()
+    {
+        return POINTER;
+    }
+
+    public int intValue()
+        throws ClassCastException
+    {
+        return POINTER;
+    }
+}

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

Added: 
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=765590&view=auto
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
 (added)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
 Thu Apr 16 12:13:20 2009
@@ -0,0 +1,45 @@
+/* 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;
+
+/** Represents the Operating System 32-bit pointer C/C++ pointer.
+ * <br/><br/>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * @since Runtime 1.0
+ */
+class Pointer64 extends Pointer {
+
+    private long POINTER;
+    private long CLEANUP;
+
+    private Pointer64(long ptr, long clr)
+    {
+        POINTER = ptr;
+        CLEANUP = clr;
+    }
+
+    public long longValue()
+    {
+        return POINTER;
+    }
+
+    public int intValue()
+        throws ClassCastException
+    {
+        throw new ClassCastException();
+    }
+}

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

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=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Thu Apr 16 
12:13:20 2009
@@ -69,6 +69,7 @@
        $(SRCDIR)/shared/dbb.$(OBJ) \
        $(SRCDIR)/shared/error.$(OBJ) \
        $(SRCDIR)/shared/memory.$(OBJ) \
+       $(SRCDIR)/shared/pointer.$(OBJ) \
        $(SRCDIR)/shared/string.$(OBJ) \
        $(SRCDIR)/shared/tables.$(OBJ) \
        $(SRCDIR)/shared/version.$(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=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Apr 16 
12:13:20 2009
@@ -63,6 +63,7 @@
        $(SRCDIR)/shared/dbb.$(OBJ) \
        $(SRCDIR)/shared/error.$(OBJ) \
        $(SRCDIR)/shared/memory.$(OBJ) \
+       $(SRCDIR)/shared/pointer.$(OBJ) \
        $(SRCDIR)/shared/string.$(OBJ) \
        $(SRCDIR)/shared/tables.$(OBJ) \
        $(SRCDIR)/shared/version.$(OBJ)

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h?rev=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h Thu Apr 
16 12:13:20 2009
@@ -62,6 +62,22 @@
                                                  acr_cclass_e clazz,
                                                  jsize len);
 
+
+/**
+ * Load and reference the class.
+ * @param env Current JNI environment.
+ * @param clazz Class to load.
+ * @return ACR_SUCCESS on success.
+ */
+ACR_DECLARE(int) ACR_LoadClass(JNIEnv *env, JAVA_C_ID *clazz);
+
+/**
+ * UnLoad and dereference the class.
+ * @param env Current JNI environment.
+ * @param clazz Class to load.
+ */
+ACR_DECLARE(void) ACR_UnloadClass(JNIEnv *env, JAVA_C_ID *clazz);
+
 #ifdef __cplusplus
 }
 #endif

Added: 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=765590&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h Thu Apr 
16 12:13:20 2009
@@ -0,0 +1,53 @@
+/* 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.
+ */
+
+#ifndef _ACR_POINTER_H
+#define _ACR_POINTER_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_pointer.h
+ * @brief
+ *
+ * ACR Pointer class functions
+ *
+ */
+
+/**
+ * Pointer callback function prototype.
+ */
+typedef int (acr_pointer_callback_fn_t)(void *);
+
+/**
+ * Create new Pointer class instance
+ * param env Current JNI environment
+ * param p Native pointer to wrap into Pointer class
+ * param cb callback function to use on Pointer.finalize()
+ */
+ACR_DECLARE(jobject) ACR_CreatePointer(JNIEnv *env, void *p,
+                                       acr_pointer_callback_fn_t *cb);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_POINTER_H */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Thu Apr 
16 12:13:20 2009
@@ -292,6 +292,12 @@
     } else (void)(0)
 
 
+#define GET_IFIELD_J(I, O)  \
+    _f##I##n.i ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
+
+#define GET_IFIELD_I(I, O)  \
+    _f##I##n.i ? (*_E)->GetLongField(_E, (O), _f##I##n.i) : 0
+
 #define SET_IFIELD_J(I, O, V)  \
     if (_f##I##n.i) {                                                       \
         (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)(V));               \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h?rev=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h Thu Apr 
16 12:13:20 2009
@@ -102,6 +102,7 @@
     ACR_EX_ENULL,           /* java/lang/NullPointerException */
     ACR_EX_EINVAL,          /* java/lang/IllegalArgumentException */
     ACR_EX_EINDEX,          /* java/lang/IndexOutOfBoundsException */
+    ACR_EX_ECCAST,          /* java/lang/ClassCastException */
     ACR_EX_EIO,             /* java/io/IOException */
     ACR_EX_ESOCK            /* java/net/SocketException */
 } acr_trowclass_e;

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=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Thu Apr 16 
12:13:20 2009
@@ -173,6 +173,74 @@
         return NULL;
 }
 
+ACR_DECLARE(int) ACR_LoadClass(JNIEnv *_E, JAVA_C_ID *clazz)
+{
+    int rv = ACR_SUCCESS;
+    jobject c;
+    char an[ACR_SBUFF_SIZ];
+
+    if (clazz->i != NULL) {
+        /* Already inited */
+        return rv;
+    }
+    if ((*_E)->EnsureLocalCapacity(_E, 3) < 0) {
+        goto failed;
+    }
+    /* Init class array */
+    sprintf(an, "L%s;", clazz->n);
+    c = (jobject)(*_E)->FindClass(_E, clazz->n);
+    if ((*_E)->ExceptionCheck(_E) || c == NULL) {
+        fprintf(stderr, "Failed  1 %s %p\n", clazz->n, c);
+        fflush(stderr);
+
+        goto failed;
+    }
+    clazz->i = (jclass)(*_E)->NewGlobalRef(_E, c);
+    if ((*_E)->ExceptionCheck(_E) || clazz->i == NULL) {
+        clazz->i = NULL;
+        fprintf(stderr, "Failed  2\n");
+        fflush(stderr);
+        goto failed;
+    }
+    (*_E)->DeleteLocalRef(_E, c);
+
+    /* Init class array */
+    sprintf(an, "L%s;", clazz->n);
+    c = (jobject)(*_E)->FindClass(_E, an);
+    if ((*_E)->ExceptionCheck(_E) || c == NULL) {
+        fprintf(stderr, "Failed  3\n");
+        fflush(stderr);
+        goto failed;
+    }
+    clazz->a = (jclass)(*_E)->NewGlobalRef(_E, c);
+    if ((*_E)->ExceptionCheck(_E) || clazz->a == NULL) {
+        clazz->a = NULL;
+        goto failed;
+        fprintf(stderr, "Failed  4\n");
+        fflush(stderr);
+    }
+    return rv;
+
+failed:
+    if (clazz->i != NULL) {
+        (*_E)->DeleteGlobalRef(_E, clazz->i);
+        clazz->i = NULL;
+    }
+    return ACR_EGENERAL;
+}
+
+ACR_DECLARE(void) ACR_UnloadClass(JNIEnv *_E, JAVA_C_ID *clazz)
+{
+    if (clazz->i != NULL) {
+        (*_E)->DeleteGlobalRef(_E, clazz->i);
+        clazz->i = NULL;
+    }
+    if (clazz->a != NULL) {
+        (*_E)->DeleteGlobalRef(_E, clazz->a);
+        clazz->a = NULL;
+    }
+}
+
 #ifdef ACR_ENABLE_TEST
 /* Just for testing the cache table */
 int acr_clazz_cache_size()

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=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Thu Apr 16 
12:13:20 2009
@@ -29,6 +29,7 @@
     "java/lang/NullPointerException",
     "java/lang/IllegalArgumentException",
     "java/lang/IndexOutOfBoundsException",
+    "java/lang/ClassCastException",
     "java/io/IOException",
     "java/net/SocketException",
     NULL

Added: 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=765590&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Thu Apr 16 
12:13:20 2009
@@ -0,0 +1,143 @@
+/* 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_error.h"
+#include "acr_clazz.h"
+#include "acr_pointer.h"
+
+/**
+ * Pointer class utilities
+ */
+#if CC_SIZEOF_VOIDP == 8
+
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    ACR_CLASS_PATH "Pointer64"
+};
+
+J_DECLARE_F_ID(0000) = {
+    NULL,
+    "POINTER",
+    "J"
+};
+
+J_DECLARE_F_ID(0001) = {
+    NULL,
+    "CLEANUP",
+    "J"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(JJ)V"
+};
+
+#else
+
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    ACR_CLASS_PATH "Pointer32"
+};
+
+J_DECLARE_F_ID(0000) = {
+    NULL,
+    "POINTER",
+    "I"
+};
+
+J_DECLARE_F_ID(0001) = {
+    NULL,
+    "CLEANUP",
+    "I"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(II)V"
+};
+
+#endif
+
+ACR_CLASS_LDEF(Pointer)
+{
+    int rv;
+
+    if ((rv = ACR_LoadClass(_E, &_clazzn)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_IFIELD(0000);
+    J_LOAD_IFIELD(0001);
+    J_LOAD_METHOD(0000);
+
+    return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(Pointer)
+{
+    ACR_UnloadClass(_E, &_clazzn);
+}
+
+#if CC_SIZEOF_VOIDP == 8
+
+ACR_JNI_EXPORT_DECLARE(void, Pointer, cleanup0)(ACR_JNISTDARGS)
+{
+    acr_pointer_callback_fn_t *cleanup;
+    jlong h = GET_IFIELD_J(0000, _O);
+    jlong c = GET_IFIELD_J(0001, _O);
+
+    cleanup = (acr_pointer_callback_fn_t *)((acr_ptr_t)c);
+    if (cleanup) {
+        (*cleanup)((void *)((acr_ptr_t)h));
+    }
+    SET_IFIELD_J(0000, _O, 0);
+}
+
+#else
+
+ACR_JNI_EXPORT_DECLARE(void, Pointer, cleanup0)(ACR_JNISTDARGS)
+{
+    acr_pointer_callback_fn_t *cleanup;
+    jint h = GET_IFIELD_I(0000, _O);
+    jint c = GET_IFIELD_I(0001, _O);
+
+    cleanup = (acr_pointer_callback_fn_t *)((acr_ptr_t)c);
+    if (cleanup) {
+        (*cleanup)((void *)((acr_ptr_t)h));
+    }
+    SET_IFIELD_I(0000, _O, 0);
+}
+
+#endif
+
+ACR_DECLARE(jobject) ACR_CreatePointer(JNIEnv *_E, void *p,
+                                       acr_pointer_callback_fn_t *cb)
+{
+    if (_clazzn.i && _m0000n.i)
+        return (*_E)->NewObject(_E, _clazzn.i, _m0000n.i,
+                                (acr_ptr_t)p, (acr_ptr_t)cb);
+    else
+        return NULL;
+}

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

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=765590&r1=765589&r2=765590&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Thu Apr 16 
12:13:20 2009
@@ -23,6 +23,7 @@
 #include "acr_tables.h"
 #include "acr_vm.h"
 #include "acr_clazz.h"
+#include "acr_pointer.h"
 
 
 /**
@@ -201,3 +202,23 @@
     jobjectArray a = ACR_NewCoreObjectArray(_E, ACR_CC_STRING, d);
     return a;
 }
+
+ACR_CLASS_LDEC(Pointer);
+
+ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test016)(ACR_JNISTDARGS, jint d)
+{
+    ACR_CLASS_LRUN(Pointer);
+    return 0;
+}
+
+static void callback(void *p)
+{
+    fprintf(stderr, "Pointer callback called: %p\n", p);
+    fflush(stderr);
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test017)(ACR_JNISTDARGS, jint d)
+{
+    
+    return  ACR_CreatePointer(_E, (void *)d, callback);
+}

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=765590&r1=765589&r2=765590&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 16 12:13:20 2009
@@ -55,6 +55,8 @@
     private static native int   test013(int d);
     private static native Class test014(int d);
     private static native String[] test015(int d);
+    private static native int   test016(int d);
+    private static native Pointer test017(int d);
 
 
     protected void setUp()
@@ -219,5 +221,23 @@
         assertEquals("Size", 33, a.length);
     }
 
+    public void testClassLoad()
+        throws Exception
+    {
+        // Shuold not be called as last
+        int i = test016(0);
+        assertEquals("Value", 0, i);
+    }
+
+    public void testPointerCb()
+        throws Throwable
+    {
+        // Shuold not be called as last
+        Pointer p = test017(0xcafebabe);
+        assertNotNull("Pointer",p);
+        p.testCleanup();
+        // Second invocation should display (nil)
+        p.testCleanup();
+    }
 
 }


Reply via email to