From dbdb43f077f4fa016e9f3f65345c4a947eceaa77 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 8 Jan 2015 09:28:22 +0100 Subject: Update for Rustc --- examples/fullscreen.rs | 4 +--- examples/multiwindow.rs | 4 +--- examples/support/mod.rs | 11 ++++------- examples/window.rs | 4 +--- src/lib.rs | 2 -- src/win32/init.rs | 8 +++++--- src/win32/mod.rs | 12 ++++++------ tests/headless.rs | 4 ---- 8 files changed, 18 insertions(+), 31 deletions(-) diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index 6a2af2c..c77569f 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -1,7 +1,5 @@ -#![feature(phase)] - #[cfg(target_os = "android")] -#[phase(plugin, link)] +#[macro_use] extern crate android_glue; extern crate glutin; diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs index 1f390cd..fc01ef0 100644 --- a/examples/multiwindow.rs +++ b/examples/multiwindow.rs @@ -1,7 +1,5 @@ -#![feature(phase)] - #[cfg(target_os = "android")] -#[phase(plugin, link)] +#[macro_use] extern crate android_glue; extern crate glutin; diff --git a/examples/support/mod.rs b/examples/support/mod.rs index 42ce6a4..7144952 100644 --- a/examples/support/mod.rs +++ b/examples/support/mod.rs @@ -1,8 +1,5 @@ #![cfg(feature = "window")] -#[phase(plugin)] -extern crate gl_generator; - use glutin; #[cfg(not(target_os = "android"))] @@ -23,12 +20,12 @@ pub struct Context { pub fn load(window: &glutin::Window) -> Context { let gl = gl::Gl::load(window); - let version = { - use std::c_str::CString; - unsafe { CString::new(gl.GetString(gl::VERSION) as *const i8, false) } + let version = unsafe { + use std::ffi; + ffi::c_str_to_bytes(&(gl.GetString(gl::VERSION) as *const i8)).to_string() }; - println!("OpenGL version {}", version.as_str().unwrap()); + println!("OpenGL version {}", version); Context { gl: gl } } diff --git a/examples/window.rs b/examples/window.rs index 910d6e6..9cb59c8 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -1,7 +1,5 @@ -#![feature(phase)] - #[cfg(target_os = "android")] -#[phase(plugin, link)] +#[macro_use] extern crate android_glue; extern crate glutin; diff --git a/src/lib.rs b/src/lib.rs index 4e118e8..4f4f86e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,6 @@ #![feature(unsafe_destructor)] -#![feature(globs)] #![feature(phase)] #![unstable] -#![feature(associated_types)] //! The purpose of this library is to provide an OpenGL context on as many //! platforms as possible. diff --git a/src/win32/init.rs b/src/win32/init.rs index d3341fe..77965ea 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -6,6 +6,7 @@ use {CreationError, Event}; use CreationError::OsError; use std::cell::RefCell; +use std::ffi::CString; use std::rc::Rc; use std::sync::mpsc::{Sender, Receiver, channel}; @@ -224,11 +225,12 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // loading the extra WGL functions let extra_functions = gl::wgl_extra::Wgl::load_with(|addr| { use libc; - use std::c_str::ToCStr; + + let addr = CString::from_slice(addr.as_bytes()); + let addr = addr.as_slice_with_nul().as_ptr(); unsafe { - let addr = addr.to_c_str(); - gl::wgl::GetProcAddress(addr.as_ptr()) as *const libc::c_void + gl::wgl::GetProcAddress(addr) as *const libc::c_void } }); diff --git a/src/win32/mod.rs b/src/win32/mod.rs index 9c78a8a..168771d 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -1,5 +1,6 @@ use std::sync::atomic::AtomicBool; use std::ptr; +use std::ffi::CString; use std::collections::RingBuf; use std::sync::mpsc::Receiver; use libc; @@ -256,14 +257,13 @@ impl Window { /// See the docs in the crate root file. pub fn get_proc_address(&self, addr: &str) -> *const () { - use std::c_str::ToCStr; + let addr = CString::from_slice(addr.as_bytes()); + let addr = addr.as_slice_with_nul().as_ptr(); unsafe { - addr.with_c_str(|s| { - let p = gl::wgl::GetProcAddress(s) as *const (); - if !p.is_null() { return p; } - winapi::GetProcAddress(self.gl_library, s) as *const () - }) + let p = gl::wgl::GetProcAddress(addr) as *const (); + if !p.is_null() { return p; } + winapi::GetProcAddress(self.gl_library, addr) as *const () } } diff --git a/tests/headless.rs b/tests/headless.rs index b2b23da..542445e 100644 --- a/tests/headless.rs +++ b/tests/headless.rs @@ -1,7 +1,3 @@ -#![feature(phase)] - -#[phase(plugin)] -extern crate gl_generator; extern crate glutin; extern crate libc; -- cgit v1.2.3 From 8d9133d3318c81021b1179f2cafe368650b4e7c8 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Thu, 8 Jan 2015 03:20:11 -0800 Subject: Update to latest Rust nightly --- examples/support/mod.rs | 11 ++++++----- src/lib.rs | 3 --- src/x11/headless.rs | 10 +++++++--- src/x11/window/mod.rs | 50 ++++++++++++++++++++++++++----------------------- tests/headless.rs | 4 +--- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/examples/support/mod.rs b/examples/support/mod.rs index 42ce6a4..02079fd 100644 --- a/examples/support/mod.rs +++ b/examples/support/mod.rs @@ -1,6 +1,6 @@ #![cfg(feature = "window")] -#[phase(plugin)] +#[no_link] extern crate gl_generator; use glutin; @@ -23,12 +23,13 @@ pub struct Context { pub fn load(window: &glutin::Window) -> Context { let gl = gl::Gl::load(window); - let version = { - use std::c_str::CString; - unsafe { CString::new(gl.GetString(gl::VERSION) as *const i8, false) } + let version = unsafe { + use std::ffi::c_str_to_bytes; + let ref version = gl.GetString(gl::VERSION) as *const i8; + String::from_utf8_lossy(c_str_to_bytes(version)).into_owned() }; - println!("OpenGL version {}", version.as_str().unwrap()); + println!("OpenGL version {}", version); Context { gl: gl } } diff --git a/src/lib.rs b/src/lib.rs index 4e118e8..0934f86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,5 @@ #![feature(unsafe_destructor)] -#![feature(globs)] -#![feature(phase)] #![unstable] -#![feature(associated_types)] //! The purpose of this library is to provide an OpenGL context on as many //! platforms as possible. 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(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, @@ -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 () }) } diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 9d79ad4..cff2c61 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -17,13 +17,19 @@ mod monitor; static THREAD_INIT: Once = ONCE_INIT; fn ensure_thread_init() { - THREAD_INIT.doit(|| { + THREAD_INIT.call_once(|| { unsafe { ffi::XInitThreads(); } }); } +fn with_c_str(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()) +} + struct XWindow { display: *mut ffi::Display, window: ffi::Window, @@ -234,13 +240,13 @@ impl Window { // creating window, step 2 let wm_delete_window = unsafe { - use std::c_str::ToCStr; - - let delete_window = "WM_DELETE_WINDOW".to_c_str(); - let mut wm_delete_window = ffi::XInternAtom(display, delete_window.as_ptr(), 0); + let mut wm_delete_window = with_c_str("WM_DELETE_WINDOW", |delete_window| + ffi::XInternAtom(display, delete_window, 0) + ); ffi::XSetWMProtocols(display, window, &mut wm_delete_window, 1); - let c_title = builder.title.to_c_str(); - ffi::XStoreName(display, window, c_title.as_ptr()); + with_c_str(&*builder.title, |title| {; + ffi::XStoreName(display, window, title); + }); ffi::XFlush(display); wm_delete_window @@ -257,13 +263,15 @@ impl Window { // creating input context let ic = unsafe { - use std::c_str::ToCStr; - - let input_style = "inputStyle".to_c_str(); - let client_window = "clientWindow".to_c_str(); - let ic = ffi::XCreateIC(im, input_style.as_ptr(), - ffi::XIMPreeditNothing | ffi::XIMStatusNothing, client_window.as_ptr(), - window, ptr::null()); + let ic = with_c_str("inputStyle", |input_style| + with_c_str("clientWindow", |client_window| + ffi::XCreateIC( + im, input_style, + ffi::XIMPreeditNothing | ffi::XIMStatusNothing, client_window, + window, ptr::null() + ) + ) + ); if ic.is_null() { return Err(OsError(format!("XCreateIC failed"))); } @@ -302,8 +310,7 @@ impl Window { // loading the extra GLX functions let extra_functions = ffi::glx_extra::Glx::load_with(|addr| { - use std::c_str::ToCStr; - addr.with_c_str(|s| { + with_c_str(addr, |s| { use libc; ffi::glx::GetProcAddress(s as *const u8) as *const libc::c_void }) @@ -356,12 +363,10 @@ impl Window { } pub fn set_title(&self, title: &str) { - use std::c_str::ToCStr; - let c_title = title.to_c_str(); - unsafe { - ffi::XStoreName(self.x.display, self.x.window, c_title.as_ptr()); + with_c_str(title, |title| unsafe { + ffi::XStoreName(self.x.display, self.x.window, title); ffi::XFlush(self.x.display); - } + }) } pub fn show(&self) { @@ -582,11 +587,10 @@ impl Window { } pub fn get_proc_address(&self, addr: &str) -> *const () { - use std::c_str::ToCStr; use std::mem; unsafe { - addr.with_c_str(|s| { + with_c_str(addr, |s| { ffi::glx::GetProcAddress(mem::transmute(s)) as *const () }) } diff --git a/tests/headless.rs b/tests/headless.rs index b2b23da..23a337d 100644 --- a/tests/headless.rs +++ b/tests/headless.rs @@ -1,6 +1,4 @@ -#![feature(phase)] - -#[phase(plugin)] +#[no_link] extern crate gl_generator; extern crate glutin; extern crate libc; -- cgit v1.2.3