@@ -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
0 commit comments