1
0
Fork 0
forked from wry/wry

Merge pull request #304 from mahkoh/jorth/edition-2024

it: handle new warnings
This commit is contained in:
mahkoh 2024-10-20 18:52:01 +02:00 committed by GitHub
commit cc426a0a4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 35 deletions

View file

@ -59,25 +59,29 @@ unsafe extern "C" fn init(
) -> *const u8 {
let tc = CONFIG.get();
assert!(tc.is_not_null());
Rc::increment_strong_count(tc);
{
let tc = &*tc;
tc.srv.set(Some(ServerData {
srv_data,
srv_unref,
srv_handler,
}));
unsafe {
Rc::increment_strong_count(tc);
{
let tc = &*tc;
tc.srv.set(Some(ServerData {
srv_data,
srv_unref,
srv_handler,
}));
}
tc.cast()
}
tc.cast()
}
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) {
let tc = &*data.cast::<TestConfig>();
let msg = std::slice::from_raw_parts(msg, size);
let tc = unsafe { &*data.cast::<TestConfig>() };
let msg = unsafe { std::slice::from_raw_parts(msg, size) };
let res = bincode_ops().deserialize::<ServerMessage>(msg);
let msg = match res {
Ok(msg) => msg,

View file

@ -270,29 +270,33 @@ mod leaks {
unsafe impl GlobalAlloc for TracingAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let res = c::calloc(layout.size(), 1) as *mut u8;
if IN_ALLOCATOR.get() == 0 {
IN_ALLOCATOR.set(1);
ALLOCATIONS.get().deref_mut().insert(
res,
Allocation {
addr: res,
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);
unsafe {
let res = c::calloc(layout.size(), 1) as *mut u8;
if IN_ALLOCATOR.get() == 0 {
IN_ALLOCATOR.set(1);
ALLOCATIONS.get().deref_mut().insert(
res,
Allocation {
addr: res,
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);
}
res
}
res
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
if INITIALIZED.get() {
ALLOCATIONS.get().deref_mut().remove(&ptr);
unsafe {
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 _);
}
}

View file

@ -183,16 +183,18 @@ unsafe extern "C" fn ___tracy_demangle(
if mangled.is_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();
};
let demangled = rustc_demangle::demangle(mangled);
static mut BUF: Vec<u8> = Vec::new();
BUF.clear();
if write!(BUF, "{demangled:#}\0").is_err() {
return ptr::null();
unsafe {
BUF.clear();
if write!(BUF, "{demangled:#}\0").is_err() {
return ptr::null();
}
BUF.as_ptr().cast()
}
BUF.as_ptr().cast()
}
static ENABLED: AtomicBool = AtomicBool::new(false);