Skip to content

Commit

Permalink
Merge pull request #100 from andelf/update-for-newest-rust
Browse files Browse the repository at this point in the history
fix compile error under newest rust
  • Loading branch information
AngryLawyer committed May 13, 2014
2 parents 24c9c3d + cfeb4d4 commit aacc6d7
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 95 deletions.
11 changes: 5 additions & 6 deletions src/sdl2/audio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cast;
use std::ptr;
use std::mem;
use std::c_str::CString;
Expand Down Expand Up @@ -209,11 +208,11 @@ pub struct AudioSpec<'a > {

extern "C" fn c_audio_callback(userdata: *c_void, stream: *uint8_t, len: c_int) {
unsafe {
let f : &mut |&mut [u8]| = cast::transmute(userdata);
let f : &mut |&mut [u8]| = mem::transmute(userdata);

// FIXME: lifetime error in calling
//slice::raw::mut_buf_as_slice(stream as *mut u8, len as uint, *f)
(*f)(cast::transmute(Slice {
(*f)(mem::transmute(Slice {
data: stream,
len: len as uint
}))
Expand All @@ -232,7 +231,7 @@ impl<'a> AudioSpec<'a> {
let audio_buf = ptr::null::<u8>();
let audio_len = 0u32;
unsafe {
let ret = ll::SDL_LoadWAV_RW(src.raw, 0, cast::transmute(&spec), &audio_buf, &audio_len);
let ret = ll::SDL_LoadWAV_RW(src.raw, 0, mem::transmute(&spec), &audio_buf, &audio_len);
if ret.is_null() {
Err(get_error())
} else {
Expand Down Expand Up @@ -272,8 +271,8 @@ impl AudioDevice {
};
let ret = ll::SDL_OpenAudioDevice(device_c_str,
iscapture as c_int,
cast::transmute(spec),
cast::transmute(&obtained),
mem::transmute(spec),
mem::transmute(&obtained),
0);
if ret == 0 {
Err(get_error())
Expand Down
8 changes: 4 additions & 4 deletions src/sdl2/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libc::c_int;

#[allow(non_camel_case_types)]
pub mod ll {
use std::cast;
use std::mem;
use libc::{c_int, c_char, c_uchar, c_uint, c_void, int16_t, uint8_t};
use joystick::ll::{SDL_Joystick, SDL_JoystickGUID};

Expand Down Expand Up @@ -32,13 +32,13 @@ pub mod ll {

impl SDL_GameControllerButtonBindData {
pub fn button(&self) -> *c_int {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}
pub fn axis(&self) -> *c_int {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}
pub fn hat(&self) -> *SDL_GameControllerButtonBindDataHat {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}
}

Expand Down
70 changes: 35 additions & 35 deletions src/sdl2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Event Handling
*/

use std::cast;
use std::mem;
use libc::{c_int, c_void, uint32_t};
use std::num::FromPrimitive;
use std::str;
Expand All @@ -25,7 +25,7 @@ use get_error;
#[doc(hidden)]
#[allow(non_camel_case_types)]
pub mod ll {
use std::cast;
use std::mem;
use libc::{c_float, c_int, c_char, c_uint, c_void, int16_t,
int32_t, uint8_t, uint16_t, uint32_t};
use gesture::ll::SDL_GestureID;
Expand Down Expand Up @@ -314,99 +314,99 @@ pub mod ll {

impl SDL_Event {
pub fn _type(&self) -> *uint32_t {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn common(&self) -> *SDL_CommonEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn window(&self) -> *SDL_WindowEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn key(&self) -> *SDL_KeyboardEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn edit(&self) -> *SDL_TextEditingEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn text(&self) -> *SDL_TextInputEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn motion(&self) -> *SDL_MouseMotionEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn button(&self) -> *SDL_MouseButtonEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn wheel(&self) -> *SDL_MouseWheelEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn jaxis(&self) -> *SDL_JoyAxisEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn jball(&self) -> *SDL_JoyBallEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn jhat(&self) -> *SDL_JoyHatEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn jbutton(&self) -> *SDL_JoyButtonEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn jdevice(&self) -> *SDL_JoyDeviceEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn caxis(&self) -> *SDL_ControllerAxisEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn cbutton(&self) -> *SDL_ControllerButtonEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn cdevice(&self) -> *SDL_ControllerDeviceEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn quit(&self) -> *SDL_QuitEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn user(&self) -> *SDL_UserEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn syswm(&self) -> *SDL_SysWMEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn tfinger(&self) -> *SDL_TouchFingerEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn mgesture(&self) -> *SDL_MultiGestureEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn dgesture(&self) -> *SDL_DollarGestureEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}

pub fn drop(&self) -> *SDL_DropEvent {
unsafe { cast::transmute_copy(&self) }
unsafe { mem::transmute_copy(&self) }
}
}

Expand Down Expand Up @@ -682,7 +682,7 @@ impl Event {
data2: ptr::null(),
};
unsafe {
ptr::copy_memory(cast::transmute::<_,*mut ll::SDL_UserEvent>(&ret), &event, 1);
ptr::copy_memory(mem::transmute::<_,*mut ll::SDL_UserEvent>(&ret), &event, 1);
}
Some(ret)
},
Expand Down Expand Up @@ -785,7 +785,7 @@ impl Event {
Ok(window) => window,
};

let text = str::from_utf8_owned(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<~[u8]>()).unwrap_or("".to_owned());
let text = str::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<Vec<u8>>().as_slice()).into_owned();
TextEditingEvent(event.timestamp as uint, window, text,
event.start as int, event.length as int)
}
Expand All @@ -798,7 +798,7 @@ impl Event {
Ok(window) => window,
};

let text = str::from_utf8_owned(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<~[u8]>()).unwrap_or("".to_owned());
let text = str::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<Vec<u8>>().as_slice()).into_owned();
TextInputEvent(event.timestamp as uint, window, text)
}

Expand Down Expand Up @@ -1081,33 +1081,33 @@ pub fn wait_event_timeout(timeout: int) -> Result<Event, ~str> {
}

extern "C" fn event_filter_wrapper(userdata: *c_void, event: *ll::SDL_Event) -> c_int {
let filter: extern fn(event: Event) -> bool = unsafe { cast::transmute(userdata) };
let filter: extern fn(event: Event) -> bool = unsafe { mem::transmute(userdata) };
if event.is_null() { 1 }
else { filter(Event::from_ll(unsafe { cast::transmute(event) })) as c_int }
else { filter(Event::from_ll(unsafe { mem::transmute(event) })) as c_int }
}

/// Set up a filter to process all events before they change internal state and are posted to the internal event queue.
pub fn set_event_filter(filter_func: extern fn(event: Event) -> bool) {
unsafe { ll::SDL_SetEventFilter(event_filter_wrapper,
cast::transmute(filter_func)) }
mem::transmute(filter_func)) }
}

/// Add a callback to be triggered when an event is added to the event queue.
pub fn add_event_watch(filter_func: extern fn(event: Event) -> bool) {
unsafe { ll::SDL_AddEventWatch(event_filter_wrapper,
cast::transmute(filter_func)) }
mem::transmute(filter_func)) }
}

/// Remove an event watch callback added.
pub fn delete_event_watch(filter_func: extern fn(event: Event) -> bool) {
unsafe { ll::SDL_DelEventWatch(event_filter_wrapper,
cast::transmute(filter_func)) }
mem::transmute(filter_func)) }
}

/// Run a specific filter function on the current event queue, removing any events for which the filter returns 0.
pub fn filter_events(filter_func: extern fn(event: Event) -> bool) {
unsafe { ll::SDL_FilterEvents(event_filter_wrapper,
cast::transmute(filter_func)) }
mem::transmute(filter_func)) }
}

/// Set the state of processing events.
Expand Down
8 changes: 4 additions & 4 deletions src/sdl2/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use collections::hashmap::HashMap;
use std::num::FromPrimitive;
use std::ptr;
use std::str;
use std::slice;
use std::vec;

use keycode::KeyCode;
use rect::Rect;
Expand Down Expand Up @@ -79,13 +79,13 @@ pub fn get_keyboard_state() -> HashMap<ScanCode, bool> {
let mut state: HashMap<ScanCode, bool> = HashMap::new();
let count = 0;

let raw = unsafe { slice::raw::from_buf_raw(ll::SDL_GetKeyboardState(&count),
count as uint) };
let raw = unsafe { vec::raw::from_buf(ll::SDL_GetKeyboardState(&count),
count as uint) };

let mut current = 0;
while current < raw.len() {
state.insert(FromPrimitive::from_int(current as int).unwrap(),
raw[current] == 1);
*raw.get(current) == 1);
current += 1;
}

Expand Down
6 changes: 3 additions & 3 deletions src/sdl2/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Rectangle Functions
*/

use std::cast;
use std::mem;
use libc::c_int;

/// A structure that defines a two dimensional point.
Expand Down Expand Up @@ -67,9 +67,9 @@ impl Rect {

let result = unsafe {
ll::SDL_EnclosePoints(
cast::transmute(points.as_ptr()),
mem::transmute(points.as_ptr()),
points.len() as c_int,
cast::transmute(clip.as_ref()),
mem::transmute(clip.as_ref()),
&out
) != 0
};
Expand Down
Loading

0 comments on commit aacc6d7

Please sign in to comment.