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

How to handle variable number of arguments? #238

Closed
arcticfox1919 opened this issue May 31, 2022 · 4 comments
Closed

How to handle variable number of arguments? #238

arcticfox1919 opened this issue May 31, 2022 · 4 comments
Labels
package:ffigen waiting-on-dart-ffi Issues which are blocked by lacking suppport in dart:ffi

Comments

@arcticfox1919
Copy link

The C library function I want to bind has some variable number of parameters, ffigen doesn't seem to handle this situation very well, is there any way?

for example:

int func(int, ... ) {}
@dcharkes dcharkes added the waiting-on-dart-ffi Issues which are blocked by lacking suppport in dart:ffi label May 31, 2022
@dcharkes
Copy link
Collaborator

This is not yet supported in dart:ffi dart-lang/sdk#38578, so package:ffigen cannot generate something to support this yet.

@kingwill101
Copy link

@dcharkes any update on this, now that dart-lang/sdk#38578 has been completed?

@kingwill101
Copy link

I see that 79e845f was done but it seems to not work.

int fcntl (int __fd, int __cmd, ...);
  int fcntl(
    int __fd,
    int __cmd,
  ) {
    return _fcntl(
      __fd,
      __cmd,
    );
  }


  late final _fcntlPtr =
      _lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>>('fcntl');
  late final _fcntl = _fcntlPtr.asFunction<int Function(int, int)>();

@dcharkes
Copy link
Collaborator

If you write bindings yourself, you need to use VarArgs somewhere: https://api.dart.dev/stable/3.4.4/dart-ffi/VarArgs-class.html

If you want FFIgen to generate bindings, you need to configure FFIgen to do that.

functions:
  variadic-arguments:
    myfunc:
      // Native C types are supported
      - [int, unsigned char, long*, float**]
      // Common C typedefs (stddef.h) are supported too
      - [uint8_t, intptr_t, size_t, wchar_t*]
      // Structs/Unions/Typedefs from generated code or a library import can be referred too.
      - [MyStruct*, my_custom_lib.CustomUnion]

Since the feature is implemented, and was tracked by #497, I'll close this as duplicate issue.

Please file a new issue if you're having issues with VarArgs or FFIgen variadic-arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:ffigen waiting-on-dart-ffi Issues which are blocked by lacking suppport in dart:ffi
Projects
None yet
Development

No branches or pull requests

4 participants