aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2015-04-02 22:04:17 +0200
committerPierre Krieger <pierre.krieger1708@gmail.com>2015-04-02 22:41:35 +0200
commitd33c138164d069f025439f97920771f1f8c7775e (patch)
treed54b6953a9540d3b9e93c7a76ac48814be8c9773
parent2e1fe8283f82208375737674a731d2fe3c5e4539 (diff)
downloadglutin-d33c138164d069f025439f97920771f1f8c7775e.tar.gz
glutin-d33c138164d069f025439f97920771f1f8c7775e.zip
Rustup
-rw-r--r--examples/multiwindow.rs8
-rw-r--r--examples/support/mod.rs5
-rw-r--r--src/lib.rs2
-rw-r--r--src/win32/callback.rs18
-rw-r--r--src/win32/init.rs27
-rw-r--r--src/win32/make_current_guard.rs4
-rw-r--r--src/x11/headless.rs12
-rw-r--r--src/x11/window/mod.rs4
8 files changed, 32 insertions, 48 deletions
diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs
index a7680b8..9256555 100644
--- a/examples/multiwindow.rs
+++ b/examples/multiwindow.rs
@@ -6,7 +6,7 @@ extern crate android_glue;
extern crate glutin;
-use std::thread::Thread;
+use std::thread;
mod support;
@@ -22,15 +22,15 @@ fn main() {
let window2 = glutin::Window::new().unwrap();
let window3 = glutin::Window::new().unwrap();
- let t1 = Thread::scoped(move || {
+ let t1 = thread::scoped(move || {
run(window1, (0.0, 1.0, 0.0, 1.0));
});
- let t2 = Thread::scoped(move || {
+ let t2 = thread::scoped(move || {
run(window2, (0.0, 0.0, 1.0, 1.0));
});
- let t3 = Thread::scoped(move || {
+ let t3 = thread::scoped(move || {
run(window3, (1.0, 0.0, 0.0, 1.0));
});
diff --git a/examples/support/mod.rs b/examples/support/mod.rs
index 94ef1a7..329bd4b 100644
--- a/examples/support/mod.rs
+++ b/examples/support/mod.rs
@@ -1,5 +1,6 @@
#![cfg(feature = "window")]
+use std::ffi::CStr;
use glutin;
#[cfg(not(target_os = "android"))]
@@ -21,8 +22,8 @@ pub fn load(window: &glutin::Window) -> Context {
let gl = gl::Gl::load(window);
let version = unsafe {
- use std::ffi;
- String::from_utf8(ffi::c_str_to_bytes(&(gl.GetString(gl::VERSION) as *const i8)).to_vec()).unwrap()
+ let data = CStr::from_ptr(gl.GetString(gl::VERSION) as *const i8).to_bytes().to_vec();
+ String::from_utf8(data).unwrap()
};
println!("OpenGL version {}", version);
diff --git a/src/lib.rs b/src/lib.rs
index c97f769..cf06b7b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,4 @@
-#![feature(collections, unsafe_destructor, os, core, std_misc, alloc)]
+#![feature(collections, unsafe_destructor, core, std_misc, alloc)]
#![unstable]
//! The purpose of this library is to provide an OpenGL context on as many
diff --git a/src/win32/callback.rs b/src/win32/callback.rs
index 66d88e7..e852eeb 100644
--- a/src/win32/callback.rs
+++ b/src/win32/callback.rs
@@ -1,12 +1,8 @@
use std::mem;
use std::ptr;
-use std::rc::Rc;
use std::cell::RefCell;
use std::sync::mpsc::Sender;
-use std::sync::{
- Arc,
- Mutex
-};
+use std::sync::{Arc, Mutex};
use CursorState;
use Event;
@@ -232,16 +228,12 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
if let Ok(cursor_state) = cstash.cursor_state.lock() {
match *cursor_state {
CursorState::Normal => {
- unsafe {
- user32::SetCursor(user32::LoadCursorW(
- ptr::null_mut(),
- winapi::IDC_ARROW));
- }
+ user32::SetCursor(user32::LoadCursorW(
+ ptr::null_mut(),
+ winapi::IDC_ARROW));
},
CursorState::Grab | CursorState::Hide => {
- unsafe {
- user32::SetCursor(ptr::null_mut());
- }
+ user32::SetCursor(ptr::null_mut());
}
}
}
diff --git a/src/win32/init.rs b/src/win32/init.rs
index d0012e2..0a77cb7 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -1,11 +1,8 @@
use std::sync::atomic::AtomicBool;
-use std::sync::{
- Arc,
- Mutex
-};
+use std::sync::{Arc, Mutex};
+use std::io;
use std::ptr;
use std::mem;
-use std::os;
use std::thread;
use super::callback;
@@ -41,7 +38,7 @@ pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<C
-> Result<Window, CreationError>
{
// initializing variables to be sent to the task
- let title = builder.title.as_slice().utf16_units()
+ let title = builder.title.utf16_units()
.chain(Some(0).into_iter()).collect::<Vec<u16>>(); // title to utf16
let (tx, rx) = channel();
@@ -125,13 +122,13 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
if handle.is_null() {
return Err(OsError(format!("CreateWindowEx function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
let hdc = user32::GetDC(handle);
if hdc.is_null() {
let err = Err(OsError(format!("GetDC function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
return err;
}
@@ -191,13 +188,13 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
if handle.is_null() {
return Err(OsError(format!("CreateWindowEx function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
let hdc = user32::GetDC(handle);
if hdc.is_null() {
return Err(OsError(format!("GetDC function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
WindowWrapper(handle, hdc)
@@ -377,7 +374,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
Some(extra_functions.CreateContextAttribsARB(hdc.1 as *const libc::c_void,
share as *const libc::c_void,
- attributes.as_slice().as_ptr()))
+ attributes.as_ptr()))
} else {
None
@@ -399,7 +396,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
if ctxt.is_null() {
return Err(OsError(format!("OpenGL context creation failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(ContextWrapper(ctxt as winapi::HGLRC))
@@ -506,12 +503,12 @@ unsafe fn set_pixel_format(hdc: &WindowWrapper, id: libc::c_int) -> Result<(), C
as winapi::UINT, &mut output) == 0
{
return Err(OsError(format!("DescribePixelFormat function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
if gdi32::SetPixelFormat(hdc.1, id, &output) == 0 {
return Err(OsError(format!("SetPixelFormat function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(())
@@ -525,7 +522,7 @@ unsafe fn load_opengl32_dll() -> Result<winapi::HMODULE, CreationError> {
if lib.is_null() {
return Err(OsError(format!("LoadLibrary function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(lib)
diff --git a/src/win32/make_current_guard.rs b/src/win32/make_current_guard.rs
index d6bcc8e..2435454 100644
--- a/src/win32/make_current_guard.rs
+++ b/src/win32/make_current_guard.rs
@@ -1,5 +1,5 @@
use std::marker::PhantomData;
-use std::os;
+use std::io;
use libc;
use winapi;
@@ -30,7 +30,7 @@ impl<'a, 'b> CurrentContextGuard<'a, 'b> {
if result == 0 {
return Err(CreationError::OsError(format!("wglMakeCurrent function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(CurrentContextGuard {
diff --git a/src/x11/headless.rs b/src/x11/headless.rs
index e23dfa7..291f04d 100644
--- a/src/x11/headless.rs
+++ b/src/x11/headless.rs
@@ -5,12 +5,6 @@ use libc;
use std::{mem, ptr};
use super::ffi;
-fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) -> T {
- use std::ffi::CString;
- let c_str = CString::from_slice(s.as_bytes());
- f(c_str.as_ptr())
-}
-
pub struct HeadlessContext {
context: ffi::OSMesaContext,
buffer: Vec<u32>,
@@ -53,9 +47,9 @@ impl HeadlessContext {
pub fn get_proc_address(&self, addr: &str) -> *const () {
unsafe {
- with_c_str(addr, |s| {
- ffi::OSMesaGetProcAddress(mem::transmute(s)) as *const ()
- })
+ use std::ffi::CString;
+ let c_str = CString::new(addr.as_bytes().to_vec()).unwrap();
+ ffi::OSMesaGetProcAddress(mem::transmute(c_str.as_ptr())) as *const ()
}
}
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index 7c93ad3..0188386 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -39,7 +39,7 @@ fn ensure_thread_init() {
fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) -> T {
use std::ffi::CString;
- let c_str = CString::from_slice(s.as_bytes());
+ let c_str = CString::new(s.as_bytes().to_vec()).unwrap();
f(c_str.as_ptr())
}
@@ -778,7 +778,7 @@ impl Window {
MouseCursor::AllScroll | MouseCursor::ZoomIn |
MouseCursor::ZoomOut => "left_ptr",
};
- let c_string = CString::from_slice(cursor_name.as_bytes());
+ let c_string = CString::new(cursor_name.as_bytes().to_vec()).unwrap();
let xcursor = ffi::XcursorLibraryLoadCursor(self.x.display, c_string.as_ptr());
ffi::XDefineCursor (self.x.display, self.x.window, xcursor);
ffi::XFlush(self.x.display);