Skip to content

Commit

Permalink
Hack around a soundness issue
Browse files Browse the repository at this point in the history
Prevent `CBox` from being opaquable if it isn't `Send`. This effectively
works around #18, albeit does not solve it. This will prevent `!Send`
futures from being turned into CGlue's opaque, `CBox: Send`.
  • Loading branch information
h33p committed Jul 30, 2024
1 parent 6eb2baa commit 7a76fcc
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cglue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cglue"
version = "0.3.3"
version = "0.3.4"
authors = ["Aurimas Blažulionis <[email protected]>"]
edition = "2018"
description = "FFI safe abstractions for making plugins and C-compatible libraries"
Expand Down
3 changes: 2 additions & 1 deletion cglue/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ impl<T> Drop for CBox<'_, T> {
}
}

unsafe impl<'a, T> Opaquable for CBox<'a, T> {
// FIXME: express both Send and !Send box safely (https://github.com/h33p/cglue/issues/18)
unsafe impl<'a, T: Send> Opaquable for CBox<'a, T> {
type OpaqueTarget = CBox<'a, c_void>;
}

Expand Down
2 changes: 1 addition & 1 deletion cglue/src/tests/extra/wrap_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait ExtraFeature {
}

#[cglue_trait]
pub trait Basic: Sized {
pub trait Basic: Sized + Send + Sync {
#[vtbl_only('_, wrap_with_obj(ExtraFeature))]
fn b_1(&self) -> ExtraFeatureWrap<&Self> {
ExtraFeatureWrap { _v: self }
Expand Down
2 changes: 1 addition & 1 deletion cglue/src/tests/simple/trait_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_group() {
// and a ref group impl.
//
// Having both requres explicitly specifying inner type like done here.
fn into_test<'a, T: Into<TestGroupBaseBox<'a, T>> + 'a>(t: T) -> TestGroupBox<'a> {
fn into_test<'a, T: Into<TestGroupBaseBox<'a, T>> + Send + 'a>(t: T) -> TestGroupBox<'a> {
group_obj!(t as TestGroup)
}
let _ = into_test(&a);

Check warning on line 28 in cglue/src/tests/simple/trait_groups.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> cglue/src/tests/simple/trait_groups.rs:28:23 | 28 | let _ = into_test(&a); | ^^ help: change this to: `a` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
Expand Down

0 comments on commit 7a76fcc

Please sign in to comment.