You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/13 16:04:31 UTC

svn commit: r764474 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/include/ main/native/os/darwin/ main/native/os/hpux/ main/native/os/linux/ main/native/os/solaris/ main/native/os/win32/ main/native/shared/ ...

Author: mturk
Date: Mon Apr 13 14:04:31 2009
New Revision: 764474

URL: http://svn.apache.org/viewvc?rev=764474&view=rev
Log:
Return OS.getProcessor as unified string

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_memory.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
    commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java

Modified: 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=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java Mon Apr 13 14:04:31 2009
@@ -115,4 +115,9 @@
      */
     public static native String getHardwarePlatform();
 
+    /**
+     * Data model (32 or 64 bit).
+     */
+    public static native int getDataModel();
+
 }

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=764474&r1=764473&r2=764474&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 Mon Apr 13 14:04:31 2009
@@ -67,7 +67,7 @@
  * @param file Source file where the function was called
  * @param line Source file line where the function was called
  */
-ACR_DECLARE(void) ACR_Free(JNIEnv *_E, const char *file, int line,
+ACR_DECLARE(void) ACR_Free(JNIEnv *env, const char *file, int line,
                            void *mem);
 
 /**
@@ -79,7 +79,7 @@
  * @param file Source file where the function was called
  * @param line Source file line where the function was called
  */
-ACR_DECLARE(acr_sbh_t *) ACR_SbhCreate(JNIEnv *_E, const char *file, int line,
+ACR_DECLARE(acr_sbh_t *) ACR_SbhCreate(JNIEnv *env, const char *file, int line,
                                        void *buff, acr_size_t size);
 
 /**
@@ -89,7 +89,7 @@
  * @param file Source file where the function was called
  * @param line Source file line where the function was called
  */
-ACR_DECLARE(void ) ACR_SbhReset(JNIEnv *_E, const char *file, int line,
+ACR_DECLARE(void ) ACR_SbhReset(JNIEnv *env, const char *file, int line,
                                 acr_sbh_t *sbh);
 
 /**
@@ -99,7 +99,7 @@
  * @param file Source file where the function was called
  * @param line Source file line where the function was called
  */
-ACR_DECLARE(void ) ACR_SbhDestroy(JNIEnv *_E, const char *file, int line,
+ACR_DECLARE(void ) ACR_SbhDestroy(JNIEnv *env, const char *file, int line,
                                   acr_sbh_t *sbh);
 
 /**
@@ -111,7 +111,7 @@
  * @param line Source file line where the function was called
  * @return Pointer to allocated memory.
  */
-ACR_DECLARE(void *) ACR_SbhMalloc(JNIEnv *_E, const char *file, int line,
+ACR_DECLARE(void *) ACR_SbhMalloc(JNIEnv *env, const char *file, int line,
                                   acr_sbh_t *sbh, acr_size_t size);
 
 /**
@@ -123,7 +123,7 @@
  * @param line Source file line where the function was called
  * @return Pointer to allocated memory.
  */
-ACR_DECLARE(void *) ACR_SbhCalloc(JNIEnv *_E, const char *file, int line,
+ACR_DECLARE(void *) ACR_SbhCalloc(JNIEnv *env, const char *file, int line,
                                   acr_sbh_t *sbh, acr_size_t size);
 
 #ifdef __cplusplus

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Mon Apr 13 14:04:31 2009
@@ -62,6 +62,18 @@
  */
 ACR_DECLARE(char *) ACR_Ltoa(acr_long_t n);
 
+/** Convert string to lower case
+ * @param str String to convert.
+ * @remark Conversion is done in place.
+ */
+ACR_DECLARE(char *) ACR_StrLwr(char *src);
+
+/** Convert string to upper case
+ * @param str String to convert.
+ * @remark Conversion is done in place.
+ */
+ACR_DECLARE(char *) ACR_StrUpr(char *src);
+
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c?rev=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c Mon Apr 13 14:04:31 2009
@@ -16,6 +16,7 @@
 
 #include "acr.h"
 #include "acr_private.h"
+#include "acr_string.h"
 #include <sys/utsname.h>
 #include <sys/sysctl.h>
 #include <mach/machine.h>
@@ -98,8 +99,19 @@
 
         s = sizeof(cpu_type_t);
         if ((sysctlbyname("hw.cputype", &cpu, &s, NULL, 0) == 0) &&
-            (ai = NXGetArchInfoFromCpuType(cpu, CPU_SUBTYPE_MULTIPLE)) != NULL)
-            return CSTR_TO_JSTRING(ai->name);
+            (ai = NXGetArchInfoFromCpuType(cpu, CPU_SUBTYPE_MULTIPLE)) != NULL) {
+                ACR_CopyStrn(string, ai->name, MAXSIZESYSSTRING);
+                ACR_StrLwr(string);
+                if (strstr(string, "86")) {
+#if CC_SIZEOF_VOIDP == 8
+                    return CSTR_TO_JSTRING("x86_64");
+#else
+                    return CSTR_TO_JSTRING("ia32");
+#endif
+                }
+                else
+                    return CSTR_TO_JSTRING(string);
+            }
         else
             return CSTR_TO_JSTRING(unknown);
     }
@@ -119,3 +131,13 @@
         return CSTR_TO_JSTRING(string);
 }
 
+ACR_JNI_EXPORT_DECLARE(jint, OS, getDataModel)(ACR_JNISTDARGS)
+{
+    UNREFERENCED_STDARGS;
+#if CC_SIZEOF_VOIDP == 8
+    return 64;
+#else
+    return 32;
+#endif
+}
+

Modified: commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c?rev=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c Mon Apr 13 14:04:31 2009
@@ -91,9 +91,9 @@
  */
 #if HAS_BIG_ENDIAN
 #if CC_SIZEOF_VOIDP == 8
-    return CSTR_TO_JSTRING("parisc64");
+    return CSTR_TO_JSTRING("pa64");
 #else
-    return CSTR_TO_JSTRING("parisc");
+    return CSTR_TO_JSTRING("pa32");
 #endif
 #else
 #if CC_SIZEOF_VOIDP == 8
@@ -109,3 +109,13 @@
     return CSTR_TO_JSTRING(unknown);
 }
 
+ACR_JNI_EXPORT_DECLARE(jint, OS, getDataModel)(ACR_JNISTDARGS)
+{
+    UNREFERENCED_STDARGS;
+#if CC_SIZEOF_VOIDP == 8
+    return 64;
+#else
+    return 32;
+#endif
+}
+

Modified: 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=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c Mon Apr 13 14:04:31 2009
@@ -17,6 +17,7 @@
 #include "acr.h"
 #include "acr_private.h"
 #include "acr_arch.h"
+#include "acr_string.h"
 #include <sys/utsname.h>
 
 #define MAXSIZESYSSTRING 256
@@ -86,15 +87,30 @@
 
 ACR_JNI_EXPORT_DECLARE(jstring, OS, getProcessor)(ACR_JNISTDARGS)
 {
+    char string[MAXSIZESYSSTRING];
     struct utsname sys;
     if (!uname(&sys)) {
-        if (strstr(sys.machine, "86") || !strcmp(sys.machine, "ia64")) {
+        ACR_CopyStrn(string, sys.machine, MAXSIZESYSSTRING);
+        ACR_StrLwr(string);
+
+#if HAS_BIG_ENDIAN
+        /* TODO: Name BE machines (PPC ?) */
+#else
+        if (strstr(string, "64")) {
 #if CC_SIZEOF_VOIDP == 8
-            return CSTR_TO_JSTRING(sys.machine);
+            return CSTR_TO_JSTRING(string);
 #else
             return CSTR_TO_JSTRING("ia32");
 #endif
         }
+        else if (strstr(string, "86")) {
+            return CSTR_TO_JSTRING("ia32");
+        }
+        else
+#endif
+        {
+            return CSTR_TO_JSTRING(string);
+        }
     }
     return CSTR_TO_JSTRING(unknown);
 }
@@ -104,3 +120,12 @@
     return CSTR_TO_JSTRING(unknown);
 }
 
+ACR_JNI_EXPORT_DECLARE(jint, OS, getDataModel)(ACR_JNISTDARGS)
+{
+    UNREFERENCED_STDARGS;
+#if CC_SIZEOF_VOIDP == 8
+    return 64;
+#else
+    return 32;
+#endif
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c?rev=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c Mon Apr 13 14:04:31 2009
@@ -81,11 +81,19 @@
 
 ACR_JNI_EXPORT_DECLARE(jstring, OS, getProcessor)(ACR_JNISTDARGS)
 {
-    char string[MAXSIZESYSSTRING];
-    if (sysinfo(SI_ARCHITECTURE, string, sizeof(string)) < 0)
-        return CSTR_TO_JSTRING(unknown);
-     else
-        return CSTR_TO_JSTRING(string);
+#if HAS_BIG_ENDIAN
+#if CC_SIZEOF_VOIDP == 8
+    return CSTR_TO_JSTRING("sparc64");
+#else
+    return CSTR_TO_JSTRING("sparc32");
+#endif
+#else
+#if CC_SIZEOF_VOIDP == 8
+    return CSTR_TO_JSTRING("x86_64");
+#else
+    return CSTR_TO_JSTRING("ia32");
+#endif
+#endif
 }
 
 ACR_JNI_EXPORT_DECLARE(jstring, OS, getHardwarePlatform)(ACR_JNISTDARGS)
@@ -96,3 +104,13 @@
      else
         return CSTR_TO_JSTRING(string);
 }
+
+ACR_JNI_EXPORT_DECLARE(jint, OS, getDataModel)(ACR_JNISTDARGS)
+{
+    UNREFERENCED_STDARGS;
+#if CC_SIZEOF_VOIDP == 8
+    return 64;
+#else
+    return 32;
+#endif
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c?rev=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c Mon Apr 13 14:04:31 2009
@@ -198,29 +198,22 @@
 {
     char buf[32];
 
+#if !defined(_WIN64)
+    strcpy(buf, "ia32");
+#else
     switch (acr_osinf->wProcessorArchitecture) {
         case PROCESSOR_ARCHITECTURE_AMD64:
+        case PROCESSOR_ARCHITECTURE_INTEL:
             strcpy(buf, "x86_64");
         break;
         case PROCESSOR_ARCHITECTURE_IA64:
             strcpy(buf, "ia64");
-        case PROCESSOR_ARCHITECTURE_INTEL:
-#if !defined(_WIN64)
-            if (acr_osinf->wProcessorLevel > 2 && acr_osinf->wProcessorLevel < 7)
-                sprintf(buf, "i%d86", acr_osinf->wProcessorLevel);
-            else
-#endif
-            {
-                /* TODO: Figure out the proper names for
-                 * other Intel processors
-                 */
-                strcpy(buf, "ia32");
-            }
         break;
         default:
             strcpy(buf, unknown);
         break;
     }
+#endif
 
     return CSTR_TO_JSTRING(buf);
 }
@@ -252,3 +245,13 @@
 
     return CSTR_TO_JSTRING(buf);
 }
+
+ACR_JNI_EXPORT_DECLARE(jint, OS, getDataModel)(ACR_JNISTDARGS)
+{
+    UNREFERENCED_STDARGS;
+#if CC_SIZEOF_VOIDP == 8
+    return 64;
+#else
+    return 32;
+#endif
+}

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=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon Apr 13 14:04:31 2009
@@ -138,3 +138,29 @@
     }
     return start;
 }
+
+ACR_DECLARE(char *) ACR_StrLwr(char *src)
+{
+
+    char *p = src;
+    if (src) {
+        while (*p) {
+            *p = acr_tolower(*p);
+            p++;
+        }
+    }
+    return src;
+}
+
+ACR_DECLARE(char *) ACR_StrUpr(char *src)
+{
+
+    char *p = src;
+    if (src) {
+        while (*p) {
+            *p = acr_toupper(*p);
+            p++;
+        }
+    }
+    return src;
+}

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java?rev=764474&r1=764473&r2=764474&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java Mon Apr 13 14:04:31 2009
@@ -49,14 +49,15 @@
 
         /* The following are just for display purpose */
         System.out.println("");
-        System.out.println("Name      " + OS.getSysname());
-        System.out.println("Node      " + OS.getNodename());
-        System.out.println("Release   " + OS.getRelease());
-        System.out.println("Version   " + OS.getVersion());
+        System.out.println("Name       " + OS.getSysname());
+        System.out.println("Node       " + OS.getNodename());
+        System.out.println("Release    " + OS.getRelease());
+        System.out.println("Version    " + OS.getVersion());
 
-        System.out.println("Machine   " + OS.getMachine());
-        System.out.println("Processor " + OS.getProcessor());
-        System.out.println("Hardware  " + OS.getHardwarePlatform());
+        System.out.println("Machine    " + OS.getMachine());
+        System.out.println("Processor  " + OS.getProcessor());
+        System.out.println("Data Model " + OS.getDataModel());
+        System.out.println("Hardware   " + OS.getHardwarePlatform());
 
     }