Skip to content

Commit a24507f

Browse files
committed
fix test
Signed-off-by: Yuhao Su <[email protected]>
1 parent 6fc530b commit a24507f

File tree

3 files changed

+30
-45
lines changed

3 files changed

+30
-45
lines changed

jemalloc-ctl/src/macros.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,25 @@ macro_rules! w {
114114
#[test]
115115
#[cfg(not(target_arch = "mips64el"))]
116116
fn [<$id _write_test>]() {
117-
// /// Help test write
118-
// pub trait WriteTestDefault {
119-
// fn default() -> Self;
120-
// }
121-
// macro_rules! impl_write_test_default {
122-
// ($write_ty:ty, $val:expr) => {
123-
// impl WriteTestDefault for $write_ty {
124-
// fn default() -> $write_ty {
125-
// $val
126-
// }
127-
// }
128-
// };
129-
// }
117+
/// Help test write
118+
pub trait WriteTestDefault {
119+
fn default() -> Self;
120+
}
121+
macro_rules! impl_write_test_default {
122+
($write_ty:ty, $val:expr) => {
123+
impl WriteTestDefault for $write_ty {
124+
fn default() -> $write_ty {
125+
$val
126+
}
127+
}
128+
};
129+
}
130130

131-
// use crate::ffi::CStr;
132-
// impl_write_test_default! {libc::size_t, 0}
133-
// impl_write_test_default! {u64, 0}
134-
// impl_write_test_default! {bool, false}
135-
// impl_write_test_default! {&'static CStr, CStr::from_bytes_with_nul(b"test\0").unwrap()}
131+
use crate::ffi::CStr;
132+
impl_write_test_default! {libc::size_t, 0}
133+
impl_write_test_default! {u64, 0}
134+
impl_write_test_default! {bool, false}
135+
impl_write_test_default! {&'static CStr, CStr::from_bytes_with_nul(b"test\0").unwrap()}
136136

137137
match stringify!($id) {
138138
"background_thread" |
@@ -141,10 +141,10 @@ macro_rules! w {
141141
_ => (),
142142
}
143143

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

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

149149
#[cfg(feature = "use_std")]
150150
println!(

jemalloc-ctl/src/prof.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ option! {
1818
/// #
1919
/// # fn main() {
2020
/// use tikv_jemalloc_ctl::prof;
21+
/// use std::ffi::CStr;
22+
/// let dump_file_name = CStr::from_bytes_with_nul(b"dump\0").unwrap();
2123
/// let dump = prof::dump::mib().unwrap();
22-
/// prof.write("prof.heap").unwrap();
24+
/// dump.write(dump_file_name).unwrap();
2325
/// # }
2426
/// ```
2527
mib_docs: /// See [`dump`].
@@ -41,8 +43,10 @@ option! {
4143
/// #
4244
/// # fn main() {
4345
/// use tikv_jemalloc_ctl::prof;
46+
/// use std::ffi::CStr;
47+
/// let dump_file_name = CStr::from_bytes_with_nul(b"my_prefix\0").unwrap();
4448
/// let prefix = prof::prefix::mib().unwrap();
45-
/// prefix.write("my_prefix").unwrap();
49+
/// prefix.write(dump_file_name).unwrap();
4650
/// # }
4751
/// ```
4852
mib_docs: /// See [`prefix`].
@@ -52,9 +56,9 @@ option! {
5256
active[ str: b"prof.active\0", non_str: 2 ] => bool |
5357
ops: r, w, u |
5458
docs:
55-
/// Control whether sampling is currently active.
59+
/// Control whether sampling is currently active.
5660
///
57-
/// See the `opt.prof_active` option for additional information,
61+
/// See the `opt.prof_active` option for additional information,
5862
/// as well as the interrelated `thread.prof.active` mallctl.
5963
///
6064
/// # Examples
@@ -70,4 +74,4 @@ option! {
7074
/// # }
7175
/// ```
7276
mib_docs: /// See [`active`].
73-
}
77+
}

jemalloc-ctl/src/raw.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,6 @@ pub unsafe fn write<T>(name: &[u8], mut value: T) -> Result<()> {
146146
))
147147
}
148148

149-
/// Uses the null-terminated string `name` as the key to the _MALLCTL NAMESPACE_
150-
/// and writes it string `value`
151-
///
152-
/// # Safety
153-
///
154-
/// This function is `unsafe` because it is possible to pass a string that does not
155-
/// match it's len.
156-
pub unsafe fn write_str_unsafe(name: &[u8], mut value: *const c_char, len: usize) -> Result<()> {
157-
validate_name(name);
158-
159-
cvt(tikv_jemalloc_sys::mallctl(
160-
name as *const _ as *const c_char,
161-
ptr::null_mut(),
162-
ptr::null_mut(),
163-
&mut value as *mut _ as *mut _,
164-
len,
165-
))
166-
}
167-
168149
/// Uses the MIB `mib` as key to the _MALLCTL NAMESPACE_ and writes its `value`
169150
/// returning its previous value.
170151
///
@@ -332,7 +313,7 @@ pub fn write_str(name: &[u8], value: &'static [u8]) -> Result<()> {
332313
// This is safe because `value` will always point to a null-terminated
333314
// string, which makes it safe for all key value types: pointers to
334315
// null-terminated strings, pointers, pointer-sized integers, etc.
335-
unsafe { write_str_unsafe(name, value.as_ptr() as *const c_char, value.len()) }
316+
unsafe { write(name, value.as_ptr() as *const c_char) }
336317
}
337318

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

0 commit comments

Comments
 (0)