-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-ffi
Metadata
Metadata
Assignees
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-ffi
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
dcharkes commentedon Oct 28, 2019
Untagged unions should be fairly easy to add in a manner similar to structs:
For them to be useful, we might want to add nested structs (#37271) and inline fixed-size arrays (#35763) first though.
cc @mkustermann
Hexer10 commentedon Dec 25, 2019
Any update for this feature? Right now I'd like to implement the
SendInput
function from the winapi, which requires an INPUT array structured as suchand seems like right now this is not possible.
dcharkes commentedon Dec 26, 2019
No update yet.
For the example you provided, you would actually need a union nested in a struct, which requires the nested structs/unions feature in addition (#37271).
As workaround, you can use nesting of structs workaround mentioned in that issue, and use manual casting for the different union values. It's not pretty but it should get you going.
[cfe/ffi] Refactor `dart:ffi` transformations
[vm/ffi] Support `Union`s backend
dcharkes commentedon Apr 9, 2021
We've got two options for structuring the similar
Struct
andUnion
APIs:Compound extends NativeType
.extends NativeType
.Option 1:
Pros:
'Compound'
rather than'Struct' or 'Union'
.Cons:
Compound
thanStruct
andUnion
.Compound
is taken from c++ terminology, and includes more than structs and unions, including pointers.structure or union
in the spec.Note that we can't actually unify
StructPointer
andUnionPointer
extensions:Users might have used the
StructPointer
to disambiguate, so making a sharedCompoundPointer
would be a breaking change.Option 2:
Pros:
Struct
andUnion
.Cons:
Option 2 prototype: https://dart-review.googlesource.com/c/sdk/+/194420/5
(Option 1 prototype only on my local machine.)
Anyone with more arguments for and against? Other options? Any preferences? @lrhn @mkustermann @mraleph
dcharkes commentedon Apr 9, 2021
Brief summary of offline discussion @sstrickl @askeksa-google @mraleph:
'struct' or 'union'
as that's what the C spec does and what the C grammar does._Compound
superclass for conceptual sharing and implementation sharing. (Use 'compound' over 'composite', because composite has a different meaning in the C standard.)[analyzer/ffi] Support `Union`s
[vm/ffi] Introduce `_Compound` `NativeType`
[vm/ffi] Refactor IL construction to `compound`
[vm/ffi] Refactor CFE transform to `compound`
alexlapa commentedon May 11, 2021
@dcharkes ,
I'm getting a strange compilation error when using unions on current Flutter master channel, which is:
Error log
Is this a known limitation or should i open an issue in dart-lang/ffi?
dcharkes commentedon May 12, 2021
@alexlapa bugs in
dart:ffi
can be reported here. Bugs withpackage:ffi
can be reported in dart-lang/ffi. I've opened a new issue to investigate this. Thanks for reporting!