From faafab27bb70214a9cdbed14a7bf40740c0d7709 Mon Sep 17 00:00:00 2001 From: Tony Aldridge Date: Wed, 25 Nov 2015 15:16:41 +0000 Subject: [PATCH 1/2] Make various functions prefer c_char over native Rust u8/i8, for cross-platform compilation --- Cargo.toml | 4 ++-- README.md | 2 +- src/sdl2/audio.rs | 10 +++++----- src/sdl2/clipboard.rs | 5 +++-- src/sdl2/controller.rs | 10 +++++----- src/sdl2/event.rs | 6 +++--- src/sdl2/filesystem.rs | 7 ++++--- src/sdl2/hint.rs | 9 +++++---- src/sdl2/joystick.rs | 6 +++--- src/sdl2/keyboard/keycode.rs | 5 +++-- src/sdl2/keyboard/scancode.rs | 5 +++-- src/sdl2/messagebox.rs | 5 +++-- src/sdl2/render.rs | 2 +- src/sdl2/rwops.rs | 4 ++-- src/sdl2/sdl.rs | 5 +++-- src/sdl2/version.rs | 2 +- src/sdl2/video.rs | 20 ++++++++++---------- 17 files changed, 57 insertions(+), 50 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8fb11485..7eef800a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ name = "sdl2" description = "SDL2 bindings for Rust" repository = "https://github.com/AngryLawyer/rust-sdl2" documentation = "http://angrylawyer.github.io/rust-sdl2/sdl2/" -version = "0.11.0" +version = "0.12.0" license = "MIT" authors = [ "Tony Aldridge " ] keywords = ["SDL", "windowing", "graphics"] @@ -16,7 +16,7 @@ path = "src/sdl2/lib.rs" [dependencies] num = "0.1" -bitflags = "0.3.2" +bitflags = "0.3" libc = "0.2" rand = "0.3" diff --git a/README.md b/README.md index be2b0659..fcdce99b 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ download through Crates.io: ```toml [dependencies] - sdl2 = "0.11" + sdl2 = "0.12" ``` Alternatively, pull it from GitHub diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index b9e7a9fa..99e78ed3 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -51,7 +51,7 @@ //! ``` use std::ffi::{CStr, CString}; use num::FromPrimitive; -use libc::{c_int, c_void, uint8_t}; +use libc::{c_int, c_void, uint8_t, c_char}; use std::ops::{Deref, DerefMut}; use std::path::Path; use std::marker::PhantomData; @@ -80,7 +80,7 @@ impl AudioSubsystem { let buf = ll::SDL_GetCurrentAudioDriver(); assert!(!buf.is_null()); - str::from_utf8(CStr::from_ptr(buf).to_bytes()).unwrap() + str::from_utf8(CStr::from_ptr(buf as *const i8).to_bytes()).unwrap() } } @@ -100,7 +100,7 @@ impl AudioSubsystem { if dev_name.is_null() { Err(get_error()) } else { - Ok(String::from_utf8_lossy(CStr::from_ptr(dev_name).to_bytes()).to_string()) + Ok(String::from_utf8_lossy(CStr::from_ptr(dev_name as *const i8).to_bytes()).to_string()) } } } @@ -221,7 +221,7 @@ impl Iterator for DriverIterator { assert!(!buf.is_null()); self.index += 1; - Some(str::from_utf8(CStr::from_ptr(buf).to_bytes()).unwrap()) + Some(str::from_utf8(CStr::from_ptr(buf as *const i8).to_bytes()).unwrap()) } } } @@ -480,7 +480,7 @@ impl AudioDevice { let device_ptr = device.map_or(null(), |s| s.as_ptr()); let iscapture_flag = 0; - let device_id = ll::SDL_OpenAudioDevice(device_ptr, iscapture_flag, &desired, &mut obtained, 0); + let device_id = ll::SDL_OpenAudioDevice(device_ptr as *const c_char, iscapture_flag, &desired, &mut obtained, 0); match device_id { 0 => { Err(get_error()) diff --git a/src/sdl2/clipboard.rs b/src/sdl2/clipboard.rs index 91152e97..3c330f29 100644 --- a/src/sdl2/clipboard.rs +++ b/src/sdl2/clipboard.rs @@ -1,4 +1,5 @@ use std::ffi::{CString, CStr}; +use libc::c_char; use SdlResult; use get_error; @@ -31,7 +32,7 @@ impl ClipboardUtil { pub fn set_clipboard_text(&self, text: &str) -> SdlResult<()> { unsafe { let text = CString::new(text).unwrap(); - let result = ll::SDL_SetClipboardText(text.as_ptr()); + let result = ll::SDL_SetClipboardText(text.as_ptr() as *const c_char); if result == 0 { Err(get_error()) @@ -48,7 +49,7 @@ impl ClipboardUtil { if buf.is_null() { Err(get_error()) } else { - Ok(String::from_utf8_lossy(CStr::from_ptr(buf).to_bytes()).into_owned()) + Ok(String::from_utf8_lossy(CStr::from_ptr(buf as *const i8).to_bytes()).into_owned()) } } } diff --git a/src/sdl2/controller.rs b/src/sdl2/controller.rs index d5676442..58de8828 100644 --- a/src/sdl2/controller.rs +++ b/src/sdl2/controller.rs @@ -74,7 +74,7 @@ impl GameControllerSubsystem { pub fn add_mapping(&self, mapping: &str) -> SdlResult { let mapping = try!(CString::new(mapping).unwrap_or_sdlresult()); - let result = unsafe { ll::SDL_GameControllerAddMapping(mapping.as_ptr()) }; + let result = unsafe { ll::SDL_GameControllerAddMapping(mapping.as_ptr() as *const c_char) }; match result { 1 => Ok(MappingStatus::Added), @@ -112,7 +112,7 @@ impl Axis { /// used by the game controller mapping strings. pub fn from_string(axis: &str) -> Option { let id = match CString::new(axis) { - Ok(axis) => unsafe { ll::SDL_GameControllerGetAxisFromString(axis.as_ptr()) }, + Ok(axis) => unsafe { ll::SDL_GameControllerGetAxisFromString(axis.as_ptr() as *const c_char) }, // string contains a nul byte - it won't match anything. Err(_) => ll::SDL_CONTROLLER_AXIS_INVALID }; @@ -169,7 +169,7 @@ impl Button { /// used by the game controller mapping strings. pub fn from_string(button: &str) -> Option