Skip to content

Commit

Permalink
Merge pull request #1404: make SdlDrop zero sized
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobrand committed Jun 13, 2024
2 parents b98948c + 6a8f13b commit b3ac580
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ In this file will be listed the changes, especially the breaking ones that one s
when upgrading from a version of rust-sdl2 to another.

### Unreleased
[PR #1404](https://github.com/Rust-SDL2/rust-sdl2/pull/1404) Make `SdlDrop` a zero sized type.

[PR #1389](https://github.com/Rust-SDL2/rust-sdl2/pull/1389) Fix some undefined behavior.

Expand Down
10 changes: 5 additions & 5 deletions src/sdl2/sdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::cell::Cell;
use std::error;
use std::ffi::{CStr, CString, NulError};
use std::fmt;
use std::marker::PhantomData;
use std::mem::transmute;
use std::os::raw::c_void;
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};

use crate::sys;
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Sdl {

Ok(Sdl {
sdldrop: SdlDrop {
_anticonstructor: std::ptr::null_mut(),
marker: PhantomData,
},
})
}
Expand Down Expand Up @@ -186,15 +186,15 @@ impl Sdl {
pub struct SdlDrop {
// Make it impossible to construct `SdlDrop` without access to this member,
// and opt out of Send and Sync.
_anticonstructor: *mut c_void,
marker: PhantomData<*mut ()>,
}

impl Clone for SdlDrop {
fn clone(&self) -> SdlDrop {
let prev_count = SDL_COUNT.fetch_add(1, Ordering::Relaxed);
assert!(prev_count > 0);
SdlDrop {
_anticonstructor: std::ptr::null_mut(),
marker: PhantomData,
}
}
}
Expand All @@ -209,7 +209,7 @@ impl Drop for SdlDrop {
unsafe {
sys::SDL_Quit();
}
IS_MAIN_THREAD_DECLARED.swap(false, Ordering::SeqCst);
IS_MAIN_THREAD_DECLARED.store(false, Ordering::SeqCst);
}
}
}
Expand Down

0 comments on commit b3ac580

Please sign in to comment.