commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1085267 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/exception/ native/ native/include/acr/ native/os/darwin/ native/os/linux/ native/port/ native/shared/ test/org/apache/co...
Date Fri, 25 Mar 2011 07:26:21 GMT
Author: mturk
Date: Fri Mar 25 07:26:15 2011
New Revision: 1085267

URL: http://svn.apache.org/viewvc?rev=1085267&view=rev
Log:
Add more of the old code

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Os.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/NoSuchObjectException.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/TimeoutException.java   (with props)
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/include/acr/ring.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/darwin/
    commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/port/bsdrand.c   (with props)
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/Native.java
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
    commons/sandbox/runtime/trunk/src/main/native/port/bsdpath.c
    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/shared/string.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java Fri Mar 25 07:26:15 2011
@@ -62,10 +62,9 @@ public final class Native
                 initialized = init0();
             } catch (Throwable t) {
                 // Ignore
-                System.out.println(t.toString());
             }
 
-            if (!Platform.supported()) {
+            if (!Platform.isSupported()) {
                 throw new UnsupportedOperatingSystemException(
                     "Apache Commons Runtime does not support this " +
                     "operating system"

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Os.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Os.java?rev=1085267&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Os.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Os.java Fri Mar 25 07:26:15 2011
@@ -0,0 +1,104 @@
+/* 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.util.EnumSet;
+
+/** Operating system type and version info.
+ *
+ * @since Runtime 1.0
+ *
+ */
+public final class Os
+{
+
+    private Os()
+    {
+        // No class instance
+    }
+
+    /**
+     * Operating system type {@code EnumSet}.
+     */
+    public static final EnumSet<OsType> TYPE;
+
+    /*
+     * Get OS type.
+     * @param type OS type to test.
+     */
+    private static native int init();
+    private static native int get0();
+    private static native int get1();
+    private static native String get2();
+    private static native String get3();
+    private static native String get4();
+    private static native String get5();
+    static {
+        if (init() != 0) {
+            // Cannot happen (tm)
+        }
+        TYPE = OsType.valueOf(get0());
+    }
+    /**
+     * Name of the operating system implementation.
+     */
+    public static String getSysname()
+    {
+        return get2();
+    }
+
+    /**
+     * Network name of this machine.
+     */
+    public static String getNodename()
+    {
+        return get3();
+    }
+
+    /**
+     * Release level of the operating system.
+     */
+    public static String getRelease()
+    {
+        return get4();
+    }
+
+    /**
+     * Version level of the operating system.
+     */
+    public static String getVersion()
+    {
+        return get5();
+    }
+
+    /**
+     * CPU count.
+     */
+    public static int getNumCpu()
+    {
+        return get1();
+    }
+
+    /**
+     * Data model (32 or 64 bit).
+     */
+    public static int getDataModel()
+    {
+        return Platform.DATA_MODEL;
+    }
+
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java Fri Mar 25 07:26:15 2011
@@ -67,16 +67,22 @@ public enum OsType
     DARWIN(     0x20400),
 
     /**
+     * Operating system is of BSD type.
+     * <br/>Defined integer value is: {@code 0x20800}
+     */
+    BSD(        0x20800),
+
+    /**
      * Operating system is Hewlett Packard HP-UX.
      * <br/>Defined integer value is: {@code 0x20800}
      */
-    HPUX(       0x20800),
+    HPUX(       0x21000),
 
     /**
      * Operating system is IBM AIX.
      * <br/>Defined integer value is: {@code 0x21000}
      */
-    AIX(        0x21000);
+    AIX(        0x22000);
 
     private int value;
     private OsType(int v)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java Fri Mar 25 07:26:15 2011
@@ -37,13 +37,17 @@ class Platform
      * The caller should throw the {@code UnsupportedOperatingSystemException}
      * if this call returns {@code false}.
      */
-    public static native boolean supported();
-
+    private static native boolean supported0();
+    public static boolean isSupported()
+    {
+        return supported0();
+    }
     /*
      * Get Platform integer property value.
      */
-    private static native void init0(int[] p);
-    private static final int default_charset()
+    private static native void init0(int cp);
+    private static native void init1(int[] p);
+    private static final int getDefaultCharset()
     {
         int cs;
         try {
@@ -68,8 +72,8 @@ class Platform
     static {
         int [] i = new int[16];
 
-        i[0] = default_charset();
-        init0(i);
+        init0(getDefaultCharset());
+        init1(i);
 
         SIZEOF_INT                      =   i[0];
         SIZEOF_LONG                     =   i[1];

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java Fri Mar 25 07:26:15 2011
@@ -185,21 +185,29 @@ public final class SystemId
             else
                 pid = 0x20401;
         }
-        else if (sys.equals("hpux")) {
+        else if (sys.equals("bsd")) {
             if (cpu.equals("x86"))
                 pid = 0x20800;
+            else if (cpu.equals("x86_64"))
+                pid = 0x20810;
+            else
+                pid = 0x20801;
+        }
+        else if (sys.equals("hpux")) {
+            if (cpu.equals("x86"))
+                pid = 0x21000;
             else if (cpu.equals("ia64"))
-                pid = 0x20811;
+                pid = 0x21011;
             else if (cpu.equals("parisc32"))
-                pid = 0x20802;
+                pid = 0x21002;
             else
-                pid = 0x20812;
+                pid = 0x21012;
         }
         else if (sys.equals("aix")) {
             if (cpu.equals("ppc"))
-                pid = 0x21000;
+                pid = 0x22000;
             else
-                pid = 0x21010;
+                pid = 0x22010;
         }
         return pid;
     }

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/NoSuchObjectException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/NoSuchObjectException.java?rev=1085267&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/NoSuchObjectException.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/NoSuchObjectException.java Fri Mar 25 07:26:15 2011
@@ -0,0 +1,39 @@
+/* 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.exception;
+
+/**
+ * NoSuchObjectException thrown when an attempt is made to
+ * invoke an operation on unexisting operating system {@code object}.
+ * This class mimics the os {@code ENOENT} error.
+ *
+ * @since Runtime 1.0
+ */
+
+public class NoSuchObjectException extends RuntimeException
+{
+
+    public NoSuchObjectException()
+    {
+        super();
+    }
+
+    public NoSuchObjectException(String msg)
+    {
+        super(msg);
+    }
+}

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/TimeoutException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/TimeoutException.java?rev=1085267&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/TimeoutException.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/TimeoutException.java Fri Mar 25 07:26:15 2011
@@ -0,0 +1,42 @@
+/* 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.exception;
+import java.io.IOException;
+
+/**
+ * Exception thrown when a blocking operation times out.  Blocking
+ * operations for which a timeout is specified need a means to
+ * indicate that the timeout has occurred. For many such operations it
+ * is possible to return a value that indicates timeout; when that is
+ * not possible or desirable then {@code TimeoutException} should be
+ * declared and thrown.
+ *
+ * @since Runtime 1.0
+ */
+public class TimeoutException extends IOException
+{
+
+    public TimeoutException()
+    {
+        super();
+    }
+
+    public TimeoutException(String msg)
+    {
+        super(msg);
+    }
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Fri Mar 25 07:26:15 2011
@@ -60,15 +60,18 @@ ASMSOURCES=\
 	@zlib_asm_sources@
 
 UNIX_SOURCES=\
+	$(TOPDIR)/os/unix/init.c \
 	$(TOPDIR)/os/unix/platform.c
 
-
-LINUX_SOURCES=
+LINUX_SOURCES=\
+	$(TOPDIR)/os/linux/os.c
 
 SOLARIS_SOURCES=
 
 BSDX_SOURCES=
 
+DARWIN_SOURCES=
+
 HPUX_SOURCES=
 
 AIX_SOURCES=
@@ -81,6 +84,7 @@ LIBSOURCES=\
 	$(UNIX_SOURCES) \
 	$(@platform@_SOURCES) \
 	$(TOPDIR)/port/bsdpath.c \
+	$(TOPDIR)/port/bsdrand.c \
 	$(TOPDIR)/port/bsdstring.c \
 	$(TOPDIR)/port/bsdsys.c \
 	$(TOPDIR)/shared/clazz.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Fri Mar 25 07:26:15 2011
@@ -450,7 +450,7 @@ case "$host" in
         test ".$cc_set" = .no && cc=cc
     ;;
     darwin   )
-        platform=BSDX
+        platform=DARWIN
         platformver="`uname -r | sed 's/\.//g'`"
     ;;
     *bsd     )
@@ -754,6 +754,7 @@ else
 fi
 varadds includes "-I??(TOPDIR)/os/unix"
 test ".$has_legacy_code" = .yes && varadds cppopts -DENABLE_LEGACY_CODE
+test ".$has_test_private" = .yes && varadds cppopts -DENABLE_TEST_PRIVATE
 if [ ".$has_maintainer_mode" = .yes ]; then
     varadds cppopts -DDEBUG -D_DEBUG
 else
@@ -786,12 +787,6 @@ elif [ ".$has_posix_mutex" = .yes ]; the
 else
     varadds cppopts -DUSE_FCNTL_MUTEX
 fi
-if [ ".$has_test_private" = .yes ]; then
-    varadds cppopts -DENABLE_TESTPRIVATE
-    testobjects='$(TEST_OBJECTS)'
-else
-    testobjects=""
-fi
 varadds cppopts -DOCPR_API_EXPORT
 if [ ".$has_shared_version" = .yes ]; then
     sharedlib='$(SHAREDLIB)'
@@ -1475,7 +1470,6 @@ sed -e 's|@host@|'"$host"'|g' \
     -e 's|@bits@|'"$bits"'|g' \
     -e 's|@topdir@|'"$topdir"'|g' \
     -e 's|@platform@|'"$platform"'|g' \
-    -e 's|@testobjects@|'"$testobjects"'|g' \
     -e 's|@modules@|'"$modules"'|g' \
     -e 's|@sharedlib@|'"$sharedlib"'|g' \
     -e 's|@linkedlib@|'"$linkedlib"'|g' \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Fri Mar 25 07:26:15 2011
@@ -54,13 +54,9 @@ enum {
     ACR_EX_ENOTFOUND,       /* java/io/FileNotFoundException */
     ACR_EX_ESYNC,           /* java/io/SyncFailedException */
     ACR_EX_ESOCK,           /* java/net/SocketException */
-    ACR_EX_CLOSED_DESC,     /* exception/ClosedDescriptorException */
-    ACR_EX_ACLOSED_DESC,    /* exception/AsyncClosedDescriptorException */
-    ACR_EX_INVALID_DESC,    /* exception/InvalidDescriptorException */
     ACR_EX_ENOENT,          /* exception/NoSuchObjectException */
     ACR_EX_OSERR,           /* exception/OperatingSystemException */
     ACR_EX_ETIMEOUT,        /* exception/TimeoutException */
-    ACR_EX_UNALIGNED,       /* exception/UnalignedMemoryException */
     ACR_EX_UNSUPPORTED,     /* exception/UnsupportedOperatingSystemException */
     ACR_EX_LEN
 };

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h?rev=1085267&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h Fri Mar 25 07:26:15 2011
@@ -0,0 +1,47 @@
+/* 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_JNIAPI_H_
+#define _ACR_JNIAPI_H_
+
+#include "acr/jnitypes.h"
+#include "acr/ring.h"
+
+/**
+ * The prototype for any ACR thread local storage destructor function.
+ */
+typedef void (*acr_tls_destructor_t)(const void *, void *);
+typedef struct acr_tlsd_t  {
+    ACR_RING_ENTRY(acr_tlsd_t)  link;
+    const void                  *key;
+    void                        *val;
+    /** Destroy callback.
+     * If NULL pr_mfree(val) will be called
+     */
+    acr_tls_destructor_t        dtor;
+} acr_tlsd_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEnv *
+AcrGetJNIEnv(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _ACR_JNIAPI_H_ */

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

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h Fri Mar 25 07:26:15 2011
@@ -37,6 +37,8 @@
 
 #define JNI_STDARGS             JNIEnv *_E, jobject _O
 #define JNI_STDENV              JNIEnv *_E
+#define UNREFERENCED_STDARGS    _E = _E; _O = _O
+#define UNREFERENCED_OBJECT     _O = _O
 
 #define LLT(X)                  ((acr_intptr_t)(X))
 #if CC_SIZEOF_VOIDP == 8
@@ -52,10 +54,10 @@
 #define V2I(P)                  ((int)(acr_intptr_t)(P))
 #define V2U(P)                  ((unsigned int)(acr_uintptr_t)(P))
 
-#define ACR_CLASS_LOADER(CL)                        \
+#define ACR_CLASS_CTOR(CL)                          \
     int acr_class_##CL##_load(JNIEnv *_E)
 
-#define ACR_CLASS_UNLOADER(CL)                      \
+#define ACR_CLASS_DTOR(CL)                          \
     void acr_class_##CL##_unload(JNIEnv *_E)
 
 #define ACR_CLASS_DECLARE(CL)                       \
@@ -65,7 +67,7 @@
 #define ACR_CLASS_LOAD(CL)                          \
     if (acr_class_##CL##_load(_E)) return 1;
 
-#define ACR_CLASS_UNLOAD(CL)                          \
+#define ACR_CLASS_UNLOAD(CL)                        \
     acr_class_##CL##_unload(_E)
 
 #define J_DECLARE_CLAZZ   static JAVA_C_ID _clazzn
@@ -75,4 +77,15 @@
 
 #define IF_CLAZZ_LOADED() if (_clazzn.i != NULL && _m0000n.i != NULL)
 
+#define UTF8_TO_JSTRING(V)      AcrNewJavaStringU(_E, (const char *)(V))
+#define CSTR_TO_JSTRING(V)      AcrNewJavaStringA(_E, (const char *)(V))
+#define WSTR_TO_JSTRING(V)      AcrNewJavaStringW(_E, (const wchar_t *)(V))
+#if defined(_WINDOWS)
+#define PSTR_TO_JSTRING(V)      AcrNewJavaStringW(_E, (const wchar_t *)(V))
+#define _PTEXT(X)               L ## X
+#else
+#define PSTR_TO_JSTRING(V)      AcrNewJavaStringU(_E, (const char *)(V))
+#define _PTEXT(X)               X
+#endif
+
 #endif /* _ACR_JNIDEFS_H_ */

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h Fri Mar 25 07:26:15 2011
@@ -58,13 +58,17 @@ AcrMemoryAbort(JNI_STDENV, int retcode, 
                const char *filename, const char *funcname, int lineno);
 
 void *
-AcrDebugMalloc(JNIEnv *_E, size_t size,
+AcrDebugMalloc(JNI_STDENV, size_t size,
                const char *filename, const char *funcname, int lineno);
 void *
-AcrDebugCalloc(JNIEnv *_E, size_t size,
+AcrDebugCalloc(JNI_STDENV, size_t size,
                const char *filename, const char *funcname, int lineno);
 
 void *
+AcrDebugRealloc(JNI_STDENV, void *mem, size_t size,
+                const char *filename, const char *funcname, int lineno);
+
+void *
 AcrMalloc(JNI_STDENV, size_t size);
 
 void *

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/port.h Fri Mar 25 07:26:15 2011
@@ -35,7 +35,7 @@ char   *_bsd_strsignal(int);
 # define strsignal      _bsd_strsignal
 #endif
 
-const char  *_bsd_basename_c(const char *);
+const char  *basename_c(const char *);
 char *_bsd_basename_r(const char *, char *, size_t);
 #if !HAVE_BASENAME_R
 # define basename_r     _bsd_basename_r
@@ -48,6 +48,10 @@ size_t      _bsd_getpagesize(void);
 #if !HAVE_GETPAGESIZE
 # define getpagesize    _bsd_getpagesize
 #endif
+unsigned int _bsd_arc4random(void);
+#if !HAVE_ARC4RANDOM
+# define arc4random     _bsd_arc4random
+#endif
 
 #ifdef __cplusplus
 }

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/ring.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/ring.h?rev=1085267&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/ring.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/ring.h Fri Mar 25 07:26:15 2011
@@ -0,0 +1,406 @@
+/* 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.
+ */
+
+/*
+ * This code draws heavily from the 4.4BSD <sys/queue.h> macros
+ * and Dean Gaudet's "splim/ring.h".
+ * <http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/queue.h>
+ * <http://www.arctic.org/~dean/splim/>
+ *
+ * We'd use Dean's code directly if we could guarantee the
+ * availability of inline functions.
+ */
+
+#ifndef _ACR_RING_H_
+#define _ACR_RING_H_
+
+#include "acr/stdtypes.h"
+
+/**
+ * @file ring.h
+ * @brief ACR rings
+ */
+
+/**
+ * @defgroup ring Ring Macro Implementations
+ * @ingroup ACR
+ * A ring is a kind of doubly-linked list that can be manipulated
+ * without knowing where its head is.
+ * @{
+ */
+
+/**
+ * The Ring Element
+ *
+ * A ring element struct is linked to the other elements in the ring
+ * through its ring entry field, e.g.
+ * <pre>
+ *      struct my_element_t {
+ *          ACR_RING_ENTRY(my_element_t) link;
+ *          int foo;
+ *          char *bar;
+ *      };
+ * </pre>
+ *
+ * An element struct may be put on more than one ring if it has more
+ * than one ACR_RING_ENTRY field. Each ACR_RING_ENTRY has a corresponding
+ * ACR_RING_HEAD declaration.
+ *
+ * @warning For strict C standards compliance you should put the
+ * ACR_RING_ENTRY first in the element struct unless the head is always
+ * part of a larger object with enough earlier fields to accommodate the
+ * offsetof() used to compute the ring sentinel below.
+ * You can usually ignore this caveat.
+ */
+#define ACR_RING_ENTRY(elem)                                                \
+    struct {                                                                \
+        struct elem * volatile next;                                        \
+        struct elem * volatile prev;                                        \
+    }
+
+/**
+ * The Ring Head
+ *
+ * Each ring is managed via its head, which is a struct declared like this:
+ * <pre>
+ *      ACR_RING_HEAD(my_ring_t, my_element_t);
+ *      struct my_ring_t ring, *ringp;
+ * </pre>
+ *
+ * This struct looks just like the element link struct so that we can
+ * be sure that the typecasting games will work as expected.
+ *
+ * The first element in the ring is next after the head, and the last
+ * element is just before the head.
+ */
+#define ACR_RING_HEAD(head, elem)                                           \
+    struct head {                                                           \
+        struct elem *next;                                                  \
+        struct elem *prev;                                                  \
+    }
+
+/**
+ * The Ring Sentinel
+ *
+ * This is the magic pointer value that occurs before the first and
+ * after the last elements in the ring, computed from the address of
+ * the ring's head.  The head itself isn't an element, but in order to
+ * get rid of all the special cases when dealing with the ends of the
+ * ring, we play typecasting games to make it look like one.
+ *
+ * Here is a diagram to illustrate the arrangements of the next and
+ * prev pointers of each element in a single ring. Note that they point
+ * to the start of each element, not to the ACR_RING_ENTRY structure.
+ *
+ * <pre>
+ *     +->+------+<-+  +->+------+<-+  +->+------+<-+
+ *     |  |struct|  |  |  |struct|  |  |  |struct|  |
+ *    /   | elem |   \/   | elem |   \/   | elem |  \
+ * ...    |      |   /\   |      |   /\   |      |   ...
+ *        +------+  |  |  +------+  |  |  +------+
+ *   ...--|prev  |  |  +--|ring  |  |  +--|prev  |
+ *        |  next|--+     | entry|--+     |  next|--...
+ *        +------+        +------+        +------+
+ *        | etc. |        | etc. |        | etc. |
+ *        :      :        :      :        :      :
+ * </pre>
+ *
+ * The ACR_RING_HEAD is nothing but a bare ACR_RING_ENTRY. The prev
+ * and next pointers in the first and last elements don't actually
+ * point to the head, they point to a phantom place called the
+ * sentinel. Its value is such that last->next->next == first because
+ * the offset from the sentinel to the head's next pointer is the same
+ * as the offset from the start of an element to its next pointer.
+ * This also works in the opposite direction.
+ *
+ * <pre>
+ *        last                            first
+ *     +->+------+<-+  +->sentinel<-+  +->+------+<-+
+ *     |  |struct|  |  |            |  |  |struct|  |
+ *    /   | elem |   \/              \/   | elem |  \
+ * ...    |      |   /\              /\   |      |   ...
+ *        +------+  |  |  +------+  |  |  +------+
+ *   ...--|prev  |  |  +--|ring  |  |  +--|prev  |
+ *        |  next|--+     |  head|--+     |  next|--...
+ *        +------+        +------+        +------+
+ *        | etc. |                        | etc. |
+ *        :      :                        :      :
+ * </pre>
+ *
+ * Note that the offset mentioned above is different for each kind of
+ * ring that the element may be on, and each kind of ring has a unique
+ * name for its ACR_RING_ENTRY in each element, and has its own type
+ * for its ACR_RING_HEAD.
+ *
+ * Note also that if the offset is non-zero (which is required if an
+ * element has more than one ACR_RING_ENTRY), the unreality of the
+ * sentinel may have bad implications on very perverse implementations
+ * of C -- see the warning in ACR_RING_ENTRY.
+ *
+ * @param hp   The head of the ring
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_SENTINEL(hp, elem, link)                                    \
+    (struct elem *)((char *)(&(hp)->next) - ACR_OFFSETOF(struct elem, link))
+
+/**
+ * The first element of the ring
+ * @param hp   The head of the ring
+ */
+#define ACR_RING_FIRST(hp)      (hp)->next
+/**
+ * The last element of the ring
+ * @param hp   The head of the ring
+ */
+#define ACR_RING_LAST(hp)       (hp)->prev
+/**
+ * The next element in the ring
+ * @param ep   The current element
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_NEXT(ep, link) (ep)->link.next
+/**
+ * The previous element in the ring
+ * @param ep   The current element
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_PREV(ep, link) (ep)->link.prev
+
+
+/**
+ * Initialize a ring
+ * @param hp   The head of the ring
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_INIT(hp, elem, link) do {                                  \
+        ACR_RING_FIRST((hp)) = ACR_RING_SENTINEL((hp), elem, link);         \
+        ACR_RING_LAST((hp))  = ACR_RING_SENTINEL((hp), elem, link);         \
+    } while (0)
+
+/**
+ * Determine if a ring is empty
+ * @param hp   The head of the ring
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ * @return true or false
+ */
+#define ACR_RING_EMPTY(hp, elem, link)                                      \
+    (ACR_RING_FIRST((hp)) == ACR_RING_SENTINEL((hp), elem, link))
+
+/**
+ * Initialize a singleton element
+ * @param ep   The element
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_ELEM_INIT(ep, link) do {                                   \
+        ACR_RING_NEXT((ep), link) = (ep);                                   \
+        ACR_RING_PREV((ep), link) = (ep);                                   \
+    } while (0)
+
+
+/**
+ * Splice the sequence ep1..epN into the ring before element lep
+ *   (..lep.. becomes ..ep1..epN..lep..)
+ * @warning This doesn't work for splicing before the first element or on
+ *   empty rings... see ACR_RING_SPLICE_HEAD for one that does
+ * @param lep  Element in the ring to splice before
+ * @param ep1  First element in the sequence to splice in
+ * @param epN  Last element in the sequence to splice in
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_SPLICE_BEFORE(lep, ep1, epN, link) do {                    \
+        ACR_RING_NEXT((epN), link) = (lep);                                 \
+        ACR_RING_PREV((ep1), link) = ACR_RING_PREV((lep), link);            \
+        ACR_RING_NEXT(ACR_RING_PREV((lep), link), link) = (ep1);            \
+        ACR_RING_PREV((lep), link) = (epN);                                 \
+    } while (0)
+
+/**
+ * Splice the sequence ep1..epN into the ring after element lep
+ *   (..lep.. becomes ..lep..ep1..epN..)
+ * @warning This doesn't work for splicing after the last element or on
+ *   empty rings... see ACR_RING_SPLICE_TAIL for one that does
+ * @param lep  Element in the ring to splice after
+ * @param ep1  First element in the sequence to splice in
+ * @param epN  Last element in the sequence to splice in
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_SPLICE_AFTER(lep, ep1, epN, link) do {                     \
+        ACR_RING_PREV((ep1), link) = (lep);                                 \
+        ACR_RING_NEXT((epN), link) = ACR_RING_NEXT((lep), link);            \
+        ACR_RING_PREV(ACR_RING_NEXT((lep), link), link) = (epN);            \
+        ACR_RING_NEXT((lep), link) = (ep1);                                 \
+    } while (0)
+
+/**
+ * Insert the element nep into the ring before element lep
+ *   (..lep.. becomes ..nep..lep..)
+ * @warning This doesn't work for inserting before the first element or on
+ *   empty rings... see ACR_RING_INSERT_HEAD for one that does
+ * @param lep  Element in the ring to insert before
+ * @param nep  Element to insert
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_INSERT_BEFORE(lep, nep, link)                              \
+        ACR_RING_SPLICE_BEFORE((lep), (nep), (nep), link)
+
+/**
+ * Insert the element nep into the ring after element lep
+ *   (..lep.. becomes ..lep..nep..)
+ * @warning This doesn't work for inserting after the last element or on
+ *   empty rings... see ACR_RING_INSERT_TAIL for one that does
+ * @param lep  Element in the ring to insert after
+ * @param nep  Element to insert
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_INSERT_AFTER(lep, nep, link)                               \
+        ACR_RING_SPLICE_AFTER((lep), (nep), (nep), link)
+
+
+/**
+ * Splice the sequence ep1..epN into the ring before the first element
+ *   (..hp.. becomes ..hp..ep1..epN..)
+ * @param hp   Head of the ring
+ * @param ep1  First element in the sequence to splice in
+ * @param epN  Last element in the sequence to splice in
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_SPLICE_HEAD(hp, ep1, epN, elem, link)                      \
+        ACR_RING_SPLICE_AFTER(ACR_RING_SENTINEL((hp), elem, link),          \
+                             (ep1), (epN), link)
+
+/**
+ * Splice the sequence ep1..epN into the ring after the last element
+ *   (..hp.. becomes ..ep1..epN..hp..)
+ * @param hp   Head of the ring
+ * @param ep1  First element in the sequence to splice in
+ * @param epN  Last element in the sequence to splice in
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_SPLICE_TAIL(hp, ep1, epN, elem, link)                      \
+        ACR_RING_SPLICE_BEFORE(ACR_RING_SENTINEL((hp), elem, link),         \
+                             (ep1), (epN), link)
+
+/**
+ * Insert the element nep into the ring before the first element
+ *   (..hp.. becomes ..hp..nep..)
+ * @param hp   Head of the ring
+ * @param nep  Element to insert
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_INSERT_HEAD(hp, nep, elem, link)                           \
+        ACR_RING_SPLICE_HEAD((hp), (nep), (nep), elem, link)
+
+/**
+ * Insert the element nep into the ring after the last element
+ *   (..hp.. becomes ..nep..hp..)
+ * @param hp   Head of the ring
+ * @param nep  Element to insert
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_INSERT_TAIL(hp, nep, elem, link)                           \
+        ACR_RING_SPLICE_TAIL((hp), (nep), (nep), elem, link)
+
+/**
+ * Concatenate ring h2 onto the end of ring h1, leaving h2 empty.
+ * @param h1   Head of the ring to concatenate onto
+ * @param h2   Head of the ring to concatenate
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_CONCAT(h1, h2, elem, link) do {                            \
+        if (!ACR_RING_EMPTY((h2), elem, link)) {                            \
+            ACR_RING_SPLICE_BEFORE(ACR_RING_SENTINEL((h1), elem, link),     \
+                                  ACR_RING_FIRST((h2)),                     \
+                                  ACR_RING_LAST((h2)), link);               \
+            ACR_RING_INIT((h2), elem, link);                                \
+        }                                                                   \
+    } while (0)
+
+/**
+ * Prepend ring h2 onto the beginning of ring h1, leaving h2 empty.
+ * @param h1   Head of the ring to prepend onto
+ * @param h2   Head of the ring to prepend
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_PREPEND(h1, h2, elem, link) do {                           \
+        if (!ACR_RING_EMPTY((h2), elem, link)) {                            \
+            ACR_RING_SPLICE_AFTER(ACR_RING_SENTINEL((h1), elem, link),      \
+                                  ACR_RING_FIRST((h2)),                     \
+                                  ACR_RING_LAST((h2)), link);               \
+            ACR_RING_INIT((h2), elem, link);                                \
+        }                                                                   \
+    } while (0)
+
+/**
+ * Unsplice a sequence of elements from a ring
+ * @warning The unspliced sequence is left with dangling pointers at either end
+ * @param ep1  First element in the sequence to unsplice
+ * @param epN  Last element in the sequence to unsplice
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_UNSPLICE(ep1, epN, link) do {                              \
+        ACR_RING_NEXT(ACR_RING_PREV((ep1), link), link) =                   \
+                     ACR_RING_NEXT((epN), link);                            \
+        ACR_RING_PREV(ACR_RING_NEXT((epN), link), link) =                   \
+                     ACR_RING_PREV((ep1), link);                            \
+    } while (0)
+
+/**
+ * Remove a single element from a ring
+ * @warning The unspliced element is left with dangling pointers at either end
+ * @param ep   Element to remove
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_REMOVE(ep, link)                                           \
+    ACR_RING_UNSPLICE((ep), (ep), link)
+
+/**
+ * Iterate over a ring
+ * @param ep The current element
+ * @param head The head of the ring
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_FOREACH(ep, head, elem, link)                              \
+    for (ep = ACR_RING_FIRST(head);                                         \
+         ep != ACR_RING_SENTINEL(head, elem, link);                         \
+         ep = ACR_RING_NEXT(ep, link))
+
+/**
+ * Iterate over a ring safe against removal of the current element
+ * @param ep1 The current element
+ * @param ep2 Iteration cursor
+ * @param head The head of the ring
+ * @param elem The name of the element struct
+ * @param link The name of the ACR_RING_ENTRY in the element struct
+ */
+#define ACR_RING_FOREACH_SAFE(ep1, ep2, head, elem, link)                   \
+    for (ep1 = ACR_RING_FIRST(head), ep2 = ACR_RING_NEXT(ep1, link);        \
+         ep1 != ACR_RING_SENTINEL(head, elem, link);                        \
+         ep1 = ep2, ep2 = ACR_RING_NEXT(ep1, link))
+
+/** @} */
+
+#endif /* !_ACR_RING_H_ */
+

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

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h Fri Mar 25 07:26:15 2011
@@ -272,4 +272,14 @@
 #define ISIZEOF(s)           ((int)sizeof(s))
 #define TSIZEOF(t, s)        ((t)sizeof(s))
 
+#define ACR_OS_WINDOWS          0x10000
+#define ACR_OS_WIN64            0x10010
+#define ACR_OS_WOW64            0x10020
+#define ACR_OS_UNIX             0x20000
+#define ACR_OS_LINUX            0x20100
+#define ACR_OS_SOLARIS          0x20200
+#define ACR_OS_DARWIN           0x20400
+#define ACR_OS_HPUX             0x20800
+#define ACR_OS_AIX              0x21000
+
 #endif /* _ACR_STDDEFS_H_ */

Added: commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c?rev=1085267&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c Fri Mar 25 07:26:15 2011
@@ -0,0 +1,84 @@
+/* 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.
+ */
+
+#include "acr/jniapi.h"
+#include "acr/string.h"
+#include <sys/utsname.h>
+
+static int            _sys_done = -1;
+static struct utsname _sys_buf;
+static int            _sys_ncpu = 0;
+static const char     _unknown[] = "unknown";
+
+ACR_JNI_EXPORT(jint, Os, get0)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    return ACR_OS_LINUX;
+}
+
+ACR_JNI_EXPORT(jint, Os, get1)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    if (_sys_ncpu == 0) {
+        long nc = sysconf(_SC_NPROCESSORS_CONF);
+        if (nc == -1)
+            _sys_ncpu = 1;
+        else
+            _sys_ncpu = (int)nc;
+    }
+    return _sys_ncpu;
+}
+
+ACR_JNI_EXPORT(jint, Os, init)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    if (_sys_done == 0)
+        return 0;
+    _sys_done = uname(&_sys_buf);
+    if (_sys_done)
+        return errno;
+    else
+        return 0;
+}
+
+ACR_JNI_EXPORT(jstring, Os, get2)(JNI_STDARGS)
+{
+    return CSTR_TO_JSTRING("linux");
+}
+
+ACR_JNI_EXPORT(jstring, Os, get3)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.nodename);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}
+
+ACR_JNI_EXPORT(jstring, Os, get4)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.release);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}
+
+ACR_JNI_EXPORT(jstring, Os, get5)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.version);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/native/port/bsdpath.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/port/bsdpath.c?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/port/bsdpath.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/port/bsdpath.c Fri Mar 25 07:26:15 2011
@@ -25,7 +25,7 @@
 #define NO_PSA(c) ((c) !=  '/')
 #endif
 
-const char *_bsd_basename_c(const char *path)
+const char *basename_c(const char *path)
 {
     const char *endp, *startp;
 
@@ -58,7 +58,7 @@ char *_bsd_basename_r(const char *path, 
         bname = sbuf;
         blen  = sizeof(sbuf);
     }
-    basep = _bsd_basename_c(path);
+    basep = basename_c(path);
     len = strlen(basep) + 1;
     if (len > blen) {
         ACR_SET_OS_ERROR(ACR_ENAMETOOLONG);

Added: commons/sandbox/runtime/trunk/src/main/native/port/bsdrand.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/port/bsdrand.c?rev=1085267&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/port/bsdrand.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/port/bsdrand.c Fri Mar 25 07:26:15 2011
@@ -0,0 +1,177 @@
+/* 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.
+ */
+
+/*
+ * Arc4 random number generator for OpenBSD.
+ * Copyright 1996 David Mazieres <dm@lcs.mit.edu>.
+ *
+ * Modification and redistribution in source and binary forms is
+ * permitted provided that due credit is given to the author and the
+ * OpenBSD project by leaving this copyright notice intact.
+ */
+
+/*
+ * This code is derived from section 17.1 of Applied Cryptography,
+ * second edition, which describes a stream cipher allegedly
+ * compatible with RSA Labs "RC4" cipher (the actual description of
+ * which is a trade secret).  The same algorithm is used as a stream
+ * cipher called "arcfour" in Tatu Ylonen's ssh package.
+ *
+ * Here the stream cipher has been modified always to include the time
+ * when initializing the state.  That makes it impossible to
+ * regenerate the same random sequence twice, so this can't be used
+ * for encryption, but will generate good random numbers.
+ *
+ * RC4 is a registered trademark of RSA Laboratories.
+ */
+
+#include "acr/port.h"
+#include "acr/error.h"
+#include "arch_defs.h"
+
+#if !defined(_WINDOWS)
+#include <sys/time.h>
+#else
+#include <wincrypt.h>
+#endif
+
+struct arc4_stream {
+    unsigned char i;
+    unsigned char j;
+    unsigned char s[256];
+};
+
+static int rs_initialized;
+static struct arc4_stream rs;
+
+ACR_INLINE(void)
+arc4_init(struct arc4_stream *as)
+{
+    int n;
+
+    for (n = 0; n < 256; n++)
+        as->s[n] = n;
+    as->i = 0;
+    as->j = 0;
+}
+
+ACR_INLINE(void)
+arc4_addrandom(struct arc4_stream *as, unsigned char *dat, int datlen)
+{
+    int            n;
+    unsigned char si;
+
+    as->i--;
+    for (n = 0; n < 256; n++) {
+        as->i = (as->i + 1);
+        si = as->s[as->i];
+        as->j = (as->j + si + dat[n % datlen]);
+        as->s[as->i] = as->s[as->j];
+        as->s[as->j] = si;
+    }
+    as->j = as->i;
+}
+
+ACR_INLINE(char)
+arc4_getbyte(struct arc4_stream *as)
+{
+    unsigned char si, sj;
+
+    as->i = (as->i + 1);
+    si    = as->s[as->i];
+    as->j = (as->j + si);
+    sj    = as->s[as->j];
+    as->s[as->i] = sj;
+    as->s[as->j] = si;
+    return as->s[(si + sj) & 0xff];
+}
+
+ACR_INLINE(acr_uint32_t)
+arc4_getword(struct arc4_stream *as)
+{
+    acr_uint32_t val;
+    val  = arc4_getbyte(as) << 24;
+    val |= arc4_getbyte(as) << 16;
+    val |= arc4_getbyte(as) <<  8;
+    val |= arc4_getbyte(as);
+    return val;
+}
+
+static void arc4_stir(struct arc4_stream *as)
+{
+    int n;
+
+#if defined (_WINDOWS)
+    struct {
+        SYSTEMTIME tv;
+        unsigned int rnd[(128 - sizeof(SYSTEMTIME)) / sizeof(unsigned int)];
+    } rdat;
+    HCRYPTPROV hProv;
+
+    GetSystemTime(&rdat.tv);
+    if (CryptAcquireContext(&hProv, 0, 0, PROV_RSA_FULL,
+                            CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
+        /* XXX: An ugly hack for Win64, randomness is such that noone should
+         * ever expect > 2^31 bytes of data at once without the prng
+         * coming to a complete halt.
+         */
+        CryptGenRandom(hProv, TSIZEOF(DWORD, rdat.rnd), (unsigned char *)rdat.rnd);
+        CryptReleaseContext(hProv, 0);
+    }
+#else
+    int fd;
+    struct {
+        struct timeval tv;
+        unsigned int rnd[(128 - sizeof(struct timeval)) / sizeof(unsigned int)];
+    } rdat;
+
+    gettimeofday(&rdat.tv, 0);
+    fd = open(DEV_RANDOM, O_RDONLY);
+    if (fd != -1) {
+        read(fd, rdat.rnd, sizeof(rdat.rnd));
+        close(fd);
+    }
+#endif
+    /* fd < 0 or failed sysctl ?  Ah, what the heck. We'll just take
+     * whatever was on the stack... */
+
+    arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
+
+    /*
+     * Throw away the first N words of output, as suggested in the
+     * paper "Weaknesses in the Key Scheduling Algorithm of RC4"
+     * by Fluher, Mantin, and Shamir.  (N = 256 in our case.)
+     */
+    for (n = 0; n < 256 * 4; n++)
+        arc4_getbyte(as);
+}
+
+static void arc4_random_stir(void)
+{
+    if (!rs_initialized) {
+        arc4_init(&rs);
+        rs_initialized = 1;
+    }
+    arc4_stir(&rs);
+}
+
+unsigned int _bsd_arc4random()
+{
+    if (!rs_initialized)
+        arc4_random_stir();
+    return arc4_getword(&rs);
+}
+

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

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=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Fri Mar 25 07:26:15 2011
@@ -149,7 +149,7 @@ static struct {
     { NULL,                         NULL }
 };
 
-ACR_CLASS_LOADER(Class)
+ACR_CLASS_CTOR(Class)
 {
     int rv;
 

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=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Mar 25 07:26:15 2011
@@ -17,6 +17,32 @@
 #include "acr/error.h"
 #include "acr/port.h"
 
+static const char *_throw_classes[] = {
+    "java/lang/Exception",
+    "java/lang/RuntimeException",
+    "java/lang/OutOfMemoryError",
+    "java/lang/NullPointerException",
+    "java/lang/IllegalArgumentException",
+    "java/lang/IllegalStateException",
+    "java/lang/IndexOutOfBoundsException",
+    "java/lang/ClassCastException",
+    "java/lang/InstantiationException",
+    "java/lang/InternalError",
+    "java/lang/SecurityException",
+    "java/lang/UnsatisfiedLinkError",
+    "java/lang/UnsupportedOperationException",
+    "java/io/IOException",
+    "java/io/InterruptedIOException",
+    "java/io/FileNotFoundException",
+    "java/io/SyncFailedException",
+    "java/net/SocketException",
+    ACR_EXCEPTION_CP "NoSuchObjectException",
+    ACR_EXCEPTION_CP "OperatingSystemException",
+    ACR_EXCEPTION_CP "TimeoutException",
+    ACR_EXCEPTION_CP "UnsupportedOperatingSystemException",
+    0
+};
+
 static const char *const _canon_errors[] = {
     "Undefined error: 0",                       /*  0 - ENOERROR */
     "Operation not permitted",                  /*  1 - EPERM */
@@ -484,7 +510,7 @@ AcrFatalError(const char *file, const ch
         if (msg)
             fputs(", ", stderr);
         fprintf(stderr, "file %s, line #%d, func %s." ACR_CRLF,
-                _bsd_basename_c(file), line, func);
+                basename_c(file), line, func);
     }
     else {
         fputs("." ACR_CRLF, stderr);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Fri Mar 25 07:26:15 2011
@@ -18,27 +18,25 @@
 #include "acr/memory.h"
 #include "acr/clazz.h"
 
-int acr_native_codepage;
-
 J_DECLARE_CLAZZ = {
-    NULL,
-    NULL,
+    0,
+    0,
     "java/lang/String"
 };
 
 J_DECLARE_M_ID(0000) = {
-    NULL,
+    0,
     "<init>",
     "([B)V"
 };
 
 J_DECLARE_M_ID(0001) = {
-    NULL,
+    0,
     "getBytes",
     "()[B"
 };
 
-ACR_CLASS_LOADER(String)
+ACR_CLASS_CTOR(String)
 {
     int rv;
 
@@ -50,7 +48,7 @@ ACR_CLASS_LOADER(String)
     return ACR_SUCCESS;
 }
 
-ACR_CLASS_UNLOADER(String)
+ACR_CLASS_DTOR(String)
 {
     AcrUnloadClass(_E, &_clazzn);
 }
@@ -58,19 +56,22 @@ ACR_CLASS_UNLOADER(String)
 static const char *iso_8859_1_aliases[] = {
     "iso-8859-1", "iso_8859-1", "iso_8859_1", "8859-1", "8859_1",
     "iso8859-1", "iso8859_1 ", "latin1", "ibm-819", "ibm819",
-    "cp819", "819", "28591", "windows-28591", NULL
+    "cp819", "819", "28591", "windows-28591", 0
 };
 
 static const char *utf_8_aliases[] = {
-    "utf8", "utf-8", "cp1208", "65001", "windows-65001", NULL
+    "utf8", "utf-8", "cp1208", "65001", "windows-65001", 0
 };
 
 static const char *us_ascii_aliases[] = {
     "us-ascii", "ascii", "ascii7", "iso646-us", "us", "ibm367",
-    "cp367", "ansi_x3.4-1968", "646", "646us", "windows-20127", NULL
+    "cp367", "ansi_x3.4-1968", "646", "646us", "windows-20127", 0
 };
 
 int
+acr_native_codepage = -1;
+
+int
 AcrGetNativeCodePage(const char *cs)
 {
     int i;
@@ -95,24 +96,24 @@ static char *get_string_iso_8859_1(JNIEn
 {
     jsize sl;
     const jchar *sr;
-    char *rv = NULL;
+    char *rv = 0;
 
     sl = (*_E)->GetStringLength(_E, str);
     if (b && sl < ACR_MBUFF_LEN)
         rv = b;
     else {
         rv = ACR_MALLOC(char, sl + 1);
-        if (rv == NULL) {
+        if (rv == 0) {
             /* Exception has already neen throw from AcrMalloc
              */
-            return NULL;
+            return 0;
         }
     }
-    sr = (*_E)->GetStringCritical(_E, str, NULL);
+    sr = (*_E)->GetStringCritical(_E, str, 0);
     if (!sr) {
         if (rv != b)
             AcrFree(rv);
-        return NULL;
+        return 0;
     }
     else {
         jsize i;
@@ -599,12 +600,12 @@ AcrUtf8ToUcs2(JNIEnv *_E, const char *st
     out = len = (jsize)strlen(str) + 1;
     dst = ACR_MALLOC(jchar, len);
     if (!dst)
-        return NULL;
+        return 0;
     if ((rc = java_utf8_to_ucs2(str, len, dst, &out))) {
         /* Invalid UTF-8 string */
         AcrFree(dst);
         ACR_SET_OS_ERROR(rc);
-        return NULL;
+        return 0;
     }
     return dst;
 }
@@ -619,12 +620,12 @@ AcrUtf8ToWcs(JNIEnv *_E, const char *str
     out = len = strlen(str) + 1;
     dst = ACR_MALLOC(wchar_t, len);
     if (!dst)
-        return NULL;
+        return 0;
     if ((rc = conv_utf8_to_wcs(str, len, dst, &out))) {
         /* Invalid UTF-8 string */
         AcrFree(dst);
         ACR_SET_OS_ERROR(rc);
-        return NULL;
+        return 0;
     }
     return dst;
 }
@@ -639,12 +640,12 @@ AcrUsc2ToUtf8(JNIEnv *_E, const jchar *s
     out = java_ucs2_to_utf8_len(str, len);
     dst = ACR_MALLOC(char, out);
     if (!dst)
-        return NULL;
+        return 0;
     if ((rc = java_ucs2_to_utf8(str, len, dst, &out))) {
         /* Invalid UTF-8 string */
         AcrFree(dst);
         ACR_SET_OS_ERROR(rc);
-        return NULL;
+        return 0;
     }
     return dst;
 }
@@ -653,14 +654,14 @@ static char *get_string_utf_8(JNIEnv *_E
 {
     jsize sl, nl;
     const jchar *sr;
-    char *rv = NULL;
+    char *rv = 0;
 
     if (!str) {
-        return NULL;
+        return 0;
     }
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
         /* JNI out of memory error */
-        return NULL;
+        return 0;
     }
     sl = (*_E)->GetStringLength(_E, str);
     nl = sl * 3;
@@ -671,14 +672,14 @@ static char *get_string_utf_8(JNIEnv *_E
         if (!rv) {
             /* Exception has already neen throw from ACR_Malloc
              */
-            return NULL;
+            return 0;
         }
     }
-    sr = (*_E)->GetStringCritical(_E, str, NULL);
+    sr = (*_E)->GetStringCritical(_E, str, 0);
     if (!sr) {
         if (rv != b)
             AcrFree(rv);
-        return NULL;
+        return 0;
     }
     else {
         jsize ol = nl;
@@ -689,7 +690,7 @@ static char *get_string_utf_8(JNIEnv *_E
              */
             if (rv != b)
                 AcrFree(rv);
-            return NULL;
+            return 0;
         }
     }
     (*_E)->ReleaseStringCritical(_E, str, sr);
@@ -698,16 +699,16 @@ static char *get_string_utf_8(JNIEnv *_E
 
 static char *get_string_default(JNIEnv *_E, jstring str, char *b)
 {
-    jbyteArray sb = NULL;
-    char *rs = NULL;
+    jbyteArray sb = 0;
+    char *rs = 0;
 
     if (!_clazzn.i || !J4MID(0000)) {
         ACR_SET_OS_ERROR(ACR_EINIT);
-        return NULL;
+        return 0;
     }
     sb = CALL_METHOD0(Object, 0001, str);
     if ((*_E)->ExceptionCheck(_E))
-        return NULL;
+        return 0;
     else {
         jint len = (*_E)->GetArrayLength(_E, sb);
         if (b && len < ACR_PBUFF_LEN) {
@@ -716,9 +717,9 @@ static char *get_string_default(JNIEnv *
         }
         else {
             rs = ACR_MALLOC(char, len + 1);
-            if (rs == NULL) {
+            if (rs == 0) {
                 (*_E)->DeleteLocalRef(_E, sb);
-                return NULL;
+                return 0;
             }
         }
         (*_E)->GetByteArrayRegion(_E, sb, 0, len, (jbyte *)rs);
@@ -736,18 +737,18 @@ static jstring new_string_default(JNIEnv
 
     sl = (jsize)strlen(str);
     ba = (*_E)->NewByteArray(_E, sl);
-    if (ba != NULL) {
+    if (ba != 0) {
         (*_E)->SetByteArrayRegion(_E, ba, 0, sl, (jbyte *)str);
         rs = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), ba);
         (*_E)->DeleteLocalRef(_E, ba);
         return rs;
     }
-    return NULL;
+    return 0;
 }
 
 static jstring new_string_iso_8859_1(JNIEnv *_E, const char *s)
 {
-    jstring rs = NULL;
+    jstring rs = 0;
     if (s) {
         size_t l = strlen(s);
         if (l < ACR_MBUFF_SIZ) {
@@ -775,7 +776,7 @@ static jstring new_string_iso_8859_1(JNI
 
 static jstring new_string_utf_8(JNIEnv *_E, const char *s)
 {
-    jstring rs = NULL;
+    jstring rs = 0;
     if (s) {
           int ex;
         jsize sl = (jsize)strlen(s);
@@ -808,14 +809,14 @@ AcrGetJavaStringW(JNIEnv *_E, jstring st
 {
     jsize sl;
     const jchar *sr;
-    wchar_t *rv = NULL;
+    wchar_t *rv = 0;
 
     if (!str) {
-        return NULL;
+        return 0;
     }
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
         /* JNI out of memory error */
-        return NULL;
+        return 0;
     }
     sl = (*_E)->GetStringLength(_E, str);
     if (b && sl < ACR_MBUFF_LEN)
@@ -825,14 +826,14 @@ AcrGetJavaStringW(JNIEnv *_E, jstring st
         if (!rv) {
             /* Exception has already neen throw from ACR_Malloc
              */
-            return NULL;
+            return 0;
         }
     }
-    sr = (*_E)->GetStringCritical(_E, str, NULL);
+    sr = (*_E)->GetStringCritical(_E, str, 0);
     if (!sr) {
         if (rv != b)
             AcrFree(rv);
-        return NULL;
+        return 0;
     }
     else {
 #if CC_SIZEOF_WCHAR_T == 2
@@ -851,13 +852,13 @@ AcrGetJavaStringW(JNIEnv *_E, jstring st
 char *
 AcrGetJavaStringA(JNIEnv *_E, jstring str, char *b)
 {
-    char *rv = NULL;
+    char *rv = 0;
     if (!str) {
-        return NULL;
+        return 0;
     }
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
         /* JNI out of memory error */
-        return NULL;
+        return 0;
     }
     switch (acr_native_codepage) {
         case ACR_CP_ISO8859_1:
@@ -876,7 +877,7 @@ AcrGetJavaStringA(JNIEnv *_E, jstring st
 jstring
 AcrNewJavaStringW(JNIEnv *_E, const wchar_t *s)
 {
-    jstring r = NULL;
+    jstring r = 0;
     if (s) {
         size_t l = wcslen(s);
 #if CC_SIZEOF_WCHAR_T == 2
@@ -911,12 +912,12 @@ AcrNewJavaStringW(JNIEnv *_E, const wcha
 jstring
 AcrNewJavaStringA(JNIEnv *_E, const char *str)
 {
-    jstring rv = NULL;
+    jstring rv = 0;
     if (!str)
-        return NULL;
+        return 0;
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
         /* JNI out of memory error */
-        return NULL;
+        return 0;
     }
     switch (acr_native_codepage) {
         case ACR_CP_ISO8859_1:
@@ -936,10 +937,10 @@ jstring
 AcrNewJavaStringU(JNIEnv *_E, const char *str)
 {
     if (!str)
-        return NULL;
+        return 0;
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
         /* JNI out of memory error */
-        return NULL;
+        return 0;
     }
     return new_string_utf_8(_E, str);
 }

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java?rev=1085267&r1=1085266&r2=1085267&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java Fri Mar 25 07:26:15 2011
@@ -30,6 +30,9 @@ public class TestUtils
     public void setUp()
     {
         Assert.assertTrue(Loader.load());
+        System.out.println("Running tests on " + Os.getSysname() +
+                                                 Os.getDataModel() + " (" +
+                                                 Os.getNodename()  + ")");
     }
 
     @Test(groups = { "utils" })



Mime
View raw message