-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[vm/ffi] int, long, size_t, uintptr_t, wchar_t, etc #36140
Comments
|
sizeof(int) on iOS arm64 in Flutter test projects returns 4. Issue: #36140 Issue: #39637 Change-Id: I7b471fa1da653e9bee169c34d1bd36a96fa6a704 Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132607 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
From a user perspective, the lack of these standard variable-sized types is probably the single largest remaining deficiency in Dart's FFI support. It does rather complicate making FFI bindings for Dart. As someone routinely working on a number of FFI bindings for a multitude of different languages (most recently, OpenXR bindings), the specific list of missing, absolutely essential variable-sized types in Dart is:
And some other, somewhat rarer variable-sized types to consider supporting would be:
All the aforementioned types listed in priority order, in terms of how badly and frequently I have needed them. What's the plan for supporting at least |
These types are not part of the ABI, and the C standard has a very flexible specification (see this quick explanation). So, a compiler can choose what size/alignment these types have.
However, It might be the case that for some of these types, all the compilers targeting the various ABIs (OS/Hardware combinations) agree on a size/alignment. Then we could incorporate these types into the ABI-logic. The downside is that if ever some new compiler comes up that does not respect the status quo, stuff breaks. Does anyone have experience with whether the most common compilers agree on these types are handled in specific ABIs? Do we have any prior art in FFIs in other languages? Another direction we could go to is to pass in the specs for these types into a bindings generator. The downside here is that one needs to re-run the bindings generator for every compiler/compiler options/hardware/OS combination when releasing an app. @artob, what are you currently doing to work around this limitation? |
@dcharkes Respectfully, you might be overthinking this. Just about any FFI for any programming language has the same theoretical problem, yet they all provide these FFI types.
Every single FFI in every single programming language I've worked with--with the sole exception of Dart--supports these basic types: at the very least,
I omitted Go, LuaJIT, Nim, PHP, and Zig from the list, since their FFI implementations all parse C header syntax directly (and implicitly support these types).
I'm not. This, plus #35763, is blocking my efforts for nontrivial FFI bindings for Dart and Flutter. It would be a royal pain in the arse to work around both of these blockers, so I'm focusing my efforts elsewhere for now and hoping to come back to all this after a future Dart release announcement. |
Oh, and I might as well mention this here as an aside given that I haven't found an existing issue for it: the lack of general type aliases--for example, defining |
See dart-lang/language#65 for that. |
Assuming that the sizes are stable per ABI (so checking a single compiler gcc/clang/msvc per platform) and only for the subset of OS x hardware platforms that DartVM runs on: Types we already support:
Types that require
Sources:
TODO:
|
@dcharkes Would you be willing to give any estimate which future Dart release those new types ( |
No, we generally don't give estimates. We're working on it, but we don't want to rush a suboptimal solution (idea for a general solution to ABI-specific types: #42563). |
As the types names do not match between dart:ffi and C. It would be helpful to provide a mapping table somewhere in dart:ffi documentation (at least for C types which have a correct sized type available in dart:ffi). I had to search quite a lot to find how to safely map But still, I wouldn't say that Why not introducing aliases for these types as well just now ? |
I'll introduce them after #42563 to |
Wait, I've been working with |
This will be available in In the mean time this is also available in
On Windows they're both 16-bit integers yes. Not on other platforms. |
Please note that we've decided to put them into Because they did not make it into Dart 2.16, but |
This reverts commit 85a87ca. Reason for revert: * Adding `Char` breaks `package:win32` which is used in Flutter so it breaks the Flutter build: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8824468064587445729/+/u/Android_Views_Integration_Tests/stdout For reference: full list of Flutter failues: https://github.com/flutter/flutter/runs/4890844911 Original change's description: > [vm/ffi] Add common C types > > We're adding these types to `dart:ffi` rather than `package:ffi` so that > they can be used with `FfiNative`s. > > Adds `NativeType`s for the following C types: > > * char > * unsigned char > * signed char > * short > * unsigned short > * int > * unsigned int > * long > * unsigned long > * long long > * unsigned long long > * uintptr_t > * size_t > * wchar_t > > Because the C standard only defines minimum sizes for many of these > types, future platforms might diverge from the typical size even if all > platforms currently agree on a size. To avoid having to reification > later, we define all types as AbiSpecificIntegers rather than typedefs, > even if all current target platforms agree on the size. > > Closes: #36140 > > TEST=tests/ffi/c_types_test.dart > > Change-Id: Ie97d253856d787386529231e8060f879069be886 > Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-try,dart-sdk-mac-try,dart-sdk-win-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-canary-linux-debug-try,vm-fuchsia-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-mac-debug-x64-try,vm-kernel-mac-release-arm64-try,vm-kernel-nnbd-win-release-ia32-try,vm-kernel-nnbd-win-release-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-win-release-x64-try > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228541 > Reviewed-by: Martin Kustermann <kustermann@google.com> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Ic56df88c653b1395ed5e5a71af5e571b1adc3671 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229152 Reviewed-by: Daco Harkes <dacoharkes@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
|
Update 2022-01-20: This will be available in
dart:ffi
from Dart 2.17 (and from now on tip of tree). In the mean time this is also available inpackage:ffi
for Dart 2.16 (dev release).Update 2021-01-07: We will implement this by implementing #42563 and probably adding the common types to
package:ffi
.Currently
dart:ffi
only supports:int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
intptr_t
float
double
However, many C APIs use C types such as
int
,long
,size_t
,uintptr_t
, andwchar_t
.We could support these types. The question is if we support these types, then what other types should we support.
An alternative could be to not support these types but provide a way for users to specify types which differ in size per platform.
@jonasfj @sjindel-google
The text was updated successfully, but these errors were encountered: