Skip to content

Commit

Permalink
Merge branch 'release/0.7.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
yulingtianxia committed Aug 10, 2022
2 parents 1e9a870 + 312288b commit cc8d0a5
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 49 deletions.
2 changes: 1 addition & 1 deletion dart_native/.fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutterSdkVersion": "stable",
"flutterSdkVersion": "2.2.3",
"flavors": {}
}
5 changes: 5 additions & 0 deletions dart_native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.7.4

* [Fix] Errors and warnings.
* [Fix] Dart exceptions on Android.

## 0.7.3

* [Fix] Garbage characters on Android.
Expand Down
35 changes: 14 additions & 21 deletions dart_native/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.2"
version: "1.7.1"
args:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -98,14 +98,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.0"
checked_yaml:
dependency: transitive
description:
Expand Down Expand Up @@ -140,7 +140,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
version: "1.15.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -168,7 +168,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.7.3"
version: "0.7.4"
dart_native_gen:
dependency: transitive
description:
Expand All @@ -189,7 +189,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.2.0"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -297,21 +297,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.3.0"
mime:
dependency: transitive
description:
Expand All @@ -332,7 +325,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.0"
pedantic:
dependency: transitive
description:
Expand Down Expand Up @@ -393,7 +386,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -435,7 +428,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.3.0"
timing:
dependency: transitive
description:
Expand All @@ -456,7 +449,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
version: "2.1.0"
watcher:
dependency: transitive
description:
Expand All @@ -479,5 +472,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.17.0-0 <3.0.0"
dart: ">=2.13.0 <3.0.0"
flutter: ">=2.2.0"
4 changes: 2 additions & 2 deletions dart_native/lib/src/android/runtime/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final Pointer<Void> Function(
Pointer<NativeFunction<InvokeCallback>>,
int dartPort,
int thread,
bool isInterface) nativeInvoke =
int isInterface) nativeInvoke =
nativeDylib
.lookup<
NativeFunction<
Expand All @@ -72,7 +72,7 @@ final Pointer<Void> Function(
Pointer<NativeFunction<InvokeCallback>>,
Int64 dartPort,
Int32 thread,
Bool isInterface)>>('InvokeNativeMethod')
Int32 isInterface)>>('InvokeNativeMethod')
.asFunction();

// bind dart object lifecycle with java object
Expand Down
10 changes: 3 additions & 7 deletions dart_native/lib/src/android/runtime/messenger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ void _invokeCallback(Pointer<Void> result, Pointer<Utf8> method,
}

/// remove assigned signature
_assignedSignatureMap[method]?.forEach((ptr) {
calloc.free(ptr);
});
_assignedSignatureMap[method]?.forEach(calloc.free);
_assignedSignatureMap.remove(method);

calloc.free(typePtrs);
Expand Down Expand Up @@ -122,7 +120,7 @@ dynamic _doInvoke(
callbackPtr,
nativePort,
thread.index,
isInterface);
isInterface ? 1 : 0);

dynamic result;
if (callback == null) {
Expand All @@ -132,9 +130,7 @@ dynamic _doInvoke(
.elementAt(args?.length ?? 0)
.value
.toDartString());
assignedSignaturePtr?.forEach((ptr) {
calloc.free(ptr);
});
assignedSignaturePtr?.forEach(calloc.free);
calloc.free(nativeArguments.typePointers);
}
return result;
Expand Down
1 change: 0 additions & 1 deletion dart_native/lib/src/common/finalizer.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:ffi';

import 'package:dart_native/src/common/native_dylib.dart';
import 'package:dart_native/src/darwin/common/callback_manager.dart';
import 'package:ffi/ffi.dart';

typedef DartFinalizerFunction = void Function();
Expand Down
22 changes: 21 additions & 1 deletion dart_native/lib/src/common/native_dylib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import 'dart:ffi';
import 'dart:io';

import 'package:dart_native/src/android/common/library.dart' as library_android
show nativeDylib;
show nativeDylib, nativePort;

import 'package:dart_native/src/darwin/common/library.dart' as library_darwin
show nativeDylib;
import 'package:dart_native/src/darwin/common/callback_manager.dart'
as callback_darwin show nativePort;

DynamicLibrary? _nativeDylib;
DynamicLibrary get nativeDylib {
Expand All @@ -22,3 +25,20 @@ DynamicLibrary get nativeDylib {

return _nativeDylib!;
}

int _nativePort = 0;
int get nativePort {
if (_nativePort != 0) {
return _nativePort;
}

if (Platform.isIOS || Platform.isMacOS) {
_nativePort = callback_darwin.nativePort;
} else if (Platform.isAndroid) {
_nativePort = library_android.nativePort;
} else {
throw 'Platform not supported: ${Platform.localeName}';
}

return _nativePort;
}
2 changes: 1 addition & 1 deletion dart_native/lib/src/darwin/common/callback_register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool registerMethodCallback(
.setCallbackForSelectorOnTarget(targetPtr, selectorPtr, function);
List<String> dartTypes = dartTypeStringForFunction(function);
List<String> nativeTypes = nativeTypeStringForDartTypes(dartTypes);
bool returnString = nativeTypes.first == 'String';
int returnString = nativeTypes.first == 'String' ? 1 : 0;
int result = nativeAddMethod(
targetPtr, selectorPtr, types, returnString, _callbackPtr, nativePort);
return result != 0;
Expand Down
15 changes: 5 additions & 10 deletions dart_native/lib/src/darwin/runtime/block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,15 @@ class Block extends id {
List<String> nativeTypes = nativeTypeStringForDartTypes(dartTypes);
Pointer<Utf8> typeStringPtr = nativeTypes.join(', ').toNativeUtf8();
Pointer<Void> blockPtr =
blockCreate(typeStringPtr, _callbackPtr, shouldReturnAsync, nativePort);
blockCreate(typeStringPtr, _callbackPtr, shouldReturnAsync ? 0 : 1, nativePort);
assert(blockPtr != nullptr);
if (blockPtr == nullptr) {
return nilBlock;
}
int sequence = _blockSequence(blockPtr);
Block result = Block.fromPointer(blockPtr);
Block result = Block.fromPointer(blockPtr, function: function);
calloc.free(typeStringPtr);
result.types = dartTypes;
result.function = function;
result.shouldReturnAsync = shouldReturnAsync;
result.typeEncodingsPtrPtr = _blockTypeEncodings(blockPtr);
result.sequence = sequence;
Expand All @@ -84,7 +83,7 @@ class Block extends id {
/// Creating a [Block] from a [Pointer].
///
/// [Block] created by this method do NOT have [function] property.
Block.fromPointer(Pointer<Void> ptr) : super(ptr);
Block.fromPointer(Pointer<Void> ptr, {this.function}) : super(ptr);

/// This [isa] block in iOS, but it's meaningless for a block created
/// by Dart function.
Expand Down Expand Up @@ -134,12 +133,8 @@ class Block extends id {
if (newPtr == pointer) {
return this;
}
Block result = Block.fromPointer(newPtr);
// Block created by function.
if (function != null) {
result.function = function;
result.types = types;
}
Block result = Block.fromPointer(newPtr, function: function);
result.types = types;
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ typedef AddMethodC = Int32 Function(
Pointer<Void> target,
Pointer<Void> selector,
Pointer<Utf8> types,
Bool returnString,
Int32 returnString,
Pointer<NativeFunction<MethodIMPCallbackC>> callback,
Int64 dartPort);
typedef AddMethodD = int Function(
Pointer<Void> target,
Pointer<Void> selector,
Pointer<Utf8> types,
bool returnString,
int returnString,
Pointer<NativeFunction<MethodIMPCallbackC>> callback,
int dartPort);
final AddMethodD nativeAddMethod =
Expand Down Expand Up @@ -107,12 +107,12 @@ typedef BlockCallbackC = Void Function(
typedef BlockCreateC = Pointer<Void> Function(
Pointer<Utf8> typeEncodings,
Pointer<NativeFunction<BlockCallbackC>> callback,
Bool shouldReturnAsync,
Int32 shouldReturnAsync,
Int64 dartPort);
typedef BlockCreateD = Pointer<Void> Function(
Pointer<Utf8> typeEncodings,
Pointer<NativeFunction<BlockCallbackC>> callback,
bool shouldReturnAsync,
int shouldReturnAsync,
int dartPort);
final BlockCreateD blockCreate = nativeDylib
.lookupFunction<BlockCreateC, BlockCreateD>('native_block_create');
Expand Down
2 changes: 1 addition & 1 deletion dart_native/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_native
description: Write native code using Dart. This package liberates you from native code and low performance channel.
version: 0.7.3
version: 0.7.4
homepage: https://github.com/dart-native/dart_native

environment:
Expand Down

0 comments on commit cc8d0a5

Please sign in to comment.