]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #31263 - dhuseby:fixing_bsd_builds, r=alexcrichton
authorbors <bors@rust-lang.org>
Wed, 3 Feb 2016 06:38:01 +0000 (06:38 +0000)
committerbors <bors@rust-lang.org>
Wed, 3 Feb 2016 06:38:01 +0000 (06:38 +0000)
Something went haywire with github last night and the old PR https://github.com/rust-lang/rust/pull/31230 got closed somehow.  This new PR is to replace the old one.  This incorporates all of the feedback from the other PR.

@alexcrichton I incorporated the suggestion from @semarie and the result is cleaner and clearer.  I think this is ready to go.

src/libstd/sys/unix/fs.rs
src/libstd/sys/unix/stack_overflow.rs
src/libtest/lib.rs

index d2d2ce35d84a0adfe401f80935293cb91929f701..91931811234625c6c3a2bd496857eb82b4c33e68 100644 (file)
@@ -211,20 +211,14 @@ pub fn ino(&self) -> raw::ino_t {
     #[cfg(any(target_os = "macos",
               target_os = "ios",
               target_os = "netbsd",
-              target_os = "openbsd"))]
-    fn name_bytes(&self) -> &[u8] {
-        unsafe {
-            ::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
-                                    self.entry.d_namlen as usize)
-        }
-    }
-    #[cfg(any(target_os = "freebsd",
+              target_os = "openbsd",
+              target_os = "freebsd",
               target_os = "dragonfly",
               target_os = "bitrig"))]
     fn name_bytes(&self) -> &[u8] {
         unsafe {
             ::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
-                                    self.entry.d_namelen as usize)
+                                    self.entry.d_namlen as usize)
         }
     }
     #[cfg(any(target_os = "android",
index c7614db3299592239d6e933c319e57d918b3f6fb..b5cbcaa44d56c5993928fb612997abe441f3d97e 100644 (file)
@@ -135,26 +135,38 @@ pub unsafe fn cleanup() {
         Handler { _data: MAIN_ALTSTACK };
     }
 
-    pub unsafe fn make_handler() -> Handler {
-        let alt_stack = mmap(ptr::null_mut(),
-                             SIGSTKSZ,
-                             PROT_READ | PROT_WRITE,
-                             MAP_PRIVATE | MAP_ANON,
-                             -1,
-                             0);
-        if alt_stack == MAP_FAILED {
+    unsafe fn get_stackp() -> *mut libc::c_void {
+        let stackp = mmap(ptr::null_mut(),
+                          SIGSTKSZ,
+                          PROT_READ | PROT_WRITE,
+                          MAP_PRIVATE | MAP_ANON,
+                          -1,
+                          0);
+        if stackp == MAP_FAILED {
             panic!("failed to allocate an alternative stack");
         }
+        stackp
+    }
 
-        let mut stack: libc::stack_t = mem::zeroed();
+    #[cfg(any(target_os = "linux",
+              target_os = "macos",
+              target_os = "bitrig",
+              target_os = "netbsd",
+              target_os = "openbsd"))]
+    unsafe fn get_stack() -> libc::stack_t {
+        libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ }
+    }
 
-        stack.ss_sp = alt_stack;
-        stack.ss_flags = 0;
-        stack.ss_size = SIGSTKSZ;
+    #[cfg(any(target_os = "freebsd",
+              target_os = "dragonfly"))]
+    unsafe fn get_stack() -> libc::stack_t {
+        libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ }
+    }
 
+    pub unsafe fn make_handler() -> Handler {
+        let stack = get_stack();
         sigaltstack(&stack, ptr::null_mut());
-
-        Handler { _data: alt_stack }
+        Handler { _data: stack.ss_sp as *mut libc::c_void }
     }
 
     pub unsafe fn drop_handler(handler: &mut Handler) {
index 130ce3a9637f304badab07f923c58cfce99a44d4..443356fbe7cd54a83b408d6087482ce6a4a1b14b 100644 (file)
@@ -939,18 +939,12 @@ fn num_cpus() -> usize {
     fn num_cpus() -> usize {
         let mut cpus: libc::c_uint = 0;
         let mut cpus_size = std::mem::size_of_val(&cpus);
-        let mut mib = [libc::CTL_HW, libc::HW_AVAILCPU, 0, 0];
 
         unsafe {
-            libc::sysctl(mib.as_mut_ptr(),
-                         2,
-                         &mut cpus as *mut _ as *mut _,
-                         &mut cpus_size as *mut _ as *mut _,
-                         0 as *mut _,
-                         0);
+            cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
         }
         if cpus < 1 {
-            mib[1] = libc::HW_NCPU;
+            let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
             unsafe {
                 libc::sysctl(mib.as_mut_ptr(),
                              2,