forked from MariaDB/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
To my best understanding, it looks like the SQL side only looks for a pointer at the address of this struct. So, I think we could do something like this:
use std::sync::{atomic::AtomicPtr, Mutex};
use std::ffi::{CString, c_char};
use std::marker::PhantomPinned;
#[repr(C)]
struct SysVarString {
ptr: AtomicPtr<c_char>,
cs: Mutex<Option<CString>>,
pin: PhantomPinned
}
impl SysVarString {
fn update(&self, save: *const c_char) {
// lock mutex
if ptr.is_none() { self.cs = None}
else { self.cs = CString::new(CStr::from_ptr(save).expect("non UTF-8")).unwrap() }
self.ptr = cs.as_ref().map_or(std::ptr::null(), |cs| cs.as_ptr());
}
}
A safety caveat is that we need to be sure SQL doesn't write to this buffer. I think this would actually be completely thread safe as well (well, the C side wouldn't atomically read the pointer, but I'm not sure what we could do there)
Metadata
Metadata
Assignees
Labels
No labels