-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Version
ffigen: 20.0.0
Dart: 3.10.0
Platform: Linux
Summary
When generating bindings, top-level C functions have their parameter names sanitized correctly (e.g., in β in$), but struct field function pointers do not.
This inconsistency results in invalid Dart code when the C parameter name is a Dart reserved keyword.
This issue is related to #512, but this time the bug is specifically inside struct member function pointers rather than top-level functions.
π Minimal reproducible example
C header (test.h)
void var(void *in);
struct cls {
void (*var)(void *in);
};π Generated Dart code
β Top-level function (correct)
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(symbol: 'var')
external void var$(ffi.Pointer<ffi.Void> in$);Notice in was correctly renamed to in$.
β Struct field function pointer (incorrect)
final class cls extends ffi.Struct {
external ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(ffi.Pointer<ffi.Void> in)>> var$1;
}This still contains:
... Function(ffi.Pointer<ffi.Void> in)where in is a Dart reserved keyword β Dart compilation fails.
β Problem
ffigen already has logic to rename reserved keywords for parameters in top-level functions, but this renaming is not applied to:
- function pointer parameters inside struct fields
- function pointer typedefs
- callbacks
This inconsistency causes generated code to be syntactically invalid.
β Expected behavior
ffigen should apply the same identifier sanitization logic everywhere, including:
- top-level functions
- nested typedefs
- struct field function pointers
- callback signatures
Example of expected output:
ffi.Void Function(ffi.Pointer<ffi.Void> in$)or:
ffi.Void Function(ffi.Pointer<ffi.Void> arg0)Metadata
Metadata
Assignees
Labels
Type
Projects
Status