Skip to content

[ffigen] Generate TypedLists for Pointer arguments if leaf functions #874

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

Closed
dcharkes opened this issue Jan 2, 2024 · 5 comments
Closed
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) P2 A bug or feature request we're likely to work on package:ffigen

Comments

@dcharkes
Copy link
Collaborator

dcharkes commented Jan 2, 2024

It would be nice if ffigen supported generating the code for unwrapping leaf functions. Unless I missed something I have to manually call LookupFunction with the correct type arguments.

Originally posted by @johnmccutchan in dart-lang/sdk#54465 (comment)

@johnmccutchan Would you like all arguments to be typed data? This should probably be some regex match so that one can pick and choose which functions. If we want to take it really far one might want to configure it per argument even.

functions:
  leaf:
    include:
      # Match function name.
      - 'myFunc'
       # Do this to set isLeaf:true for all functions.
      - '.*'
    exclude:
      # If you only use exclude, then everything
      # not excluded is generated.
      - 'dispose'
  use-typed-data:
    include:
      # Use `TypedData` arguments for `Pointer` arguments for `myFunc`
      - 'myFunc'
       # Use `TypedData` arguments for `Pointer` arguments for all functions.
      - '.*'
    exclude:
      # If you only use exclude, then everything
      # not excluded is generated.
      - 'dispose'

Matching functions in use-typed-data that are not leaf is a no-op or an error.

Only arguments are typed data, return types are not.

The only types that can be unwrapped are:

  • int8_t
  • int16_t
  • int32_t
  • int64_t
  • uint8_t
  • uint16_t
  • uint32_t
  • uint64_t
  • float
  • double

Abi-specific integers are not supported.

@dcharkes dcharkes added P2 A bug or feature request we're likely to work on good first issue A good starting issue for contributors (issues with this label will appear in /contribute) package:ffigen labels Jan 2, 2024
@johnmccutchan
Copy link

For my purposes I would want all TypedList arguments to be automatically unwrapped to pointers for the native call.

Typically it looks like:

FFI_PLUGIN_EXPORT void body_set_position(WorldBody* body, float* v4);

FFI_PLUGIN_EXPORT void body_set_rotation(WorldBody* body, float* q4);

FFI_PLUGIN_EXPORT CollisionShape* create_convex_shape(ConvexShapeConfig* config, float* points, int num_points);

@johnmccutchan
Copy link

Could we do something where we mark up arguments in the header file?

FFI_PLUGIN_EXPORT void body_set_position(WorldBody* body, /* ffigen: unwrapped-type-data */ float* v4);

@johnmccutchan
Copy link

should the yaml field be prefixed with leaf-? Instead of use-typed-data: it should be leaf-use-typed-data:

@dcharkes
Copy link
Collaborator Author

dcharkes commented Jan 2, 2024

So far we have not elected to have configuration in the header files, because in many projects the author does not own the C header file.

Regarding configuration, we're considering moving away from YAML and having a Dart API instead. But that's a bit of a longer term project.

For now lets just stick with the YAML style we already have.

should the yaml field be prefixed with leaf-? Instead of use-typed-data: it should be leaf-use-typed-data:

sgtm

@dcharkes
Copy link
Collaborator Author

dcharkes commented May 8, 2024

With the new API, this is no longer needed. The .address expression is used in the argument position.

@dcharkes dcharkes closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) P2 A bug or feature request we're likely to work on package:ffigen
Projects
None yet
Development

No branches or pull requests

2 participants