1.0.46.6: better MACHINE-VERSION on Darwin
authorNikodemus Siivola <nikodemus@random-state.net>
Sun, 20 Feb 2011 10:33:43 +0000 (10:33 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Sun, 20 Feb 2011 10:33:43 +0000 (10:33 +0000)
 Patch by Josh Elsasser.

 Use machdep.cpu.brand_string instead of hw.model.

 lp#668332

NEWS
src/code/bsd-os.lisp
tools-for-build/ldso-stubs.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index 7cb8194..ccb69b6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@
 changes relative to sbcl-1.0.46:
   * enhancement: --script muffles style-warnings and compiler notes. (lp#677779)
   * enhancement: redefinition warnings for macros from different files. (lp#434657)
+  * enhancement: better MACHINE-VERSION on Darwin x86 and x86-64. (lp#668332)
   * bug fix: SB-DEBUG:BACKTRACE-AS-LIST guards against potentially leaking
     stack-allocated values out of their dynamic-extent. (lp#310175)
   * bug fix: attempts to use SB-SPROF for wallclock profiling on threaded
index dca2b6f..1b1633d 100644 (file)
   (newp (* t))
   (newlen sb!unix:size-t))
 
+#!+darwin
+(define-alien-routine ("sysctlbyname" %sysctlbyname) int
+  (name c-string)
+  (oldp (* t))
+  (oldlenp (* sb!unix:size-t))
+  (newp (* t))
+  (newlen sb!unix:size-t))
+
 (defun sysctl (type &rest name)
   #!+sb-doc
   "Retrieves an integer or string value with the given name."
                  (free-alien result)
                  (sb!unix::newcharstar-string result)))))))))
 
+#!+darwin
+(defun sysctlbyname (type name)
+  #!+sb-doc
+  "Retrieves an integer or string value with the given name."
+  (with-alien ((result-len sb!unix:size-t))
+    (ecase type
+      (:int
+       (with-alien ((result int))
+         (setf result-len (alien-size int :bytes))
+         (unless (minusp (%sysctlbyname name (addr result)
+                                        (addr result-len) nil 0))
+           result)))
+      (:str
+       (unless (minusp (%sysctlbyname name nil (addr result-len) nil 0))
+         (with-alien ((result (* char) (make-alien char result-len)))
+           (if (minusp (%sysctlbyname name result (addr result-len) nil 0))
+               (free-alien result)
+               (sb!unix::newcharstar-string result))))))))
+
 (defun software-type ()
   #!+sb-doc
   "Return a string describing the supporting software."
 
 ;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
 (defun get-machine-version ()
-  ;; FIXME: on Darwin we would prefer machdep.cpu.brand_string -- but I can't
-  ;; seem to grab it using sysctl() -- but the shell tool finds it. When
-  ;; someone has the time, check out how Darwin shell sysctl does it.
-  (sysctl :str ctl-hw hw-model))
+  (or #!+darwin (sysctlbyname :str "machdep.cpu.brand_string")
+      (sysctl :str ctl-hw hw-model)))
index 471859e..f698e79 100644 (file)
@@ -332,6 +332,8 @@ ldso_stub__ ## fct: ;                  \\
                    "dlsym")
                  #!+bsd
                  '("sysctl")
+                 #!+darwin
+                 '("sysctlbyname")
                  #!+os-provides-dladdr
                  '("dladdr")
                  #!-sunos ;; !defined(SVR4)
index 2095a60..7e0791f 100644 (file)
@@ -20,4 +20,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.46.5"
+"1.0.46.6"