Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make additional types Send + Sync #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libffi-rs/src/high/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::super::middle;
#[derive(Clone, Debug)]
pub struct Type<T> {
untyped: middle::Type,
_marker: PhantomData<*mut T>,
_marker: PhantomData<fn() -> T>,
}

impl<T> Type<T> {
Expand Down
3 changes: 3 additions & 0 deletions libffi-rs/src/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ pub struct Cif {
result: Type,
}

unsafe impl Send for Cif {}
unsafe impl Sync for Cif {}

// To clone a Cif we need to clone the types and then make sure the new
// ffi_cif refers to the clones of the types.
impl Clone for Cif {
Expand Down
6 changes: 6 additions & 0 deletions libffi-rs/src/middle/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ type Owned<T> = T;
/// ```
pub struct Type(Unique<low::ffi_type>);

unsafe impl Send for Type {}
unsafe impl Sync for Type {}

/// Represents a sequence of C types.
///
/// This can be used to construct a struct type or as the arguments
/// when creating a [`Cif`].
pub struct TypeArray(Unique<*mut low::ffi_type>);

unsafe impl Send for TypeArray {}
unsafe impl Sync for TypeArray {}

impl fmt::Debug for Type {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_fmt(format_args!("Type({:?})", *self.0))
Expand Down