Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Allow Utf8 usage without cast #6

Closed
vaind opened this issue Sep 14, 2019 · 6 comments
Closed

Allow Utf8 usage without cast #6

vaind opened this issue Sep 14, 2019 · 6 comments

Comments

@vaind
Copy link

vaind commented Sep 14, 2019

This example seemed to allow passing to C and reading from C without casts, by defining an FFI function as follows:

typedef reverse_func = ffi.Pointer<Utf8> Function(ffi.Pointer<Utf8> str, ffi.Int32 length);
...
// used as:
final reversedMessage = Utf8.fromUtf8(reverse(Utf8.toUtf8('backwards'), 9));

That doesn't work with the current version of the Utf8.toUtf8 and fromUtf8. It's necessary to use Pointer<Uint8> in the function definition with as well as appropriate casts when calling/receiving. The error when using the signature as above is Error: Expected type 'Pointer<Utf8> Function()' to be 'Pointer<Uint8> Function()'

As this is repeated in all the calls, it would be nice if we could get rid of the casts altogether (which seemed to have worked in the given example).

The difference seems to be

class Utf8 extends ffi.Struct<Utf8> {
  @ffi.Uint8() // this
@mkustermann
Copy link

@dcharkes @sjindel-google

@sjindel-google
Copy link
Contributor

@vaind Can you please share the code where you call asFunction/lookupFunction?

@vaind
Copy link
Author

vaind commented Sep 16, 2019

Does this diff help? It was an attempt to get rid of the casts.

objectbox/objectbox-dart@db1454d

@sjindel-google
Copy link
Contributor

I checked out your code but I couldn't find the reverse function?

@vaind
Copy link
Author

vaind commented Sep 16, 2019

The reverse function from the description of this comment is from the dart FFI example repo linked in the original post. We're not using that function, I just referred to it hoping you'd be aware of it and it would be easier to understand than talking about our actual code (as linked in the previous comment).

The whole thing is not about that specific function but about being able to use Pointer<Utf8> in FFI typedefs - that currently doesn't compile

@vaind
Copy link
Author

vaind commented Nov 18, 2019

This is now possible with ffi 0.1.3

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

No branches or pull requests

3 participants