From 8d3e85882f4924fb1052bc0adc69d4148491df4c Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Fri, 3 Apr 2015 16:46:48 +0200 Subject: [PATCH 1/5] impl Clone where Copy --- sdl2-sys/src/audio.rs | 2 +- sdl2-sys/src/touch.rs | 2 +- src/sdl2/audio.rs | 2 +- src/sdl2/controller.rs | 2 +- src/sdl2/joystick.rs | 4 ++-- src/sdl2/keycode.rs | 2 +- src/sdl2/scancode.rs | 2 +- src/sdl2/video.rs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdl2-sys/src/audio.rs b/sdl2-sys/src/audio.rs index 8a4d966b..8ac9f69b 100644 --- a/sdl2-sys/src/audio.rs +++ b/sdl2-sys/src/audio.rs @@ -42,7 +42,7 @@ pub struct SDL_AudioSpec { pub type SDL_AudioFilter = Option; #[allow(dead_code, missing_copy_implementations, raw_pointer_derive)] -#[derive(Copy)] +#[derive(Copy, Clone)] #[repr(C)] pub struct SDL_AudioCVT { pub needed: c_int, diff --git a/sdl2-sys/src/touch.rs b/sdl2-sys/src/touch.rs index 070dd84c..8db0eded 100644 --- a/sdl2-sys/src/touch.rs +++ b/sdl2-sys/src/touch.rs @@ -5,7 +5,7 @@ pub type SDL_FingerID = int64_t; pub type SDL_Finger = Finger; pub type TouchDevice = SDL_TouchID; -#[derive(PartialEq, Copy)] +#[derive(PartialEq, Copy, Clone)] #[repr(C)] pub struct Finger { id: TouchDevice, diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 52c5be88..d5792599 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -407,7 +407,7 @@ impl<'a, CB> Drop for AudioDeviceLockGuard<'a, CB> { } } -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct AudioCVT { raw: ll::SDL_AudioCVT } diff --git a/src/sdl2/controller.rs b/src/sdl2/controller.rs index 94d719d6..e1b09f73 100644 --- a/src/sdl2/controller.rs +++ b/src/sdl2/controller.rs @@ -156,7 +156,7 @@ pub fn get_event_state() -> bool { } /// Possible return values for `add_mapping` -#[derive(Copy)] +#[derive(Copy, Clone)] pub enum MappingStatus { Added = 1, Updated = 0, diff --git a/src/sdl2/joystick.rs b/src/sdl2/joystick.rs index a3484b5d..b0e15f3f 100644 --- a/src/sdl2/joystick.rs +++ b/src/sdl2/joystick.rs @@ -255,7 +255,7 @@ impl Drop for Joystick { /// Wrapper around a SDL_JoystickGUID, a globally unique identifier /// for a joystick. -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct Guid { raw: ll::SDL_JoystickGUID, } @@ -321,7 +321,7 @@ impl Display for Guid { /// combinations make sense: 5 for instance would mean up and down at /// the same time... To simplify things I turn it into an enum which /// is how the SDL2 docs present it anyway (using macros). -#[derive(Copy, Debug)] +#[derive(Copy, Clone, Debug)] pub enum HatState { Centered = 0, Up = 0x01, diff --git a/src/sdl2/keycode.rs b/src/sdl2/keycode.rs index 07b9b0df..7269da2e 100644 --- a/src/sdl2/keycode.rs +++ b/src/sdl2/keycode.rs @@ -3,7 +3,7 @@ use std::num::ToPrimitive; use sys::keycode as ll; -#[derive(PartialEq, Eq, FromPrimitive, Debug, Copy)] +#[derive(PartialEq, Eq, FromPrimitive, Debug, Copy, Clone)] pub enum KeyCode { Unknown = ll::SDLK_UNKNOWN as isize, Backspace = ll::SDLK_BACKSPACE as isize, diff --git a/src/sdl2/scancode.rs b/src/sdl2/scancode.rs index 5906b367..005ca3aa 100644 --- a/src/sdl2/scancode.rs +++ b/src/sdl2/scancode.rs @@ -3,7 +3,7 @@ use std::num::ToPrimitive; use sys::scancode as ll; -#[derive(PartialEq, Eq, FromPrimitive, Debug, Copy)] +#[derive(PartialEq, Eq, FromPrimitive, Debug, Copy, Clone)] pub enum ScanCode { Unknown = ll::SDL_SCANCODE_UNKNOWN as isize, A = ll::SDL_SCANCODE_A as isize, diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 6877952a..cba99ad3 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -125,7 +125,7 @@ pub enum FullscreenType { FTDesktop = 0x00001001, } -#[derive(PartialEq, Copy)] +#[derive(PartialEq, Copy, Clone)] pub enum WindowPos { PosUndefined, PosCentered, From b88772673eb58cbee0ddc1198691472a08b8213d Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Fri, 3 Apr 2015 16:46:57 +0200 Subject: [PATCH 2/5] Fix a constant --- sdl2-sys/src/event.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdl2-sys/src/event.rs b/sdl2-sys/src/event.rs index 4dc931ae..1e5ab56f 100644 --- a/sdl2-sys/src/event.rs +++ b/sdl2-sys/src/event.rs @@ -14,7 +14,7 @@ pub type SDL_bool = c_int; pub type SDL_EventState = uint8_t; pub const SDL_DISABLE: SDL_EventState = 0; pub const SDL_ENABLE: SDL_EventState = 1; -pub const SDL_QUERY: SDL_EventState = -1; +pub const SDL_QUERY: SDL_EventState = 0xFF; pub type SDL_SysWMmsg = c_void; From b8c67e124cb2c7b81d564fd00fb4cac658ba78cd Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Fri, 3 Apr 2015 16:49:23 +0200 Subject: [PATCH 3/5] Remove all unsafe_destructor --- src/sdl2/audio.rs | 1 - src/sdl2/lib.rs | 2 +- src/sdl2/render.rs | 1 - src/sdl2/sdl.rs | 1 - src/sdl2/timer.rs | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index d5792599..fea6240b 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -400,7 +400,6 @@ impl<'a, CB: 'a> DerefMut for AudioDeviceLockGuard<'a, CB> { fn deref_mut(&mut self) -> &mut CB { &mut self.device.userdata.callback } } -#[unsafe_destructor] impl<'a, CB> Drop for AudioDeviceLockGuard<'a, CB> { fn drop(&mut self) { unsafe { ll::SDL_UnlockAudioDevice(self.device.device_id.id()) } diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 56b91b27..1eba318a 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -1,7 +1,7 @@ #![crate_name = "sdl2"] #![crate_type = "lib"] -#![feature(unsafe_destructor, optin_builtin_traits, std_misc, core)] +#![feature(optin_builtin_traits, std_misc, core)] extern crate libc; #[macro_use] diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 7e2ed865..9b06e1e0 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -862,7 +862,6 @@ pub struct Texture<'renderer> { _marker: PhantomData<&'renderer ()> } -#[unsafe_destructor] impl<'renderer> Drop for Texture<'renderer> { fn drop(&mut self) { if self.owned { diff --git a/src/sdl2/sdl.rs b/src/sdl2/sdl.rs index 90fd8a6f..bf110d22 100644 --- a/src/sdl2/sdl.rs +++ b/src/sdl2/sdl.rs @@ -105,7 +105,6 @@ pub struct Subsystem<'sdl> { _marker: PhantomData<&'sdl Sdl> } -#[unsafe_destructor] impl<'sdl> Drop for Subsystem<'sdl> { fn drop(&mut self) { unsafe { ll::SDL_QuitSubSystem(self.flags.bits()); } diff --git a/src/sdl2/timer.rs b/src/sdl2/timer.rs index 12f46485..e86b2264 100644 --- a/src/sdl2/timer.rs +++ b/src/sdl2/timer.rs @@ -54,7 +54,6 @@ impl<'a> Timer<'a> { } } -#[unsafe_destructor] impl<'a> Drop for Timer<'a> { fn drop(&mut self) { let ret = unsafe { ll::SDL_RemoveTimer(self.raw) }; From e71c09946456c57dff49f5e2cb96828d73166420 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Fri, 3 Apr 2015 16:57:32 +0200 Subject: [PATCH 4/5] Remove std_misc dependency This means that the error message when borrowing the render will be less useful unfortunately. Once BorrowState has been stabilized we can add it again. --- src/sdl2/lib.rs | 2 +- src/sdl2/render.rs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 1eba318a..4a14597e 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -1,7 +1,7 @@ #![crate_name = "sdl2"] #![crate_type = "lib"] -#![feature(optin_builtin_traits, std_misc, core)] +#![feature(optin_builtin_traits, core)] extern crate libc; #[macro_use] diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 9b06e1e0..387597f2 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -51,7 +51,7 @@ use std::ptr; use libc::{c_int, uint32_t, c_double, c_void}; use rect::Point; use rect::Rect; -use std::cell::{RefCell, RefMut, BorrowState}; +use std::cell::{RefCell, RefMut}; use std::ffi::CStr; use std::num::FromPrimitive; use std::vec::Vec; @@ -266,10 +266,7 @@ impl Renderer { /// } /// ``` pub fn drawer(&self) -> RenderDrawer { - match self.drawer_borrow.borrow_state() { - BorrowState::Unused => RenderDrawer::new(self.raw, self.drawer_borrow.borrow_mut()), - _ => panic!("Renderer drawer already borrowed") - } + RenderDrawer::new(self.raw, self.drawer_borrow.borrow_mut()) } /// Unwraps the window or surface the rendering context was created from. From cec9da907a65815f1852126e4585acbd044f06a8 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Fri, 3 Apr 2015 17:17:17 +0200 Subject: [PATCH 5/5] Reintroduce std_misc when testing --- src/sdl2/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 4a14597e..53ddbbbd 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -2,6 +2,7 @@ #![crate_type = "lib"] #![feature(optin_builtin_traits, core)] +#![cfg_attr(test, feature(std_misc))] extern crate libc; #[macro_use]