Skip to content

Commit 885f98c

Browse files
committed
Lint.
1 parent b90d648 commit 885f98c

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

memapi/src/lib.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ pub extern "C" fn pymemprofile_free_allocation(address: usize) {
1616
memorytracking::free_allocation(address);
1717
}
1818

19+
/// # Safety
20+
/// Intended for use from C APIs, what can I say.
1921
#[no_mangle]
20-
pub extern "C" fn pymemprofile_start_call(file_name: *const c_char, func_name: *const c_char) {
21-
let name = unsafe {
22-
format!(
23-
"{}:{}",
24-
CStr::from_ptr(file_name)
25-
.to_str()
26-
.expect("Function name wasn't UTF-8"),
27-
CStr::from_ptr(func_name)
28-
.to_str()
29-
.expect("Function name wasn't UTF-8")
30-
)
31-
};
22+
pub unsafe extern "C" fn pymemprofile_start_call(
23+
file_name: *const c_char,
24+
func_name: *const c_char,
25+
) {
26+
let name = format!(
27+
"{}:{}",
28+
CStr::from_ptr(file_name)
29+
.to_str()
30+
.expect("Function name wasn't UTF-8"),
31+
CStr::from_ptr(func_name)
32+
.to_str()
33+
.expect("Function name wasn't UTF-8")
34+
);
3235
memorytracking::start_call(name);
3336
}
3437

@@ -42,14 +45,14 @@ pub extern "C" fn pymemprofile_reset() {
4245
memorytracking::reset();
4346
}
4447

48+
/// # Safety
49+
/// Intended for use from C APIs, what can I say.
4550
#[no_mangle]
46-
pub extern "C" fn pymemprofile_dump_peak_to_flamegraph(path: *const c_char) {
47-
let path = unsafe {
48-
CStr::from_ptr(path)
49-
.to_str()
50-
.expect("Path wasn't UTF-8")
51-
.to_string()
52-
};
51+
pub unsafe extern "C" fn pymemprofile_dump_peak_to_flamegraph(path: *const c_char) {
52+
let path = CStr::from_ptr(path)
53+
.to_str()
54+
.expect("Path wasn't UTF-8")
55+
.to_string();
5356
memorytracking::dump_peak_to_flamegraph(&path);
5457
}
5558

memapi/src/memorytracking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ impl Callstack {
2525
self.calls.pop();
2626
}
2727

28-
fn to_string(&self) -> String {
29-
if self.calls.len() == 0 {
28+
fn as_string(&self) -> String {
29+
if self.calls.is_empty() {
3030
"[No Python stack]".to_string()
3131
} else {
3232
self.calls.iter().join(";")
@@ -89,7 +89,7 @@ impl AllocationTracker {
8989
let mut by_call: collections::HashMap<String, usize> = collections::HashMap::new();
9090
let peak_allocations = &self.peak_allocations;
9191
for Allocation { callstack, size } in peak_allocations.values() {
92-
let callstack = callstack.to_string();
92+
let callstack = callstack.as_string();
9393
let entry = by_call.entry(callstack).or_insert(0);
9494
*entry += size;
9595
}
@@ -174,7 +174,7 @@ fn write_flamegraph<'a, I: IntoIterator<Item = &'a str>>(
174174
peak_bytes as f64 / (1024.0 * 1024.0)
175175
);
176176
let mut options = flamegraph::Options {
177-
title: title,
177+
title,
178178
direction: flamegraph::Direction::Inverted,
179179
count_name: "KiB".to_string(),
180180
colors: flamegraph::color::Palette::Basic(flamegraph::color::BasicPalette::Mem),

0 commit comments

Comments
 (0)