aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11/headless.rs
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-01-08 13:44:26 +0100
committertomaka <pierre.krieger1708@gmail.com>2015-01-08 13:44:26 +0100
commit181e4a1d8f12136c73add790003f3372319f82f6 (patch)
tree376f5ff328731fb4678c943ae70caa040e642ba3 /src/x11/headless.rs
parent25b261975c6756a3e0f9ee36107f185103b35292 (diff)
parent3920cd5e80e2ba9bae83dc2934b05453b848cc7d (diff)
downloadglutin-181e4a1d8f12136c73add790003f3372319f82f6.tar.gz
glutin-181e4a1d8f12136c73add790003f3372319f82f6.zip
Merge pull request #187 from tomaka/update-rustc
Update for Rustc
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 ()
})
}