Bug 1381560 - Stop storing panic string length twice, r=ted
authorMichael Layzell <michael@thelayzells.com>
Mon, 17 Jul 2017 13:03:57 -0400
changeset 420566 4d0a260acd3f4d76307b49a199994ff37242daf6
parent 420565 b5cbc88dede0b871548513e0d2d10b4c9d05178f
child 420567 46d1fa12a0829046f2bee4ffd10d7af38616bba9
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1381560
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1381560 - Stop storing panic string length twice, r=ted MozReview-Commit-ID: rLOdMPxhwD
toolkit/library/rust/shared/lib.rs
--- a/toolkit/library/rust/shared/lib.rs
+++ b/toolkit/library/rust/shared/lib.rs
@@ -33,17 +33,17 @@ pub extern "C" fn rust_init_please_remov
 
 /// Used to implement `nsIDebug2::RustPanic` for testing purposes.
 #[no_mangle]
 pub extern "C" fn intentional_panic(message: *const c_char) {
     panic!("{}", unsafe { CStr::from_ptr(message) }.to_string_lossy());
 }
 
 /// Contains the panic message, if set.
-static mut PANIC_REASON: Option<(*const str, usize)> = None;
+static mut PANIC_REASON: Option<*const str> = None;
 
 /// Configure a panic hook to capture panic messages for crash reports.
 ///
 /// We don't store this in `gMozCrashReason` because:
 /// a) Rust strings aren't null-terminated, so we'd have to allocate
 ///    memory to get a null-terminated string
 /// b) The panic=abort handler is going to call `abort()` on non-Windows,
 ///    which is `mozalloc_abort` for us, which will use `MOZ_CRASH` and
@@ -53,35 +53,34 @@ pub extern "C" fn install_rust_panic_hoo
     let default_hook = panic::take_hook();
     panic::set_hook(Box::new(move |info| {
         // Try to handle &str/String payloads, which should handle 99% of cases.
         let payload = info.payload();
         // We'll hold a raw *const str here, but it will be OK because
         // Rust is going to abort the process before the payload could be
         // deallocated.
         if let Some(s) = payload.downcast_ref::<&str>() {
-            unsafe { PANIC_REASON = Some((*s as *const str, s.len())) }
+            unsafe { PANIC_REASON = Some(*s as *const str); }
         } else if let Some(s) = payload.downcast_ref::<String>() {
-            unsafe { PANIC_REASON = Some((s.as_str() as *const str, s.len())) }
+            unsafe { PANIC_REASON = Some(s.as_str() as *const str); }
         } else {
             // Not the most helpful thing, but seems unlikely to happen
             // in practice.
             println!("Unhandled panic payload!");
         }
         // Fall through to the default hook so we still print the reason and
         // backtrace to the console.
         default_hook(info);
     }));
 }
 
 #[no_mangle]
 pub extern "C" fn get_rust_panic_reason(reason: *mut *const c_char, length: *mut usize) -> bool {
     unsafe {
-        match PANIC_REASON {
-            Some((s, len)) => {
-                *reason = s as *const c_char;
-                *length = len;
-                true
-            }
-            None => false,
+        if let Some(s) = PANIC_REASON {
+            *reason = s as *const c_char;
+            *length = (*s).len();
+            true
+        } else {
+            false
         }
     }
 }