Skip to content

Commit 5dcb037

Browse files
committed
Merge branch 'release/0.3.22'
2 parents bf245c0 + 7635f11 commit 5dcb037

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+9258
-248
lines changed

dart_native/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.22
2+
3+
* [Fix] Callbacks from multi-isolates on iOS.
4+
15
## 0.3.21
26

37
* [Fix] Some crash on Android.

dart_native/example/ios/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ EXTERNAL SOURCES:
2323

2424
SPEC CHECKSUMS:
2525
CocoaLumberjack: e8955b9d337ac307103b0a34fd141c32f27e53c5
26-
dart_native: 5de43456852385997b9b29dbf40f85d82c265e1a
26+
dart_native: 628e1d0112ce8c6a09fc506004a16820b20a2d16
2727
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
2828

2929
PODFILE CHECKSUM: f10e42e188a012076f9d5e111f499229a501832a

dart_native/example/ios/Runner.xcodeproj/project.pbxproj

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -76,7 +76,6 @@
7676
AD7A5062BD98140867CF8A5E /* Pods-Runner.release.xcconfig */,
7777
9CB3F088E1519AF7D9E72E82 /* Pods-Runner.profile.xcconfig */,
7878
);
79-
name = Pods;
8079
path = Pods;
8180
sourceTree = "<group>";
8281
};
@@ -186,7 +185,7 @@
186185
};
187186
};
188187
buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */;
189-
compatibilityVersion = "Xcode 9.3";
188+
compatibilityVersion = "Xcode 12.0";
190189
developmentRegion = en;
191190
hasScannedForEncodings = 0;
192191
knownRegions = (
@@ -378,6 +377,7 @@
378377
buildSettings = {
379378
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
380379
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
380+
DEVELOPMENT_TEAM = D3RCVUP6VH;
381381
ENABLE_BITCODE = NO;
382382
FRAMEWORK_SEARCH_PATHS = (
383383
"$(inherited)",
@@ -509,6 +509,7 @@
509509
buildSettings = {
510510
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
511511
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
512+
DEVELOPMENT_TEAM = D3RCVUP6VH;
512513
ENABLE_BITCODE = NO;
513514
FRAMEWORK_SEARCH_PATHS = (
514515
"$(inherited)",
@@ -535,6 +536,7 @@
535536
buildSettings = {
536537
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
537538
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
539+
DEVELOPMENT_TEAM = D3RCVUP6VH;
538540
ENABLE_BITCODE = NO;
539541
FRAMEWORK_SEARCH_PATHS = (
540542
"$(inherited)",

dart_native/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
30-
<Testables>
31-
</Testables>
3230
<MacroExpansion>
3331
<BuildableReference
3432
BuildableIdentifier = "primary"
@@ -38,8 +36,8 @@
3836
ReferencedContainer = "container:Runner.xcodeproj">
3937
</BuildableReference>
4038
</MacroExpansion>
41-
<AdditionalOptions>
42-
</AdditionalOptions>
39+
<Testables>
40+
</Testables>
4341
</TestAction>
4442
<LaunchAction
4543
buildConfiguration = "Debug"
@@ -61,8 +59,6 @@
6159
ReferencedContainer = "container:Runner.xcodeproj">
6260
</BuildableReference>
6361
</BuildableProductRunnable>
64-
<AdditionalOptions>
65-
</AdditionalOptions>
6662
</LaunchAction>
6763
<ProfileAction
6864
buildConfiguration = "Profile"

dart_native/example/ios/Runner/AppDelegate.m

+13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
#import "AppDelegate.h"
22
#import "GeneratedPluginRegistrant.h"
33
#import <CocoaLumberjack/CocoaLumberjack.h>
4+
5+
#if __has_include(<dart_native/dart_native.h>)
6+
#import <dart_native/dart_native.h>
7+
#else
8+
@import dart_native;
9+
#endif
10+
411
#import "RuntimeSon.h"
512

13+
614
@implementation AppDelegate
715

816
- (BOOL)application:(UIApplication *)application
917
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
18+
#if DEBUG
19+
DartNativeSetThrowException(true);
20+
#else
21+
DartNativeSetThrowException(false);
22+
#endif
1023
FlutterViewController *controller = (FlutterViewController*)self.window.rootViewController;
1124

1225
FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"sample.dartnative.com"

dart_native/example/ios/Runner/RuntimeStub.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ - (instancetype)init {
2727
self = [super init];
2828
if (self) {
2929
_object = [NSObject new];
30-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
30+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
3131
[NSNotificationCenter.defaultCenter postNotificationName:@"SampleDartNotification" object:nil];
3232
});
3333
}
@@ -232,7 +232,7 @@ - (void)fooCompletion:(void (^)(void))block {
232232

233233
- (void)fooCStringBlock:(CStringRetBlock)block {
234234
char *arg = "test c-string";
235-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
235+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
236236
if (block) {
237237
char *result = block(arg);
238238
DDLogInfo(@"%s result: %s", __FUNCTION__, result);
@@ -242,15 +242,15 @@ - (void)fooCStringBlock:(CStringRetBlock)block {
242242

243243
- (void)fooDelegate:(id<SampleDelegate>)delegate {
244244
DDLogInfo(@"%s arg: %@", __FUNCTION__, delegate);
245-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
245+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
246246
NSObject *result = [delegate callback];
247247
DDLogInfo(@"%s callback result:%@", __FUNCTION__, result);
248248
});
249249
}
250250

251251
- (void)fooStructDelegate:(id<SampleDelegate>)delegate {
252252
DDLogInfo(@"%s arg: %@", __FUNCTION__, delegate);
253-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
253+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
254254
CGRect result = [delegate callbackStruct:CGRectMake(1.1, 2.2, 3.3, 4.4)];
255255
DDLogInfo(@"%s callback result:%@", __FUNCTION__, NSStringFromCGRect(result));
256256
});

dart_native/example/lib/ios/unit_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ testIOS(RuntimeStub stub, DelegateStub delegate) {
160160

161161
void _checkTimer(String isolateID) async {
162162
RuntimeStub stub = RuntimeStub();
163+
DelegateStub delegate = DelegateStub();
163164
Timer.periodic(new Duration(seconds: 1), (Timer t) {
164165
stub.fooCompletion(() {
165166
print('hello completion block on $isolateID!');
166167
});
168+
stub.fooDelegate(delegate);
167169
});
168170
}

dart_native/example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ packages:
168168
path: ".."
169169
relative: true
170170
source: path
171-
version: "0.3.21"
171+
version: "0.3.22"
172172
dart_native_gen:
173173
dependency: transitive
174174
description:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// DNDartPortsContainer.h
3+
// dart_native
4+
//
5+
// Created by 杨萧玉 on 2021/7/18.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
#import "dart_api_dl.h"
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface DNAssociatedDartObject : NSObject
14+
15+
@property (nonatomic, readonly, weak) NSObject *host;
16+
// Object can be passed on multi-isolates.
17+
@property (nonatomic, readonly) NSSet<NSNumber *> *dartPorts;
18+
19+
- (instancetype)initWithHost:(NSObject *)host
20+
storageKey:(const void *)storageKey;
21+
+ (instancetype)attachHost:(NSObject *)host
22+
dartPort:(Dart_Port)dartPort
23+
storageKey:(const void *)storageKey;
24+
+ (instancetype)objectForHost:(NSObject *)host
25+
storageKey:(const void *)storageKey;
26+
@end
27+
28+
NS_ASSUME_NONNULL_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//
2+
// DNDartPortsContainer.m
3+
// dart_native
4+
//
5+
// Created by 杨萧玉 on 2021/7/18.
6+
//
7+
8+
#import "DNAssociatedDartObject.h"
9+
#import <objc/runtime.h>
10+
#import "native_runtime.h"
11+
12+
@interface DNAssociatedDartObject ()
13+
14+
@property (nonatomic) NSMutableSet<NSNumber *> *internalDartPorts;
15+
@property (nonatomic) dispatch_queue_t portsQueue;
16+
17+
@end
18+
19+
@implementation DNAssociatedDartObject
20+
21+
- (instancetype)initWithHost:(NSObject *)host
22+
storageKey:(nonnull const void *)storageKey {
23+
self = [super init];
24+
if (self) {
25+
_host = host;
26+
_internalDartPorts = [NSMutableSet set];
27+
_portsQueue = dispatch_queue_create("com.dartnative.associatedobject", DISPATCH_QUEUE_CONCURRENT);
28+
objc_setAssociatedObject(host, storageKey, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
29+
}
30+
return self;
31+
}
32+
33+
+ (instancetype)attachHost:(NSObject *)host
34+
dartPort:(Dart_Port)dartPort
35+
storageKey:(nonnull const void *)storageKey {
36+
if (!host) {
37+
return nil;
38+
}
39+
__kindof DNAssociatedDartObject *object = [self objectForHost:host
40+
storageKey:storageKey];
41+
if (!object && (!objc_isTaggedPointer((__bridge const void *)(host)) ||
42+
[host isKindOfClass:NSClassFromString(@"__NSMallocBlock")])) {
43+
object = [[self alloc] initWithHost:host storageKey:storageKey];
44+
}
45+
[object addDartPort:dartPort];
46+
return object;
47+
}
48+
49+
+ (instancetype)objectForHost:(NSObject *)host
50+
storageKey:(nonnull const void *)storageKey {
51+
return objc_getAssociatedObject(host, storageKey);
52+
}
53+
54+
- (NSSet<NSNumber *> *)dartPorts {
55+
__block NSSet<NSNumber *> *temp;
56+
dispatch_sync(self.portsQueue, ^{
57+
temp = [self.internalDartPorts copy];
58+
});
59+
return temp;
60+
}
61+
62+
- (void)addDartPort:(Dart_Port)port {
63+
dispatch_barrier_async(self.portsQueue, ^{
64+
[self.internalDartPorts addObject:@(port)];
65+
});
66+
}
67+
68+
- (void)removeDartPort:(Dart_Port)port {
69+
dispatch_barrier_async(self.portsQueue, ^{
70+
[self.internalDartPorts removeObject:@(port)];
71+
});
72+
}
73+
74+
@end

dart_native/ios/Classes/DNBlockWrapper.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#import "DNFFIHelper.h"
1111
#import "DNInvocation.h"
1212
#import <objc/runtime.h>
13-
#import "NSThread+DartNative.h"
1413
#import "DNPointerWrapper.h"
1514
#import "native_runtime.h"
1615
#import "DNError.h"
@@ -382,9 +381,10 @@ static void DNFFIBlockClosureFunc(ffi_cif *cif, void *ret, void **args, void *us
382381
}
383382
retObjectAddr = (int64_t)*(void **)retAddr;
384383
DNHandleReturnValue(ret, wrapper, invocation);
385-
[wrapper.thread dn_performBlock:^{
386-
NSThread.currentThread.threadDictionary[@(retObjectAddr)] = nil;
387-
}];
384+
const char *type = wrapper.typeEncodings[0];
385+
if (type == native_type_object || type == native_type_block) {
386+
native_release_object((__bridge id)*(void **)retAddr);
387+
}
388388
}
389389

390390

dart_native/ios/Classes/DNMacro.h

+6
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@
1414
#define DN_EXTERN extern __attribute__((visibility("default"))) __attribute((used))
1515
#endif
1616

17+
#ifdef __cplusplus
18+
#define NATIVE_TYPE_EXTERN extern "C"
19+
#else
20+
#define NATIVE_TYPE_EXTERN extern
21+
#endif
22+
1723
#endif /* DNMacro_h */

dart_native/ios/Classes/DNMethodIMP.h

-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ typedef void (*NativeMethodCallback)(void *_Nullable *_Null_unspecified args,
2020

2121
@property (nonatomic, readonly) NativeMethodCallback callback;
2222
@property (nonatomic, getter=hasStret, readonly) BOOL stret;
23-
// Pairs of dart port and function block. Methods can be registed on multi-isolates.
24-
@property (nonatomic, readonly) NSSet<NSNumber *> *dartPorts;
2523

2624
- (instancetype)initWithTypeEncoding:(const char *)typeEncodings
2725
callback:(NativeMethodCallback)callback
2826
error:(NSError **)error;
2927
- (IMP)imp;
30-
- (void)addDartPort:(Dart_Port)port;
3128

3229
@end
3330

0 commit comments

Comments
 (0)