reformat
This commit is contained in:
parent
491551e09a
commit
8b54b6f9d5
|
@ -40,7 +40,10 @@ impl fmt::Debug for Error {
|
||||||
small; in this case as much data as possible are read \
|
small; in this case as much data as possible are read \
|
||||||
despite the error."
|
despite the error."
|
||||||
),
|
),
|
||||||
libc::ENOENT => write!(f, "`name` or `mib` specifies an unknown/invalid value."),
|
libc::ENOENT => write!(
|
||||||
|
f,
|
||||||
|
"`name` or `mib` specifies an unknown/invalid value."
|
||||||
|
),
|
||||||
libc::EPERM => write!(
|
libc::EPERM => write!(
|
||||||
f,
|
f,
|
||||||
"Attempt to read or write `void` value, or attempt to \
|
"Attempt to read or write `void` value, or attempt to \
|
||||||
|
|
|
@ -110,7 +110,9 @@ impl Name {
|
||||||
| b"thread.prof.name"
|
| b"thread.prof.name"
|
||||||
| b"prof.dump" => true,
|
| b"prof.dump" => true,
|
||||||
v if v.starts_with(b"arena.") && v.ends_with(b".dss") => true,
|
v if v.starts_with(b"arena.") && v.ends_with(b".dss") => true,
|
||||||
v if v.starts_with(b"stats.arenas.") && v.ends_with(b".dss") => true,
|
v if v.starts_with(b"stats.arenas.") && v.ends_with(b".dss") => {
|
||||||
|
true
|
||||||
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,7 +323,8 @@ impl<T: MibArg> Access<&'static str> for MibStr<T> {
|
||||||
fn update(&self, value: &'static str) -> Result<&'static str> {
|
fn update(&self, value: &'static str) -> Result<&'static str> {
|
||||||
// this is safe because the only safe way to construct a `MibStr` is by
|
// this is safe because the only safe way to construct a `MibStr` is by
|
||||||
// validating that the key refers to a byte-string value
|
// validating that the key refers to a byte-string value
|
||||||
let s = unsafe { raw::update_str_mib(self.0.as_ref(), value.as_bytes())? };
|
let s =
|
||||||
|
unsafe { raw::update_str_mib(self.0.as_ref(), value.as_bytes())? };
|
||||||
Ok(str::from_utf8(s).unwrap())
|
Ok(str::from_utf8(s).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -431,10 +434,22 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MibArg:
|
pub trait MibArg:
|
||||||
Copy + Clone + PartialEq + Default + fmt::Debug + AsRef<[usize]> + AsMut<[usize]>
|
Copy
|
||||||
|
+ Clone
|
||||||
|
+ PartialEq
|
||||||
|
+ Default
|
||||||
|
+ fmt::Debug
|
||||||
|
+ AsRef<[usize]>
|
||||||
|
+ AsMut<[usize]>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
impl<T> MibArg for T where
|
impl<T> MibArg for T where
|
||||||
T: Copy + Clone + PartialEq + Default + fmt::Debug + AsRef<[usize]> + AsMut<[usize]>
|
T: Copy
|
||||||
|
+ Clone
|
||||||
|
+ PartialEq
|
||||||
|
+ Default
|
||||||
|
+ fmt::Debug
|
||||||
|
+ AsRef<[usize]>
|
||||||
|
+ AsMut<[usize]>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs, intra_doc_link_resolution_failure)]
|
||||||
#![cfg_attr(not(feature = "use_std"), no_std)]
|
#![cfg_attr(not(feature = "use_std"), no_std)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy::stutter))]
|
#![cfg_attr(feature = "cargo-clippy", allow(clippy::stutter))]
|
||||||
#![feature(coerce_unsized)]
|
#![feature(coerce_unsized)]
|
||||||
|
|
|
@ -273,7 +273,10 @@ pub fn write_str_mib(mib: &[usize], value: &'static [u8]) -> Result<()> {
|
||||||
/// If the pointer is valid but it does not point to a null-terminated string,
|
/// If the pointer is valid but it does not point to a null-terminated string,
|
||||||
/// looking for `\0` will read garbage and might end up reading out-of-bounds,
|
/// looking for `\0` will read garbage and might end up reading out-of-bounds,
|
||||||
/// which is undefined behavior.
|
/// which is undefined behavior.
|
||||||
pub unsafe fn update_str_mib(mib: &[usize], value: &'static [u8]) -> Result<&'static [u8]> {
|
pub unsafe fn update_str_mib(
|
||||||
|
mib: &[usize],
|
||||||
|
value: &'static [u8],
|
||||||
|
) -> Result<&'static [u8]> {
|
||||||
let ptr: *const c_char = update_mib(mib, value.as_ptr() as *const c_char)?;
|
let ptr: *const c_char = update_mib(mib, value.as_ptr() as *const c_char)?;
|
||||||
ptr2str(ptr)
|
ptr2str(ptr)
|
||||||
}
|
}
|
||||||
|
@ -340,7 +343,10 @@ pub fn write_str(name: &[u8], value: &'static [u8]) -> Result<()> {
|
||||||
/// If the pointer is valid but it does not point to a null-terminated string,
|
/// If the pointer is valid but it does not point to a null-terminated string,
|
||||||
/// looking for `\0` will read garbage and might end up reading out-of-bounds,
|
/// looking for `\0` will read garbage and might end up reading out-of-bounds,
|
||||||
/// which is undefined behavior.
|
/// which is undefined behavior.
|
||||||
pub unsafe fn update_str(name: &[u8], value: &'static [u8]) -> Result<&'static [u8]> {
|
pub unsafe fn update_str(
|
||||||
|
name: &[u8],
|
||||||
|
value: &'static [u8],
|
||||||
|
) -> Result<&'static [u8]> {
|
||||||
let ptr: *const c_char = update(name, value.as_ptr() as *const c_char)?;
|
let ptr: *const c_char = update(name, value.as_ptr() as *const c_char)?;
|
||||||
ptr2str(ptr)
|
ptr2str(ptr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
let buf = CStr::from_ptr(buf);
|
let buf = CStr::from_ptr(buf);
|
||||||
match panic::catch_unwind(AssertUnwindSafe(|| state.writer.write_all(buf.to_bytes()))) {
|
match panic::catch_unwind(AssertUnwindSafe(|| {
|
||||||
|
state.writer.write_all(buf.to_bytes())
|
||||||
|
})) {
|
||||||
Ok(Ok(_)) => {}
|
Ok(Ok(_)) => {}
|
||||||
Ok(Err(e)) => state.error = Err(e),
|
Ok(Err(e)) => state.error = Err(e),
|
||||||
Err(e) => state.panic = Err(e),
|
Err(e) => state.panic = Err(e),
|
||||||
|
|
Loading…
Reference in New Issue