-
Notifications
You must be signed in to change notification settings - Fork 277
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
[refactor]: Use context in IntoFfi #2633
Conversation
ed03bbb
to
fab69d4
Compare
fc4d49c
to
4a4a802
Compare
799bab5
to
b9db95b
Compare
b9db95b
to
e93a7c5
Compare
ffi/src/owned.rs
Outdated
self.into_iter().map(IntoFfi::into_ffi).collect() | ||
store | ||
.0 | ||
.insert(unsafe { data_store.as_ptr().cast::<[T::ReprC; N]>().read() }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, it's open issue about this.
We don't need to mem::forgot(data_store)
since ReprC: Copy
.
ffi/src/lib.rs
Outdated
/// Convert from &[`Self`] into [`Self::Target`]. | ||
fn as_ref(&'itm self) -> Self::Target; | ||
/// Type that can be returned from an FFI function via out-pointer function argument | ||
pub trait Output: FfiType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trait is tricky, and might be too permissive, I should add tests as a guard
} | ||
|
||
// NOTE: Arrays must be converted into pointers | ||
impl<T: IntoFfi, const N: usize> IntoFfi for [T; N] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now it's possible to convert [T;0] into ffi which could be problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you still think this is an issue, I'd open an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second opening an issue.
ffi/src/owned.rs
Outdated
self.into_iter().map(IntoFfi::into_ffi).collect() | ||
store | ||
.0 | ||
.insert(unsafe { data_store.as_ptr().cast::<[T::ReprC; N]>().read() }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, it's open issue about this.
We don't need to mem::forgot(data_store)
since ReprC: Copy
.
02f0f31
to
755e130
Compare
3cfeb87
to
8c18da2
Compare
Signed-off-by: Marin Veršić <[email protected]>
8c18da2
to
4bcbb9d
Compare
@@ -96,7 +96,7 @@ impl AsRef<str> for Name { | |||
impl FromStr for Name { | |||
type Err = ParseError; | |||
|
|||
fn from_str(candidate: &str) -> Result<Self, Self::Err> { | |||
fn from_str(candidate: &str) -> Result<Self, <Self as FromStr>::Err> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
let arg_name = arg.name(); | ||
let arg_type = arg.ffi_type_resolved(true); | ||
|
||
let (arg_name, arg_type) = (arg.name(), arg.ffi_type_resolved(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really make it more readable (in fact, less).
} | ||
|
||
// NOTE: Arrays must be converted into pointers | ||
impl<T: IntoFfi, const N: usize> IntoFfi for [T; N] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second opening an issue.
// TODO: Be sure to match the bounds correctly | ||
//impl<'itm, T> IntoFfiVec for &'itm T | ||
//where | ||
// Self: FfiVec<ReprC = <Self as FfiType>::ReprC>, | ||
//{ | ||
// type Store = (Vec<<Self as FfiVec>::ReprC>, Vec<<Self as IntoFfi>::Store>); | ||
// | ||
// fn into_ffi(source: Vec<Self>, store: &mut Self::Store) -> Local<SliceRef<Self::ReprC>> { | ||
// store.0 = source | ||
// .into_iter() | ||
// .enumerate() | ||
// .map(|(i, item)| IntoFfi::into_ffi(item, &mut store.1[i])) | ||
// .collect(); | ||
// | ||
// Local(SliceRef::from_slice(&store.0)) | ||
// } | ||
//} | ||
// | ||
//impl<T: IntoFfiVec> IntoFfiVec for Vec<T> | ||
//where | ||
// Self: FfiVec<ReprC = SliceRef<T::ReprC>>, | ||
//{ | ||
// type Store = (Vec<<Self as FfiVec>::ReprC>, Vec<<T as IntoFfiVec>::Store>); | ||
// | ||
// fn into_ffi(source: Vec<Self>, store: &mut Self::Store) -> Local<SliceRef<Self::ReprC>> { | ||
// store.0 = source | ||
// .into_iter() | ||
// .enumerate() | ||
// .map(|(i, item)| IntoFfiVec::into_ffi(item, &mut store.1[i]).0) | ||
// .collect(); | ||
// | ||
// Local(SliceRef::from_slice(&store.0)) | ||
// } | ||
//} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add issue if commented code is to be merged. Add it to the epic.
// let mut i = 0; | ||
// while let Some((first, rest)) = substore.split_first_mut() { | ||
// let elem: &$ffi_ty<$($ty::ReprC,)*> = &slice[i]; | ||
// res.push(Clone::clone(TryFromReprC::try_from_repr_c(elem, first)?)); | ||
// substore = rest; | ||
// i += 1; | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend fixing this before merge. If you decide to merge as is, remove and create an issue.
//impl_tuple! {(A, B, C) -> FfiTuple3} | ||
//impl_tuple! {(A, B, C, D) -> FfiTuple4} | ||
//impl_tuple! {(A, B, C, D, E) -> FfiTuple5} | ||
//impl_tuple! {(A, B, C, D, E, F) -> FfiTuple6} | ||
//impl_tuple! {(A, B, C, D, E, F, G) -> FfiTuple7} | ||
//impl_tuple! {(A, B, C, D, E, F, G, H) -> FfiTuple8} | ||
//impl_tuple! {(A, B, C, D, E, F, G, H, I) -> FfiTuple9} | ||
//impl_tuple! {(A, B, C, D, E, F, G, H, I, J) -> FfiTuple10} | ||
//impl_tuple! {(A, B, C, D, E, F, G, H, I, J, K) -> FfiTuple11} | ||
//impl_tuple! {(A, B, C, D, E, F, G, H, I, J, K, L) -> FfiTuple12} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed? It would be nice if we can automate this process.
closed in favor of #2625 |
Description of the Change
Issue
Benefits
Possible Drawbacks
Usage Examples or Tests [optional]
Alternate Designs [optional]