Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Yuhao Su <[email protected]>
  • Loading branch information
yuhao-su committed Jul 24, 2023
1 parent 3db2c58 commit 52c834d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
40 changes: 20 additions & 20 deletions jemalloc-ctl/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,25 @@ macro_rules! w {
#[test]
#[cfg(not(target_arch = "mips64el"))]
fn [<$id _write_test>]() {
// /// Help test write
// pub trait WriteTestDefault {
// fn default() -> Self;
// }
// macro_rules! impl_write_test_default {
// ($write_ty:ty, $val:expr) => {
// impl WriteTestDefault for $write_ty {
// fn default() -> $write_ty {
// $val
// }
// }
// };
// }
/// Help test write
pub trait WriteTestDefault {
fn default() -> Self;
}
macro_rules! impl_write_test_default {
($write_ty:ty, $val:expr) => {
impl WriteTestDefault for $write_ty {
fn default() -> $write_ty {
$val
}
}
};
}

// use crate::ffi::CStr;
// impl_write_test_default! {libc::size_t, 0}
// impl_write_test_default! {u64, 0}
// impl_write_test_default! {bool, false}
// impl_write_test_default! {&'static CStr, CStr::from_bytes_with_nul(b"test\0").unwrap()}
use crate::ffi::CStr;
impl_write_test_default! {libc::size_t, 0}
impl_write_test_default! {u64, 0}
impl_write_test_default! {bool, false}
impl_write_test_default! {&'static CStr, CStr::from_bytes_with_nul(b"test\0").unwrap()}

match stringify!($id) {
"background_thread" |
Expand All @@ -141,10 +141,10 @@ macro_rules! w {
_ => (),
}

let _ = $id::write(<$ret_ty as Default>::default()).unwrap();
let _ = $id::write(<$ret_ty as WriteTestDefault>::default()).unwrap();

let mib = $id::mib().unwrap();
let _ = mib.write(<$ret_ty as Default>::default()).unwrap();
let _ = mib.write(<$ret_ty as WriteTestDefault>::default()).unwrap();

#[cfg(feature = "use_std")]
println!(
Expand Down
14 changes: 9 additions & 5 deletions jemalloc-ctl/src/prof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ option! {
/// #
/// # fn main() {
/// use tikv_jemalloc_ctl::prof;
/// use std::ffi::CStr;
/// let dump_file_name = CStr::from_bytes_with_nul(b"dump\0").unwrap();
/// let dump = prof::dump::mib().unwrap();
/// prof.write("prof.heap").unwrap();
/// dump.write(dump_file_name).unwrap();
/// # }
/// ```
mib_docs: /// See [`dump`].
Expand All @@ -41,8 +43,10 @@ option! {
/// #
/// # fn main() {
/// use tikv_jemalloc_ctl::prof;
/// use std::ffi::CStr;
/// let dump_file_name = CStr::from_bytes_with_nul(b"my_prefix\0").unwrap();
/// let prefix = prof::prefix::mib().unwrap();
/// prefix.write("my_prefix").unwrap();
/// prefix.write(dump_file_name).unwrap();
/// # }
/// ```
mib_docs: /// See [`prefix`].
Expand All @@ -52,9 +56,9 @@ option! {
active[ str: b"prof.active\0", non_str: 2 ] => bool |
ops: r, w, u |
docs:
/// Control whether sampling is currently active.
/// Control whether sampling is currently active.
///
/// See the `opt.prof_active` option for additional information,
/// See the `opt.prof_active` option for additional information,
/// as well as the interrelated `thread.prof.active` mallctl.
///
/// # Examples
Expand All @@ -70,4 +74,4 @@ option! {
/// # }
/// ```
mib_docs: /// See [`active`].
}
}
21 changes: 1 addition & 20 deletions jemalloc-ctl/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,6 @@ pub unsafe fn write<T>(name: &[u8], mut value: T) -> Result<()> {
))
}

/// Uses the null-terminated string `name` as the key to the _MALLCTL NAMESPACE_
/// and writes it string `value`
///
/// # Safety
///
/// This function is `unsafe` because it is possible to pass a string that does not
/// match it's len.
pub unsafe fn write_str_unsafe(name: &[u8], mut value: *const c_char, len: usize) -> Result<()> {
validate_name(name);

cvt(tikv_jemalloc_sys::mallctl(
name as *const _ as *const c_char,
ptr::null_mut(),
ptr::null_mut(),
&mut value as *mut _ as *mut _,
len,
))
}

/// Uses the MIB `mib` as key to the _MALLCTL NAMESPACE_ and writes its `value`
/// returning its previous value.
///
Expand Down Expand Up @@ -332,7 +313,7 @@ pub fn write_str(name: &[u8], value: &'static [u8]) -> Result<()> {
// This is safe because `value` will always point to a null-terminated
// string, which makes it safe for all key value types: pointers to
// null-terminated strings, pointers, pointer-sized integers, etc.
unsafe { write_str_unsafe(name, value.as_ptr() as *const c_char, value.len()) }
unsafe { write(name, value.as_ptr() as *const c_char) }
}

/// Uses the null-terminated string `name` as key to the _MALLCTL NAMESPACE_ and
Expand Down

0 comments on commit 52c834d

Please sign in to comment.