Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Fix #577 (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe authored Sep 1, 2023
1 parent 3508f98 commit 876b7ad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/src/code_generator/imports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ final unsignedLongLongType =
ImportedType(ffiImport, 'UnsignedLongLong', 'int', '0');
final longLongType = ImportedType(ffiImport, 'LongLong', 'int', '0');

final floatType = ImportedType(ffiImport, 'Float', 'double', '0');
final doubleType = ImportedType(ffiImport, 'Double', 'double', '0');
final floatType = ImportedType(ffiImport, 'Float', 'double', '0.0');
final doubleType = ImportedType(ffiImport, 'Double', 'double', '0.0');

final sizeType = ImportedType(ffiImport, 'Size', 'int', '0');
final wCharType = ImportedType(ffiImport, 'WChar', 'int', '0');
Expand Down
4 changes: 2 additions & 2 deletions lib/src/code_generator/native_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class NativeType extends Type {
SupportedNativeType.Uint16: NativeType._('Uint16', 'int', '0'),
SupportedNativeType.Uint32: NativeType._('Uint32', 'int', '0'),
SupportedNativeType.Uint64: NativeType._('Uint64', 'int', '0'),
SupportedNativeType.Float: NativeType._('Float', 'double', '0'),
SupportedNativeType.Double: NativeType._('Double', 'double', '0'),
SupportedNativeType.Float: NativeType._('Float', 'double', '0.0'),
SupportedNativeType.Double: NativeType._('Double', 'double', '0.0'),
SupportedNativeType.IntPtr: NativeType._('IntPtr', 'int', '0'),
SupportedNativeType.UintPtr: NativeType._('UintPtr', 'int', '0'),
};
Expand Down
8 changes: 8 additions & 0 deletions test/native_objc_test/block_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ void main() {
expect(value, 123);
});

test('Float block', () {
final block = ObjCBlock2.fromFunction(lib, (double x) {
return x + 4.56;
});
expect(block(1.23), closeTo(5.79, 1e-6));
expect(BlockTester.callFloatBlock_(lib, block), closeTo(5.79, 1e-6));
});

Pointer<Void> funcPointerBlockRefCountTest() {
final block = ObjCBlock1.fromFunctionPointer(
lib, Pointer.fromFunction(_add100, 999));
Expand Down
6 changes: 6 additions & 0 deletions test/native_objc_test/block_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import <Foundation/NSThread.h>

typedef int32_t (^IntBlock)(int32_t);
typedef float (^FloatBlock)(float);
typedef void (^VoidBlock)();

// Wrapper around a block, so that our Dart code can test creating and invoking
Expand All @@ -21,6 +22,7 @@ - (IntBlock)getBlock;
- (void)pokeBlock;
+ (void)callOnSameThread:(VoidBlock)block;
+ (NSThread*)callOnNewThread:(VoidBlock)block;
+ (float)callFloatBlock:(FloatBlock)block;
@end

@implementation BlockTester
Expand Down Expand Up @@ -86,4 +88,8 @@ + (NSThread*)callOnNewThread:(VoidBlock)block {
return [[NSThread alloc] initWithBlock: block];
}

+ (float)callFloatBlock:(FloatBlock)block {
return block(1.23);
}

@end

0 comments on commit 876b7ad

Please sign in to comment.