[ffigen] Fixed missing typedefs nested under return type of another typedef (#116)
diff --git a/pkgs/ffigen/.travis.yml b/pkgs/ffigen/.travis.yml index e535a1a..6f311a4 100644 --- a/pkgs/ffigen/.travis.yml +++ b/pkgs/ffigen/.travis.yml
@@ -1,6 +1,6 @@ language: dart dart: -- dev +- stable # Only building master means that we don't run two builds for each pull request. dart_task: - test: --platform vm @@ -26,6 +26,6 @@ matrix: include: - - dart: dev + - dart: stable script: ./tool/travis.sh name: Collect and report coverage.
diff --git a/pkgs/ffigen/CHANGELOG.md b/pkgs/ffigen/CHANGELOG.md index b452cb9..d24647f 100644 --- a/pkgs/ffigen/CHANGELOG.md +++ b/pkgs/ffigen/CHANGELOG.md
@@ -1,3 +1,6 @@ +# 1.0.6 +- Fixed missing typedefs nested in another typedef's return types. + # 1.0.5 - Fixed issues with generating macros of type `double.Infinity` and `double.NaN`.
diff --git a/pkgs/ffigen/lib/src/code_generator/typedef.dart b/pkgs/ffigen/lib/src/code_generator/typedef.dart index e0c3c7a..7f3c684 100644 --- a/pkgs/ffigen/lib/src/code_generator/typedef.dart +++ b/pkgs/ffigen/lib/src/code_generator/typedef.dart
@@ -47,6 +47,10 @@ dep.addAll(base.nativeFunc.getDependencies()); } } + final returnTypeBase = returnType.getBaseType(); + if (returnTypeBase.broadType == BroadType.NativeFunction) { + dep.addAll(returnTypeBase.nativeFunc.getDependencies()); + } dep.add(this); return dep; }
diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index 7b1185b..2d21dc5 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml
@@ -3,7 +3,7 @@ # BSD-style license that can be found in the LICENSE file. name: ffigen -version: 1.0.5 +version: 1.0.6 homepage: https://github.com/dart-lang/ffigen description: Experimental generator for FFI bindings, using LibClang to parse C header files.
diff --git a/pkgs/ffigen/test/header_parser_tests/native_func_typedef.h b/pkgs/ffigen/test/header_parser_tests/native_func_typedef.h index f799b9d..da2f3c0 100644 --- a/pkgs/ffigen/test/header_parser_tests/native_func_typedef.h +++ b/pkgs/ffigen/test/header_parser_tests/native_func_typedef.h
@@ -11,3 +11,7 @@ // This will be removed because 'long double' is unsupported. void funcNestedUnimplemented(void (*unnamed1)(void (*unnamed2)(long double))); + +typedef void (*insideReturnType)(); +typedef insideReturnType (*withTypedefReturnType)(); +void funcWithNativeFunc(withTypedefReturnType named);
diff --git a/pkgs/ffigen/test/header_parser_tests/native_func_typedef_test.dart b/pkgs/ffigen/test/header_parser_tests/native_func_typedef_test.dart index 7409609..1676817 100644 --- a/pkgs/ffigen/test/header_parser_tests/native_func_typedef_test.dart +++ b/pkgs/ffigen/test/header_parser_tests/native_func_typedef_test.dart
@@ -66,6 +66,16 @@ } _dart_func _func; +void funcWithNativeFunc( + ffi.Pointer<ffi.NativeFunction<withTypedefReturnType>> named, +) { +_funcWithNativeFunc ??= _dylib.lookupFunction<_c_funcWithNativeFunc,_dart_funcWithNativeFunc>('funcWithNativeFunc'); + return _funcWithNativeFunc( + named, + ); +} +_dart_funcWithNativeFunc _funcWithNativeFunc; + } class struc extends ffi.Struct{ @@ -88,6 +98,20 @@ ffi.Pointer<ffi.NativeFunction<_typedefC_4>> unnamed1, ); +typedef _typedefC_5 = ffi.Void Function( +); + +typedef withTypedefReturnType = ffi.Pointer<ffi.NativeFunction<_typedefC_5>> Function( +); + +typedef _c_funcWithNativeFunc = ffi.Void Function( + ffi.Pointer<ffi.NativeFunction<withTypedefReturnType>> named, +); + +typedef _dart_funcWithNativeFunc = void Function( + ffi.Pointer<ffi.NativeFunction<withTypedefReturnType>> named, +); + typedef _typedefC_1 = ffi.Void Function( );