Bug 509262: Restore Mac OS X 10.2 and 10.3 support. NSPR_4_7_BRANCH
authorwtc%google.com
Sat, 03 Oct 2009 02:03:48 +0000
branchNSPR_4_7_BRANCH
changeset 4160 a46e66b3c10f116e1777169a584b4d371019fde8
parent 4159 b05865b74b3c4ef2bcf1052f6909ab8fd682979f
child 4161 05a434b202094eca97b5b189b1c45784c6c422ed
push idunknown
push userunknown
push dateunknown
bugs509262
Bug 509262: Restore Mac OS X 10.2 and 10.3 support. Modified Files: configure configure.in prsystem.c Tag: NSPR_4_7_BRANCH
configure
configure.in
pr/src/misc/prsystem.c
--- a/configure
+++ b/configure
@@ -3341,20 +3341,16 @@ EOF
     cat >> confdefs.h <<\EOF
 #define DARWIN 1
 EOF
 
     cat >> confdefs.h <<\EOF
 #define HAVE_BSD_FLOCK 1
 EOF
 
-    cat >> confdefs.h <<\EOF
-#define HAVE_SOCKLEN_T 1
-EOF
-
     CFLAGS="$CFLAGS -Wmost -fno-common"
     case "${target_cpu}" in
         i*86*)
             if test -n "$USE_64"; then
                 CPU_ARCH=x86_64
                 CC="$CC -arch x86_64"
             else        
                 CPU_ARCH=i386
@@ -3449,16 +3445,52 @@ tools are selected during the Xcode/Deve
                     DSO_LDOPTS="$DSO_LDOPTS -isysroot ${MACOS_SDK_DIR}"
                 else
                                                             LDFLAGS="$LDFLAGS -Wl,-syslibroot,${MACOS_SDK_DIR}"
                     DSO_LDOPTS="$DSO_LDOPTS -Wl,-syslibroot,${MACOS_SDK_DIR}"
                 fi
             fi
         fi
     fi
+
+    echo $ac_n "checking for socklen_t""... $ac_c" 1>&6
+echo "configure:3456: checking for socklen_t" >&5
+    if eval "test \"`echo '$''{'ac_cv_socklen_t'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 3461 "configure"
+#include "confdefs.h"
+#include <stdio.h>
+                         #include <sys/socket.h>
+int main() {
+socklen_t foo = 0;
+; return 0; }
+EOF
+if { (eval echo configure:3469: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  ac_cv_socklen_t=true
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  ac_cv_socklen_t=false
+fi
+rm -f conftest*
+fi
+
+    if test "$ac_cv_socklen_t" = true ; then
+        cat >> confdefs.h <<\EOF
+#define HAVE_SOCKLEN_T 1
+EOF
+
+        echo "$ac_t""yes" 1>&6
+    else
+        echo "$ac_t""no" 1>&6
+    fi
     ;;
 
 *-dgux*)
     cat >> confdefs.h <<\EOF
 #define XP_UNIX 1
 EOF
 
     cat >> confdefs.h <<\EOF
@@ -4498,27 +4530,27 @@ EOF
     if test -z "$GNU_CC"; then
         CC="$CC -std1 -ieee_with_inexact"
         if test "$OS_RELEASE" != "V2.0"; then
             CC="$CC -readonly_strings"
         fi
         _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Olimit 4000"
         ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4507: checking for machine/builtins.h" >&5
+echo "configure:4539: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4512 "configure"
+#line 4544 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4517: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4549: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -5038,63 +5070,63 @@ if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 
 
 case $target in
 *-darwin*|*-beos*)
     ;;
 *)
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:5047: checking for dlopen in -ldl" >&5
+echo "configure:5079: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 5055 "configure"
+#line 5087 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:5066: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5098: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
 rm -f conftest*
 LIBS="$ac_save_LIBS"
 
 fi
 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   ac_safe=`echo "dlfcn.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for dlfcn.h""... $ac_c" 1>&6
-echo "configure:5083: checking for dlfcn.h" >&5
+echo "configure:5115: checking for dlfcn.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5088 "configure"
+#line 5120 "configure"
 #include "confdefs.h"
 #include <dlfcn.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:5093: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5125: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -5117,23 +5149,23 @@ fi
     ;;
 esac
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:5126: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:5158: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 5132 "configure"
+#line 5164 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5141,17 +5173,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 5150 "configure"
+#line 5182 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5165,22 +5197,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5174: checking for $ac_func" >&5
+echo "configure:5206: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5179 "configure"
+#line 5211 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -5193,17 +5225,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:5202: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5234: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -5234,17 +5266,17 @@ if test "${enable_strip+set}" = set; the
 fi
 
 
 case "${target_os}" in
 hpux*)
 if test -z "$GNU_CC"; then
 
     echo $ac_n "checking for +Olit support""... $ac_c" 1>&6
-echo "configure:5243: checking for +Olit support" >&5
+echo "configure:5275: checking for +Olit support" >&5
 if eval "test \"`echo '$''{'ac_cv_hpux_usable_olit_option'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
                   ac_cv_hpux_usable_olit_option=no
         rm -f conftest*
         echo 'int main() { return 0; }' | cat > conftest.c
         ${CC-cc} ${CFLAGS} +Olit=all -o conftest conftest.c > conftest.out 2>&1
         if test $? -eq 0; then
@@ -5273,17 +5305,17 @@ esac
 
 case "$target_os" in
 darwin*)
     _HAVE_PTHREADS=1
     ;;
 *)
     
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:5282: checking for pthread_create in -lpthreads" >&5
+echo "configure:5314: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5295,17 +5327,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:5304: checking for pthread_create in -lpthread" >&5
+echo "configure:5336: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5317,17 +5349,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:5326: checking for pthread_create in -lc_r" >&5
+echo "configure:5358: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5339,17 +5371,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:5348: checking for pthread_create in -lc" >&5
+echo "configure:5380: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5471,17 +5503,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5480: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5512: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 		case "$target_os" in
 	    freebsd*)
 # Freebsd doesn't use -pthread for compiles, it uses them for linking
@@ -5494,17 +5526,17 @@ echo "configure:5480: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5503: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5535: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
--- a/configure.in
+++ b/configure.in
@@ -991,17 +991,16 @@ case "$target" in
     esac
 
     ;;
 
 *-darwin*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(DARWIN)
     AC_DEFINE(HAVE_BSD_FLOCK)
-    AC_DEFINE(HAVE_SOCKLEN_T)
     CFLAGS="$CFLAGS -Wmost -fno-common"
     case "${target_cpu}" in
         i*86*)
             if test -n "$USE_64"; then
                 CPU_ARCH=x86_64
                 CC="$CC -arch x86_64"
             else        
                 CPU_ARCH=i386
@@ -1138,16 +1137,30 @@ tools are selected during the Xcode/Deve
                     dnl gcc 4.0.0 doesn't pass -syslibroot to ld, it needs
                     dnl to be explicit.
                     LDFLAGS="$LDFLAGS -Wl,-syslibroot,${MACOS_SDK_DIR}"
                     DSO_LDOPTS="$DSO_LDOPTS -Wl,-syslibroot,${MACOS_SDK_DIR}"
                 fi
             fi
         fi
     fi
+
+    AC_MSG_CHECKING(for socklen_t)
+    AC_CACHE_VAL(ac_cv_socklen_t,
+        [AC_TRY_COMPILE([#include <stdio.h>
+                         #include <sys/socket.h>],
+                        [socklen_t foo = 0;],
+                        [ac_cv_socklen_t=true],
+                        [ac_cv_socklen_t=false])])
+    if test "$ac_cv_socklen_t" = true ; then
+        AC_DEFINE(HAVE_SOCKLEN_T)
+        AC_MSG_RESULT(yes)
+    else
+        AC_MSG_RESULT(no)
+    fi
     ;;
 
 *-dgux*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
     AC_DEFINE(SVR4)
     AC_DEFINE(SYSV)
     AC_DEFINE(DGUX)
--- a/pr/src/misc/prsystem.c
+++ b/pr/src/misc/prsystem.c
@@ -264,16 +264,46 @@ PR_IMPLEMENT(PRInt32) PR_GetNumberOfProc
 #elif defined(XP_UNIX)
     numCpus = sysconf( _SC_NPROCESSORS_ONLN );
 #else
 #error "An implementation is required"
 #endif
     return(numCpus);
 } /* end PR_GetNumberOfProcessors() */
 
+#ifdef DARWIN
+
+/*
+ * Manually define the host_basic_info structure in Mac OS X 10.4 or later
+ * so that we can compile against Mac OS X 10.2 and 10.3 SDKs.
+ */
+
+#pragma pack(4)
+
+struct host_basic_info_new {
+    integer_t max_cpus;
+    integer_t avail_cpus;
+    natural_t memory_size;
+    cpu_type_t cpu_type;
+    cpu_subtype_t cpu_subtype;
+    /*cpu_threadtype_t*/ integer_t cpu_threadtype;
+    integer_t physical_cpu;
+    integer_t physical_cpu_max;
+    integer_t logical_cpu;
+    integer_t logical_cpu_max;
+    uint64_t max_mem;
+};
+
+#pragma pack()
+
+#define HOST_BASIC_INFO_NEW_COUNT ((mach_msg_type_number_t) \
+    (sizeof(struct host_basic_info_new)/sizeof(integer_t)))
+
+#endif /* DARWIN */
+
 /*
 ** PR_GetPhysicalMemorySize()
 ** 
 ** Implementation notes:
 **   Every platform does it a bit different.
 **     bytes is the returned value.
 **   for each platform's "if defined" section
 **     declare your local variable
@@ -294,25 +324,30 @@ PR_IMPLEMENT(PRUint64) PR_GetPhysicalMem
 
     struct pst_static info;
     int result = pstat_getstatic(&info, sizeof(info), 1, 0);
     if (result == 1)
         bytes = (PRUint64) info.physical_memory * info.page_size;
 
 #elif defined(DARWIN)
 
-    struct host_basic_info hInfo;
-    mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
+    struct host_basic_info_new hInfo;
+    mach_msg_type_number_t count = HOST_BASIC_INFO_NEW_COUNT;
 
     int result = host_info(mach_host_self(),
                            HOST_BASIC_INFO,
                            (host_info_t) &hInfo,
                            &count);
-    if (result == KERN_SUCCESS)
-        bytes = hInfo.max_mem;
+    if (result == KERN_SUCCESS) {
+        if (count >= HOST_BASIC_INFO_NEW_COUNT) {
+            bytes = hInfo.max_mem;
+        } else {
+            bytes = hInfo.memory_size;
+        }
+    }
 
 #elif defined(WIN32)
 
     /* Try to use the newer GlobalMemoryStatusEx API for Windows 2000+. */
     GlobalMemoryStatusExFn globalMemory = (GlobalMemoryStatusExFn) NULL;
     HMODULE module = GetModuleHandle("kernel32.dll");
 
     if (module) {