Merge pull request #304 from mahkoh/jorth/edition-2024
it: handle new warnings
This commit is contained in:
commit
cc426a0a4a
3 changed files with 45 additions and 35 deletions
|
|
@ -59,25 +59,29 @@ unsafe extern "C" fn init(
|
||||||
) -> *const u8 {
|
) -> *const u8 {
|
||||||
let tc = CONFIG.get();
|
let tc = CONFIG.get();
|
||||||
assert!(tc.is_not_null());
|
assert!(tc.is_not_null());
|
||||||
Rc::increment_strong_count(tc);
|
unsafe {
|
||||||
{
|
Rc::increment_strong_count(tc);
|
||||||
let tc = &*tc;
|
{
|
||||||
tc.srv.set(Some(ServerData {
|
let tc = &*tc;
|
||||||
srv_data,
|
tc.srv.set(Some(ServerData {
|
||||||
srv_unref,
|
srv_data,
|
||||||
srv_handler,
|
srv_unref,
|
||||||
}));
|
srv_handler,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
tc.cast()
|
||||||
}
|
}
|
||||||
tc.cast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn unref(data: *const u8) {
|
unsafe extern "C" fn unref(data: *const u8) {
|
||||||
Rc::decrement_strong_count(data.cast::<TestConfig>());
|
unsafe {
|
||||||
|
Rc::decrement_strong_count(data.cast::<TestConfig>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
||||||
let tc = &*data.cast::<TestConfig>();
|
let tc = unsafe { &*data.cast::<TestConfig>() };
|
||||||
let msg = std::slice::from_raw_parts(msg, size);
|
let msg = unsafe { std::slice::from_raw_parts(msg, size) };
|
||||||
let res = bincode_ops().deserialize::<ServerMessage>(msg);
|
let res = bincode_ops().deserialize::<ServerMessage>(msg);
|
||||||
let msg = match res {
|
let msg = match res {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
|
|
|
||||||
40
src/leaks.rs
40
src/leaks.rs
|
|
@ -270,29 +270,33 @@ mod leaks {
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for TracingAllocator {
|
unsafe impl GlobalAlloc for TracingAllocator {
|
||||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
let res = c::calloc(layout.size(), 1) as *mut u8;
|
unsafe {
|
||||||
if IN_ALLOCATOR.get() == 0 {
|
let res = c::calloc(layout.size(), 1) as *mut u8;
|
||||||
IN_ALLOCATOR.set(1);
|
if IN_ALLOCATOR.get() == 0 {
|
||||||
ALLOCATIONS.get().deref_mut().insert(
|
IN_ALLOCATOR.set(1);
|
||||||
res,
|
ALLOCATIONS.get().deref_mut().insert(
|
||||||
Allocation {
|
res,
|
||||||
addr: res,
|
Allocation {
|
||||||
len: layout.size(),
|
addr: res,
|
||||||
backtrace: Backtrace::new_unresolved(),
|
len: layout.size(),
|
||||||
},
|
backtrace: Backtrace::new_unresolved(),
|
||||||
);
|
},
|
||||||
// log::info!("allocated [0x{:x}, 0x{:x})", res as usize, res as usize + layout.size());
|
);
|
||||||
IN_ALLOCATOR.set(0);
|
// log::info!("allocated [0x{:x}, 0x{:x})", res as usize, res as usize + layout.size());
|
||||||
|
IN_ALLOCATOR.set(0);
|
||||||
|
}
|
||||||
|
res
|
||||||
}
|
}
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||||
if INITIALIZED.get() {
|
unsafe {
|
||||||
ALLOCATIONS.get().deref_mut().remove(&ptr);
|
if INITIALIZED.get() {
|
||||||
|
ALLOCATIONS.get().deref_mut().remove(&ptr);
|
||||||
|
}
|
||||||
|
// c::memset(ptr as _, 0, layout.size());
|
||||||
|
c::free(ptr as _);
|
||||||
}
|
}
|
||||||
// c::memset(ptr as _, 0, layout.size());
|
|
||||||
c::free(ptr as _);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,16 +183,18 @@ unsafe extern "C" fn ___tracy_demangle(
|
||||||
if mangled.is_null() {
|
if mangled.is_null() {
|
||||||
return ptr::null();
|
return ptr::null();
|
||||||
}
|
}
|
||||||
let Ok(mangled) = CStr::from_ptr(mangled).to_str() else {
|
let Ok(mangled) = unsafe { CStr::from_ptr(mangled) }.to_str() else {
|
||||||
return ptr::null();
|
return ptr::null();
|
||||||
};
|
};
|
||||||
let demangled = rustc_demangle::demangle(mangled);
|
let demangled = rustc_demangle::demangle(mangled);
|
||||||
static mut BUF: Vec<u8> = Vec::new();
|
static mut BUF: Vec<u8> = Vec::new();
|
||||||
BUF.clear();
|
unsafe {
|
||||||
if write!(BUF, "{demangled:#}\0").is_err() {
|
BUF.clear();
|
||||||
return ptr::null();
|
if write!(BUF, "{demangled:#}\0").is_err() {
|
||||||
|
return ptr::null();
|
||||||
|
}
|
||||||
|
BUF.as_ptr().cast()
|
||||||
}
|
}
|
||||||
BUF.as_ptr().cast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ENABLED: AtomicBool = AtomicBool::new(false);
|
static ENABLED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue