aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11/headless.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/x11/headless.rs')
-rw-r--r--src/x11/headless.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/x11/headless.rs b/src/x11/headless.rs
index b4a6ba0..d13d1d0 100644
--- a/src/x11/headless.rs
+++ b/src/x11/headless.rs
@@ -5,6 +5,12 @@ use libc;
use std::{mem, ptr};
use super::ffi;
+fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const i8) -> T {
+ use std::ffi::CString;
+ let c_str = CString::from_slice(s.as_bytes());
+ f(c_str.as_slice_with_nul().as_ptr())
+}
+
pub struct HeadlessContext {
context: ffi::OSMesaContext,
buffer: Vec<u32>,
@@ -41,10 +47,8 @@ impl HeadlessContext {
}
pub fn get_proc_address(&self, addr: &str) -> *const () {
- use std::c_str::ToCStr;
-
unsafe {
- addr.with_c_str(|s| {
+ with_c_str(addr, |s| {
ffi::OSMesaGetProcAddress(mem::transmute(s)) as *const ()
})
}