79736414

Date: 2025-08-15 12:25:28
Score: 1
Natty:
Report link

After scouring the internet some more, I found the answer here: Circumventing thread safety in rust with mutable pointers

And so, for my case, it looks like this:

pub struct TrblFile {
    logicalFileName: *const ::std::os::raw::c_char,
    opaque: *const ::std::os::raw::c_void,
}

// raw pointers are not thread-safe according to the compiler
// here we tell it thread-safety will be handled by us
unsafe impl Send for TrblFile {}

[...]

        if let Some(cb) = storeCb {
            let params = TrblFile { logicalFileName: copy_cstr(logicalFileName),
                                    opaque: opaque };
            let callback = Box::new(move || {
                unsafe {
                    let result = cb(params.logicalFileName, params.opaque);
                    libc::free(params.logicalFileName as * mut c_void);
                    result
                }
            });
            let mut callbacks = STORE_CALLBACKS.lock();
            callbacks.push(callback);
        }
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: DerKastellan