[ffigen] Add new supported typedef - `uintptr_t` (mapped to `ffi.UintPtr`). (#499)
diff --git a/pkgs/ffigen/CHANGELOG.md b/pkgs/ffigen/CHANGELOG.md index 15ed965..400cc2f 100644 --- a/pkgs/ffigen/CHANGELOG.md +++ b/pkgs/ffigen/CHANGELOG.md
@@ -1,3 +1,7 @@ +# 7.2.4 + +- Add new supported typedef - `uintptr_t` (mapped to `ffi.UintPtr`). + # 7.2.3 - Change compiler option order so that user options can override built-in
diff --git a/pkgs/ffigen/lib/src/code_generator/native_type.dart b/pkgs/ffigen/lib/src/code_generator/native_type.dart index 4be4b16..d76e7e7 100644 --- a/pkgs/ffigen/lib/src/code_generator/native_type.dart +++ b/pkgs/ffigen/lib/src/code_generator/native_type.dart
@@ -20,6 +20,7 @@ Float, Double, IntPtr, + UintPtr, } /// Represents a primitive native type, such as float. @@ -38,6 +39,7 @@ SupportedNativeType.Float: NativeType._('Float', 'double', '0'), SupportedNativeType.Double: NativeType._('Double', 'double', '0'), SupportedNativeType.IntPtr: NativeType._('IntPtr', 'int', '0'), + SupportedNativeType.UintPtr: NativeType._('UintPtr', 'int', '0'), }; final String _cType;
diff --git a/pkgs/ffigen/lib/src/header_parser/type_extractor/cxtypekindmap.dart b/pkgs/ffigen/lib/src/header_parser/type_extractor/cxtypekindmap.dart index 41af99a..2d25d9f 100644 --- a/pkgs/ffigen/lib/src/header_parser/type_extractor/cxtypekindmap.dart +++ b/pkgs/ffigen/lib/src/header_parser/type_extractor/cxtypekindmap.dart
@@ -32,6 +32,7 @@ 'int32_t': SupportedNativeType.Int32, 'int64_t': SupportedNativeType.Int64, 'intptr_t': SupportedNativeType.IntPtr, + 'uintptr_t': SupportedNativeType.UintPtr, }; var supportedTypedefToImportedType = <String, ImportedType>{
diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index 4c109ec..387e08d 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: 7.2.3 +version: 7.2.4 description: Generator for FFI bindings, using LibClang to parse C header files. repository: https://github.com/dart-lang/ffigen
diff --git a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart index 35fa0a9..e16d3d9 100644 --- a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart +++ b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart
@@ -149,6 +149,29 @@ ), ], ), + Struct( + name: 'WithIntPtrUintPtr', + members: [ + Member( + name: 'a', + type: PointerType( + NativeType( + SupportedNativeType.UintPtr, + ), + ), + ), + Member( + name: 'b', + type: PointerType( + PointerType( + NativeType( + SupportedNativeType.IntPtr, + ), + ), + ), + ), + ], + ), ], );
diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart index f84642b..5668f9d 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart
@@ -26,3 +26,9 @@ @ffi.Uint8() external int c; } + +class WithIntPtrUintPtr extends ffi.Struct { + external ffi.Pointer<ffi.UintPtr> a; + + external ffi.Pointer<ffi.Pointer<ffi.IntPtr>> b; +}
diff --git a/pkgs/ffigen/test/native_test/native_test.c b/pkgs/ffigen/test/native_test/native_test.c index 037a73b..f971ac6 100644 --- a/pkgs/ffigen/test/native_test/native_test.c +++ b/pkgs/ffigen/test/native_test/native_test.c
@@ -27,6 +27,8 @@ intptr_t Function1IntPtr(intptr_t x) { return x + 42; } +uintptr_t Function1UintPtr(uintptr_t x) { return x + 42; } + float Function1Float(float x) { return x + 42.0f; } double Function1Double(double x) { return x + 42.0; }
diff --git a/pkgs/ffigen/test/native_test/native_test_bindings.dart b/pkgs/ffigen/test/native_test/native_test_bindings.dart index 6fd5a6a..2e8471f 100644 --- a/pkgs/ffigen/test/native_test/native_test_bindings.dart +++ b/pkgs/ffigen/test/native_test/native_test_bindings.dart
@@ -158,6 +158,20 @@ late final _Function1IntPtr = _Function1IntPtrPtr.asFunction<int Function(int)>(); + int Function1UintPtr( + int x, + ) { + return _Function1UintPtr( + x, + ); + } + + late final _Function1UintPtrPtr = + _lookup<ffi.NativeFunction<ffi.UintPtr Function(ffi.UintPtr)>>( + 'Function1UintPtr'); + late final _Function1UintPtr = + _Function1UintPtrPtr.asFunction<int Function(int)>(); + double Function1Float( double x, ) {