Fix bounds on markers and expand tests

This commit is contained in:
Simonas Kazlauskas
2016-10-01 01:17:00 +03:00
parent 2d01e0cf98
commit 72702a55bc
7 changed files with 92 additions and 26 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "libloading"
version = "0.3.0"
version = "0.3.1"
authors = ["Simonas Kazlauskas <git@kazlauskas.me>"]
build = "build.rs"
description = "A safer binding to platforms dynamic library loading utilities"
+7
View File
@@ -1,5 +1,12 @@
//! Project changelog
/// Release 0.3.1 (TBA)
///
/// * `Symbol<T>` and `os::*::Symbol<T>` now implement `Send` where `T: Send`;
/// * `Symbol<T>` and `os::*::Symbol<T>` now implement `Sync` where `T: Sync`;
/// * `os::unix::Library` now implements `Sync`;
pub mod r0_3_1 {}
/// Release 0.3.0 (2016-07-27)
///
/// * Greatly improved documentation, especially around platform-specific behaviours;
+9 -2
View File
@@ -57,7 +57,10 @@ mod util;
pub type Result<T> = ::std::io::Result<T>;
/// A loaded dynamic library.
pub struct Library(imp::Library);
// The 2nd argument prevents Library from being Sync, this is desirable, because Windows specific
// Library does not support Sync yet (pending investigation), so to have both Unix and Windows
// consistent, make cross-platform Library not-Send for now.
pub struct Library(imp::Library, ::std::marker::PhantomData<*const ()>);
impl Library {
/// Find and load a dynamic library.
@@ -173,7 +176,7 @@ impl fmt::Debug for Library {
impl From<imp::Library> for Library {
fn from(lib: imp::Library) -> Library {
Library(lib)
Library(lib, ::std::marker::PhantomData)
}
}
@@ -183,6 +186,7 @@ impl From<Library> for imp::Library {
}
}
unsafe impl Send for Library {}
/// Symbol from a library.
///
@@ -274,3 +278,6 @@ impl<'lib, T> fmt::Debug for Symbol<'lib, T> {
self.inner.fmt(f)
}
}
unsafe impl<'lib, T: Send> Send for Symbol<'lib, T> {}
unsafe impl<'lib, T: Sync> Sync for Symbol<'lib, T> {}
+4 -3
View File
@@ -52,7 +52,7 @@ pub struct Library {
handle: *mut raw::c_void
}
unsafe impl ::std::marker::Send for Library {}
unsafe impl Send for Library {}
// That being said... this section in the volume 2 of POSIX.1-2008 states:
//
@@ -68,7 +68,7 @@ unsafe impl ::std::marker::Send for Library {}
//
// * https://github.com/nagisa/rust_libloading/pull/17
// * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_01
unsafe impl ::std::marker::Sync for Library {}
unsafe impl Sync for Library {}
impl Library {
/// Find and load a shared library (module).
@@ -201,7 +201,8 @@ pub struct Symbol<T> {
pd: marker::PhantomData<T>
}
unsafe impl<T> ::std::marker::Sync for Symbol<T> {}
unsafe impl<T: Send> Send for Symbol<T> {}
unsafe impl<T: Sync> Sync for Symbol<T> {}
impl<T> Clone for Symbol<T> {
fn clone(&self) -> Symbol<T> {
+3 -2
View File
@@ -12,7 +12,7 @@ use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
/// A platform-specific equivalent of the cross-platform `Library`.
pub struct Library(winapi::HMODULE);
unsafe impl ::std::marker::Send for Library {}
unsafe impl Send for Library {}
// This probably could implement Sync. At least I found no reason not to so far.
impl Library {
@@ -132,7 +132,8 @@ pub struct Symbol<T> {
pd: marker::PhantomData<T>
}
unsafe impl<T> ::std::marker::Sync for Symbol<T> {}
unsafe impl<T: Send> Send for Symbol<T> {}
unsafe impl<T: Sync> Sync for Symbol<T> {}
impl<T> Clone for Symbol<T> {
fn clone(&self) -> Symbol<T> {
+68
View File
@@ -0,0 +1,68 @@
extern crate libloading;
#[cfg(test)]
fn assert_send<T: Send>() {}
#[cfg(test)]
fn assert_sync<T: Sync>() {}
#[test]
fn check_library_send() {
assert_send::<libloading::Library>();
}
#[cfg(unix)]
#[test]
fn check_unix_library_send() {
assert_send::<libloading::os::unix::Library>();
}
#[cfg(windows)]
#[test]
fn check_windows_library_send() {
assert_send::<libloading::os::windows::Library>();
}
#[cfg(unix)]
#[test]
fn check_unix_library_sync() {
assert_sync::<libloading::os::unix::Library>();
}
#[test]
fn check_symbol_send() {
assert_send::<libloading::Symbol<fn() -> ()>>();
// assert_not_send::<libloading::Symbol<*const ()>>();
}
#[cfg(unix)]
#[test]
fn check_unix_symbol_send() {
assert_send::<libloading::os::unix::Symbol<fn() -> ()>>();
// assert_not_send::<libloading::os::unix::Symbol<*const ()>>();
}
#[cfg(windows)]
#[test]
fn check_windows_symbol_send() {
assert_send::<libloading::os::windows::Symbol>();
}
#[test]
fn check_symbol_sync() {
assert_sync::<libloading::Symbol<fn() -> ()>>();
// assert_not_sync::<libloading::Symbol<*const ()>>();
}
#[cfg(unix)]
#[test]
fn check_unix_symbol_sync() {
assert_sync::<libloading::os::unix::Symbol<fn() -> ()>>();
// assert_not_sync::<libloading::os::unix::Symbol<*const ()>>();
}
#[cfg(windows)]
#[test]
fn check_windows_symbol_sync() {
assert_sync::<libloading::os::windows::Symbol<fn() -> ()>>();
// assert_not_sync::<libloading::os::windows::Symbol<*const ()>>();
}
-18
View File
@@ -1,18 +0,0 @@
extern crate libloading;
use libloading::Symbol;
#[cfg(unix)]
#[test]
fn check_library_sync() {
use libloading::Library;
fn send<S: Sync>(_: Option<S>) {}
send::<Library>(None);
}
#[test]
fn check_symbol_sync() {
fn send<S: Sync>(_: Option<S>) {}
send::<Symbol<fn ()>>(None);
}