commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1085946 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/util/ native/ native/include/acr/ native/os/unix/ native/shared/
Date Sun, 27 Mar 2011 14:41:12 GMT
Author: mturk
Date: Sun Mar 27 14:41:11 2011
New Revision: 1085946

URL: http://svn.apache.org/viewvc?rev=1085946&view=rev
Log:
Add few more of the old code with some simplifications

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_load.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/uuid.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/UUID.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/stdtypes.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/UUID.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/UUID.java?rev=1085946&r1=1085945&r2=1085946&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/UUID.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/UUID.java
Sun Mar 27 14:41:11 2011
@@ -21,16 +21,13 @@ package org.apache.commons.runtime.util;
  */
 public final class UUID
 {
-    private static native byte[] getb0()
-                                    throws UnsupportedOperationException;
-
+    private static native byte[] getb0();
     private byte[] uuid;
 
     /**
      * Create new {@code UUID} instance.
      */
     public UUID()
-        throws UnsupportedOperationException
     {
         uuid = getb0();
     }

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=1085946&r1=1085945&r2=1085946&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Sun Mar 27 14:41:11 2011
@@ -60,9 +60,11 @@ ASMSOURCES=\
 	@zlib_asm_sources@
 
 UNIX_SOURCES=\
+	$(TOPDIR)/os/unix/dso.c \
 	$(TOPDIR)/os/unix/init.c \
 	$(TOPDIR)/os/unix/platform.c \
-	$(TOPDIR)/os/unix/time.c
+	$(TOPDIR)/os/unix/time.c \
+	$(TOPDIR)/os/unix/util.c
 
 LINUX_SOURCES=\
 	$(TOPDIR)/os/linux/misc.c \
@@ -97,6 +99,7 @@ LIBSOURCES=\
 	$(TOPDIR)/shared/string.c \
 	$(TOPDIR)/shared/system.c \
 	$(TOPDIR)/shared/unsafe.c \
+	$(TOPDIR)/shared/uuid.c \
 	$(TOPDIR)/shared/version.c \
 	$(TOPDIR)/shared/buildmark.c
 

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=1085946&r1=1085945&r2=1085946&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 Sun Mar 27 14:41:11
2011
@@ -282,4 +282,7 @@
 #define ACR_OS_HPUX             0x20800
 #define ACR_OS_AIX              0x21000
 
+#define UNUSED_SOURCE_FILE(F)   \
+const char __provided_##F [] = "Using system provided " #F "()"
+
 #endif /* _ACR_STDDEFS_H_ */

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/stdtypes.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/stdtypes.h?rev=1085946&r1=1085945&r2=1085946&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/stdtypes.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/stdtypes.h Sun Mar 27 14:41:11
2011
@@ -68,6 +68,7 @@ typedef  int                uid_t;
 typedef  int                gid_t;
 typedef  int                acr_uid_t;
 typedef  int                acr_gid_t;
+typedef  HMODULE            acr_dso_t;
 typedef  HANDLE             acr_osd_t;
 typedef  DWORD              acr_pid_t;
 typedef  DWORD              acr_threadkey_t;
@@ -124,6 +125,7 @@ typedef  socklen_t          acr_socklen_
 typedef  char               acr_pchar_t;
 typedef  uid_t              acr_uid_t;
 typedef  gid_t              acr_gid_t;
+typedef  void *             acr_dso_t;
 typedef  int                acr_osd_t;
 typedef  pid_t              acr_pid_t;
 typedef  pthread_key_t      acr_threadkey_t;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h?rev=1085946&r1=1085945&r2=1085946&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h Sun Mar 27 14:41:11
2011
@@ -92,7 +92,32 @@ typedef struct stat         struct_stat_
 # define SHELL_PATH         "/bin/sh"
 #endif
 
-#define UNUSED_SOURCE_FILE(F)   \
-const char __provided_##F [] = "Using system provided " #F "()"
+#if defined(F_DUPFD)
+#define FD_ABOVE_STDFILENO(D)           \
+    do {                                \
+        int __d = (D);                  \
+        if (__d == -1 || __d > 2)       \
+            break;                      \
+        (D) = fcntl(__d, F_DUPFD, 3);   \
+        if ((D) != -1 && (D) != __d)    \
+            close(__d);                 \
+    } while (0)
+
+#else
+#define FD_ABOVE_STDFILENO(D)           \
+    do {                                \
+        int __d = (D);                  \
+        if (__d == -1 || __d > 2)       \
+            break;                      \
+        do {                            \
+            (D) = dup((D));             \
+        } while ((D) < 3);              \
+        if ((D) != -1 && (D) != __d) {  \
+            while (__d < 3)             \
+                close(__d++);           \
+        }                               \
+    } while (0)
+
+#endif /* F_DUPFD */
 
 #endif /* _ACR_ARCH_DEFS_H_ */

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_load.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_load.h?rev=1085946&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_load.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_load.h Sun Mar 27 14:41:11
2011
@@ -0,0 +1,27 @@
+/* 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_ARCH_LOAD_H_
+#define _ACR_ARCH_LOAD_H_
+
+acr_dso_t
+AcrDsoLoad(const char *name);
+
+void *
+AcrGetProcAddress(acr_dso_t dso, const char *name);
+
+
+#endif /* _ACR_ARCH_LOAD_H_ */

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_load.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c?rev=1085946&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c Sun Mar 27 14:41:11 2011
@@ -0,0 +1,50 @@
+/* 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/string.h"
+#include "acr/error.h"
+#include "acr/port.h"
+#include "arch_defs.h"
+#include "arch_load.h"
+
+acr_dso_t
+AcrDsoLoad(const char *name)
+{
+    int flags = RTLD_NOW | RTLD_GLOBAL;
+
+#if defined(_AIX)
+    if (strchr(name + 1, '(') && canon[strlen(name) - 1] == ')') {
+        /* This special archive.a(dso.so) syntax is required for
+         * the way libtool likes to build shared libraries on AIX.
+         * dlopen() support for such a library requires that the
+         * RTLD_MEMBER flag be enabled.
+         */
+        flags |= RTLD_MEMBER;
+    }
+#endif
+    return dlopen(name, flags);
+}
+
+void *
+AcrGetProcAddress(acr_dso_t dso, const char *name)
+{
+    if (dso == 0) {
+        ACR_SET_OS_ERROR(ACR_EINIT);
+        return 0;
+    }
+    return dlsym(dso, name);
+}
+

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

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c?rev=1085946&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c Sun Mar 27 14:41:11 2011
@@ -0,0 +1,137 @@
+/* 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/error.h"
+#include "acr/memory.h"
+#include "acr/port.h"
+#include <poll.h>
+
+int
+AcrNonblock(int fd, int on)
+{
+    int rc = 0;
+
+    if (fd == -1)
+        return ACR_EBADF;
+#ifdef O_NONBLOCK
+    /* Use non-blocking I/O
+    */
+    long mode, forg;
+    if ((mode = fcntl(fd, F_GETFL, 0)) == -1) {
+        return ACR_GET_OS_ERROR();
+    }
+    forg = mode;
+    if (on)
+        mode |=  O_NONBLOCK;
+    else
+        mode &= ~O_NONBLOCK;
+    if (forg != mode && fcntl(fd, F_SETFL, mode) == -1) {
+        return ACR_GET_OS_ERROR();
+    }
+#else
+    /* Non blocking I/O is unsupported.
+    */
+    rc = ACR_ENOTIMPL;
+#endif
+    return rc;
+}
+
+int
+AcrCloseOnExec(int fd, int on)
+{
+    int rc = 0;
+
+    if (fd == -1)
+        return ACR_EBADF;
+#ifdef FD_CLOEXEC
+    /* Close on exec
+    */
+    long mode, forg;
+    if ((mode = fcntl(fd, F_GETFD, 0)) == -1) {
+        return ACR_GET_OS_ERROR();
+    }
+    forg = mode;
+    if (on)
+        mode |= FD_CLOEXEC;
+    else
+        mode &= ~FD_CLOEXEC;
+    if (forg != mode && fcntl(fd, F_SETFD, mode) == -1) {
+        return ACR_GET_OS_ERROR();
+    }
+#else
+    /* Flag is unsupported.
+    */
+    rc = ACR_ENOTIMPL;
+#endif
+    return rc;
+}
+
+#ifndef POLLRDNORM
+#define POLLRDNORM POLLIN
+#endif
+
+#ifndef POLLWRNORM
+#define POLLWRNORM POLLOUT
+#endif
+
+#ifndef POLLRDBAND
+#define POLLRDBAND POLLPRI
+#endif
+
+int
+AcrWaitIO(int fd, int timeout, int events)
+{
+    int            rc;
+    time_t         nexttime, prevtime = 0;
+    struct timeval t;
+    struct pollfd  pd = { fd, events, 0 };
+
+    /* Store the the current time
+    */
+    if (timeout > 0) {
+        gettimeofday(&t, 0);
+        prevtime = t.tv_sec * 1000 + t.tv_usec / 1000;
+    }
+    for (;;) {
+        rc = poll(&pd, 1, timeout);
+        if (rc == -1 && errno == EINTR) {
+            if (timeout > 0) {
+                gettimeofday(&t, 0);
+                nexttime = t.tv_sec * 1000 + t.tv_usec / 1000;
+                timeout -= (int)(nexttime - prevtime);
+                if (timeout < 0) {
+                    rc = 0;
+                    break;
+                }
+                prevtime = nexttime;
+            }
+        }
+        else
+            break;
+    }
+    if (rc == -1)
+        return errno;
+    else if (rc == 0)
+        return ACR_TIMEUP;
+    if (pd.revents & events)
+        return 0;
+    else if (pd.revents & POLLNVAL)
+        return ACR_EBADF;
+    else if (pd.revents & POLLERR)
+        return ACR_EIO;
+    else
+        return ACR_EPIPE;
+}

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

Added: commons/sandbox/runtime/trunk/src/main/native/shared/uuid.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/uuid.c?rev=1085946&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/uuid.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/uuid.c Sun Mar 27 14:41:11 2011
@@ -0,0 +1,35 @@
+/* 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/port.h"
+
+ACR_UTIL_EXPORT(jbyteArray, UUID, getb0)(JNI_STDARGS)
+{
+    unsigned int bb[4];
+    jbyteArray rv;
+
+    rv = (*_E)->NewByteArray(_E, 16);
+    if (rv) {
+        bb[0] = arc4random();
+        bb[1] = arc4random();
+        bb[2] = arc4random();
+        bb[3] = arc4random();
+        (*_E)->SetByteArrayRegion(_E, rv, 0, 16, (jbyte *)bb);
+    }
+    return rv;
+}
+

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



Mime
View raw message