diff options
author | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-01-08 12:58:35 +0100 |
---|---|---|
committer | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-01-08 12:58:58 +0100 |
commit | 3920cd5e80e2ba9bae83dc2934b05453b848cc7d (patch) | |
tree | 376f5ff328731fb4678c943ae70caa040e642ba3 /src/x11/headless.rs | |
parent | dbdb43f077f4fa016e9f3f65345c4a947eceaa77 (diff) | |
parent | 8d9133d3318c81021b1179f2cafe368650b4e7c8 (diff) | |
download | glutin-3920cd5e80e2ba9bae83dc2934b05453b848cc7d.tar.gz glutin-3920cd5e80e2ba9bae83dc2934b05453b848cc7d.zip |
Merge remote-tracking branch 'cybergeek94/master' into update-rustc
Conflicts:
examples/support/mod.rs
src/lib.rs
tests/headless.rs
Diffstat (limited to 'src/x11/headless.rs')
-rw-r--r-- | src/x11/headless.rs | 10 |
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 () }) } |