Latest Rust fixes

This commit is contained in:
Siim Kallas
2014-07-26 00:28:32 +03:00
parent e04544d3f1
commit fda6f0a74a
8 changed files with 29 additions and 25 deletions
+3 -3
View File
@@ -21,18 +21,18 @@ fn main() {
os::set_exit_status(1);
},
3 => {
let output_dir = GenericPath::new(args.get(2).as_slice());
let output_dir = GenericPath::new(args[2].as_slice());
match mkdir_recursive(&output_dir, UserDir) {
Err(e) => fail!("Could not create directory for generated sources: {:s}", e.desc),
Ok(_) => {},
};
if "keycode.rs" == args.get(1).as_slice() {
if "keycode.rs" == args[1].as_slice() {
match keycode::generate(&output_dir) {
Ok(_) => {},
Err(e) => fail!("Could not automatically generate sources for keycodes: {:s}", e.desc),
};
} else if "scancode.rs" == args.get(1).as_slice() {
} else if "scancode.rs" == args[1].as_slice() {
match scancode::generate(&output_dir) {
Ok(_) => {},
Err(e) => fail!("Could not automatically generate sources for scancodes: {:s}", e.desc),
+6 -4
View File
@@ -221,11 +221,12 @@ extern "C" fn c_audio_callback(userdata: *const c_void, stream: *const uint8_t,
impl<'a> AudioSpec<'a> {
pub fn load_wav(path: &Path) -> SdlResult<(AudioSpec, CVec<u8>)> {
AudioSpec::load_wav_rw(&try!(RWops::from_file(path, "rb")))
pub fn load_wav<'b>(path: &Path) -> SdlResult<(AudioSpec<'b>, CVec<u8>)> {
let ops = try!(RWops::from_file(path, "rb"));
AudioSpec::load_wav_rw(&ops)
}
pub fn load_wav_rw(src: &RWops) -> SdlResult<(AudioSpec, CVec<u8>)> {
pub fn load_wav_rw<'b>(src: &RWops) -> SdlResult<(AudioSpec<'b>, CVec<u8>)> {
assert_eq!(mem::size_of::<AudioSpec>(), mem::size_of::<ll::SDL_AudioSpec>());
let mut spec = unsafe { mem::uninitialized::<AudioSpec>() };
let audio_buf = ptr::null::<u8>();
@@ -261,7 +262,8 @@ impl AudioDevice {
}
}
pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> SdlResult<(AudioDevice, AudioSpec)> {
pub fn open<'a>(device: Option<&str>, iscapture: int, spec: &AudioSpec)
-> SdlResult<(AudioDevice, AudioSpec<'a>)> {
//! SDL_OpenAudioDevice
let obtained = unsafe { mem::uninitialized::<AudioSpec>() };
unsafe {
+3 -3
View File
@@ -1,4 +1,4 @@
use std::str;
use std::string;
use SdlResult;
use get_error;
@@ -31,8 +31,8 @@ pub fn set_clipboard_text(text: &String) -> SdlResult<()> {
pub fn get_clipboard_text() -> SdlResult<String> {
let result = unsafe {
let cstr = ll::SDL_GetClipboardText();
str::raw::from_c_str(cstr)
let cstr = ll::SDL_GetClipboardText() as *const u8;
string::raw::from_buf(cstr)
};
if result.len() == 0 {
+2 -2
View File
@@ -5,7 +5,7 @@ Event Handling
use std::mem;
use libc::{c_int, c_void, uint32_t};
use std::num::FromPrimitive;
use std::str;
use std::string;
use std::ptr;
use controller;
@@ -991,7 +991,7 @@ impl Event {
DropFileEventType => {
let event = *raw.drop();
let text = str::raw::from_c_str(event.file);
let text = string::raw::from_buf(event.file as *const u8);
ll::SDL_free(event.file as *const c_void);
DropFileEvent(event.timestamp as uint, text)
+3 -3
View File
@@ -1,4 +1,4 @@
use std::str;
use std::string;
use SdlResult;
use get_error;
@@ -15,7 +15,7 @@ pub mod ll {
pub fn get_base_path() -> SdlResult<String> {
let result = unsafe {
let cstr = ll::SDL_GetBasePath();
str::raw::from_c_str(cstr)
string::raw::from_buf(cstr as *const u8)
};
if result.len() == 0 {
@@ -32,7 +32,7 @@ pub fn get_pref_path(org: &str, app: &str) -> SdlResult<String> {
app.with_c_str(|app_cstr| {
ll::SDL_GetPrefPath(org_cstr, app_cstr)
})});
str::raw::from_c_str(cstr)
string::raw::from_buf(cstr as *const u8)
};
if result.len() == 0 {
+5 -3
View File
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::num::FromPrimitive;
use std::ptr;
use std::str;
use std::string;
use std::vec;
use keycode::KeyCode;
@@ -116,7 +116,8 @@ pub fn get_scancode_from_key(key: KeyCode) -> ScanCode {
pub fn get_scancode_name(scancode: ScanCode) -> String {
unsafe {
str::raw::from_c_str(ll::SDL_GetScancodeName(scancode.code() as u32))
let scancode_name = ll::SDL_GetScancodeName(scancode.code() as u32);
string::raw::from_buf(scancode_name as *const u8)
}
}
@@ -130,7 +131,8 @@ pub fn get_scancode_from_name(name: &str) -> ScanCode {
pub fn get_key_name(key: KeyCode) -> String {
unsafe {
str::raw::from_c_str(ll::SDL_GetKeyName(key.code()))
let key_name = ll::SDL_GetKeyName(key.code());
string::raw::from_buf(key_name as *const u8)
}
}
+2 -2
View File
@@ -8,7 +8,7 @@ use SdlResult;
use std::ptr;
use libc;
use libc::{c_int, uint32_t, c_float, c_double, c_void, size_t};
use std::str;
use std::string;
use std::mem;
use rect::Point;
use rect::Rect;
@@ -191,7 +191,7 @@ impl RendererInfo {
}).collect();
RendererInfo {
name: str::raw::from_c_str(mem::transmute_copy(&info.name)),
name: string::raw::from_buf(mem::transmute_copy(&info.name)),
flags: actual_flags,
texture_formats: texture_formats,
max_texture_width: info.max_texture_width as int,
+5 -5
View File
@@ -1,6 +1,6 @@
use libc::{c_int, c_float, uint32_t};
use std::ptr;
use std::str;
use std::string;
use std::mem;
use std::vec::Vec;
@@ -436,7 +436,7 @@ impl Window {
pub fn get_title(&self) -> String {
unsafe {
let cstr = ll::SDL_GetWindowTitle(self.raw);
str::raw::from_c_str(mem::transmute_copy(&cstr))
string::raw::from_buf(mem::transmute_copy(&cstr))
}
}
@@ -617,7 +617,7 @@ pub fn get_num_video_drivers() -> SdlResult<int> {
pub fn get_video_driver(id: int) -> String {
unsafe {
let cstr = ll::SDL_GetVideoDriver(id as c_int);
str::raw::from_c_str(mem::transmute_copy(&cstr))
string::raw::from_buf(mem::transmute_copy(&cstr))
}
}
@@ -634,7 +634,7 @@ pub fn video_quit() {
pub fn get_current_video_driver() -> String {
unsafe {
let cstr = ll::SDL_GetCurrentVideoDriver();
str::raw::from_c_str(mem::transmute_copy(&cstr))
string::raw::from_buf(mem::transmute_copy(&cstr))
}
}
@@ -650,7 +650,7 @@ pub fn get_num_video_displays() -> SdlResult<int> {
pub fn get_display_name(display_index: int) -> String {
unsafe {
let cstr = ll::SDL_GetDisplayName(display_index as c_int);
str::raw::from_c_str(mem::transmute_copy(&cstr))
string::raw::from_buf(mem::transmute_copy(&cstr))
}
}