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

Support collection data structures #8

Open
Rantanen opened this issue Dec 5, 2017 · 2 comments
Open

Support collection data structures #8

Rantanen opened this issue Dec 5, 2017 · 2 comments

Comments

@Rantanen
Copy link
Owner

Rantanen commented Dec 5, 2017

We need some kind of collection support. One option would be implementing COM SAFEARRAY <-> Rust [T] slice.

At least the following things should be possible:

Rust

// Collection parameters and return value.
fn method( &self, values : [u8] ) -> Vec<bool> { ... }

COM clients

var arr = list.ToArray();
foreach( var item in foo.Method( arr ) ) { ... }

Even if we need to go with the SAFEARRAY approach, we don't need to support the full SAFEARRAY to begin with. We could even make the assumption that the SAFEARRAYs can only be used in methods that return ComResult (or similar) and thus the SAFEARRAY conversion methods can yield E_INVALIDARG in bad cases to report invalid use of SAFEARRAYs.

@Rantanen
Copy link
Owner Author

Rantanen commented Nov 9, 2018

While SAFEARRAY is a horrible construct, I'm feeling more and more convinced that we need to support it for things like C#. On the other hand we do NOT want to support it for things like native C++ unless we really need to.

As such, my current proposal would be:

TypeSystem::Automation will use SAFEARRAYs everywhere, TypeSystem::Raw will use size_t/Data* pairs for collections.

In either case only one-dimensional arrays will be supported (even if SAFEARRAY could support multi-dimensional arrays).

@Rantanen
Copy link
Owner Author

Update in the context of ExternType:

We'll provide a macro, such as define_com_collection!(u8 -> U8Collection), that ends up creating the #[repr(C)] types for the array and impls ExternType for [u8], Vec<u8>, etc. with the native types mapped to the newly declared structs.

This should enable the Rust programmer to use the usual Rust collection types while still having enough information in the binary to allow the IDL/etc. to define the types for the collections.

To make things easy for the parameter mapping, I'm hoping that the U8Collection that the macro implements would be something similar to:

#[repr(C)]
struct U8Collection_Raw_Output {
    size: usize,
    data: *mut <U8 as ExternType>::ExternOutputType,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant