Skip to content

Commit 0522a0a

Browse files
committed
fix: change address to sequence on block.
1 parent 4af5cae commit 0522a0a

File tree

15 files changed

+64
-44
lines changed

15 files changed

+64
-44
lines changed

dart_native/example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ EXTERNAL SOURCES:
2323

2424
SPEC CHECKSUMS:
2525
CocoaLumberjack: e8955b9d337ac307103b0a34fd141c32f27e53c5
26-
dart_native: e10848b23206739fc16a2455f41847418a8ceb3d
26+
dart_native: ba4adc85a5cf6faafbfa7de2252397388d9480da
2727
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
2828

2929
PODFILE CHECKSUM: f10e42e188a012076f9d5e111f499229a501832a
3030

31-
COCOAPODS: 1.9.1
31+
COCOAPODS: 1.10.0

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,10 @@
248248
inputPaths = (
249249
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
250250
"${PODS_ROOT}/../Flutter/Flutter.framework",
251-
"${PODS_ROOT}/../.symlinks/plugins/dart_native/ios/DartNative.framework",
252251
);
253252
name = "[CP] Embed Pods Frameworks";
254253
outputPaths = (
255254
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
256-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DartNative.framework",
257255
);
258256
runOnlyForDeploymentPostprocessing = 0;
259257
shellPath = /bin/sh;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
ReferencedContainer = "container:Runner.xcodeproj">
6060
</BuildableReference>
6161
</BuildableProductRunnable>
62+
<AdditionalOptions>
63+
<AdditionalOption
64+
key = "NSZombieEnabled"
65+
value = "YES"
66+
isEnabled = "YES">
67+
</AdditionalOption>
68+
</AdditionalOptions>
6269
</LaunchAction>
6370
<ProfileAction
6471
buildConfiguration = "Profile"

dart_native/example/ios/Runner/RuntimeStub.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ - (void)fooStructDelegate:(id<SampleDelegate>)delegate {
257257
}
258258

259259
- (NSString *)fooNSString:(NSString *)str {
260-
DDLogInfo(@"%s arg: %@", __FUNCTION__, str);
260+
// DDLogInfo(@"%s arg: %@", __FUNCTION__, str);
261261
return @"test nsstring";
262262
}
263263

dart_native/example/lib/ios/ios_main.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:dart_native_example/ios/delegatestub.dart';
22
import 'package:dart_native_example/ios/runtimeson.dart';
3+
import 'package:dart_native_example/ios/runtimestub.dart';
34
import 'package:dart_native_example/ios/unit_test.dart';
45
import 'package:flutter/material.dart';
56
import 'dart:async';
@@ -23,24 +24,23 @@ class _IOSAppState extends State<IOSApp> {
2324
Future<void> initPlatformState() async {
2425
RuntimeSon stub = RuntimeSon();
2526
DelegateStub delegate = DelegateStub();
26-
testIOS(stub, delegate);
27+
// testIOS(stub, delegate);
2728
// Benchmark
2829
String testString =
2930
'This is a long string: sdlfdksjflksndhiofuu2893873(*(%¥#@)*&……¥撒肥料开发时傅雷家书那份会计师东方丽景三等奖';
3031
int time = DateTime.now().millisecondsSinceEpoch;
3132

32-
for (var i = 0; i < 10000; i++) {
33-
String _ = await platform.invokeMethod('fooNSString:', testString);
34-
}
33+
// for (var i = 0; i < 10000; i++) {
34+
// String _ = await platform.invokeMethod('fooNSString:', testString);
35+
// }
3536

3637
print(
3738
"Flutter Channel Cost: ${DateTime.now().millisecondsSinceEpoch - time}");
3839
time = DateTime.now().millisecondsSinceEpoch;
39-
40-
for (var i = 0; i < 10000; i++) {
40+
var count = 0;
41+
for (count = 0; count < 10000; count++) {
4142
// String _ = stub.fooNSString(testString);
4243
String a = await stub.fooNSStringAsync(testString);
43-
print(a);
4444
}
4545

4646
print("DartNative Cost: ${DateTime.now().millisecondsSinceEpoch - time}");

dart_native/example/lib/ios/runtimestub.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,8 @@ class RuntimeStub extends NSObject {
249249
return NSString.fromPointer(result).raw;
250250
}
251251

252-
Future<String> fooNSStringAsync(String str) async {
253-
return performAsync(SEL('fooNSString:'),
254-
args: [str], onQueue: DispatchQueue.global())
255-
.then((value) {
252+
Future<dynamic> fooNSStringAsync(String str) async {
253+
return performAsync(SEL('fooNSString:'), args: [str]).then((value) {
256254
return NSString.fromPointer(value.pointer).raw;
257255
});
258256
}

dart_native/ios/Classes/DNBlockWrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ NS_ASSUME_NONNULL_BEGIN
1313
DN_EXTERN
1414
const char *DNBlockTypeEncodeString(id blockObj);
1515

16-
typedef void (*NativeBlockCallback)(void *_Nullable *_Null_unspecified args, void *ret, int numberOfArguments, BOOL stret);
16+
typedef void (*NativeBlockCallback)(void *_Nullable *_Null_unspecified args, void *ret, int numberOfArguments, BOOL stret, int64_t seq);
1717

1818
@interface DNBlockWrapper : NSObject
1919

2020
@property (nonatomic, readonly) const char *_Nonnull *_Nonnull typeEncodings;
2121
@property (nonatomic, readonly) NativeBlockCallback callback;
2222
@property (nonatomic, getter=hasStret, readonly) BOOL stret;
23+
@property (nonatomic, readonly) int64_t sequence;
2324

2425
- (intptr_t)blockAddress;
2526

dart_native/ios/Classes/DNBlockWrapper.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "DNPointerWrapper.h"
1515
#import "native_runtime.h"
1616
#import "DNError.h"
17+
#import <stdatomic.h>
1718

1819
#if !__has_feature(objc_arc)
1920
#error
@@ -120,6 +121,8 @@ @interface DNBlockWrapper ()
120121

121122
@implementation DNBlockWrapper
122123

124+
static atomic_uint_fast64_t _seq = 0;
125+
123126
- (instancetype)initWithTypeString:(char *)typeString
124127
callback:(NativeBlockCallback)callback
125128
error:(out NSError **)error {
@@ -132,6 +135,8 @@ - (instancetype)initWithTypeString:(char *)typeString
132135
_callback = callback;
133136
_thread = NSThread.currentThread;
134137
[self initBlockWithError:error];
138+
atomic_fetch_add(&_seq, 1);
139+
_sequence = _seq;
135140
}
136141
}
137142
return self;
@@ -141,7 +146,7 @@ - (void)dealloc {
141146
ffi_closure_free(_closure);
142147
free(_descriptor);
143148
free(_typeEncodings);
144-
NotifyDeallocToDart(_blockAddress);
149+
NotifyDeallocToDart(_sequence);
145150
}
146151

147152
- (void)initBlockWithError:(out NSError **)error {
@@ -358,7 +363,11 @@ static void DNFFIBlockClosureFunc(ffi_cif *cif, void *ret, void **args, void *us
358363
int64_t retAddr = (int64_t)(invocation.realRetValue);
359364

360365
if (wrapper.thread == NSThread.currentThread) {
361-
wrapper.callback(args, ret, (int)numberOfArguments, wrapper.hasStret);
366+
wrapper.callback(args,
367+
ret,
368+
(int)numberOfArguments,
369+
wrapper.hasStret,
370+
wrapper.sequence);
362371
} else {
363372
[invocation retainArguments];
364373
NotifyBlockInvokeToDart(invocation, wrapper, (int)numberOfArguments);

dart_native/ios/Classes/native_runtime.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@
151151
};
152152

153153
if (queue != NULL) {
154-
// Return nil immediately.
154+
// Retain arguments and return nil immediately.
155+
[invocation retainArguments];
155156
dispatch_async(queue, ^{
156157
[invocation invoke];
157158
if (callback) {
@@ -465,7 +466,8 @@ void NotifyBlockInvokeToDart(DNInvocation *invocation,
465466
callback(invocation.realArgs,
466467
invocation.realRetValue,
467468
numberOfArguments,
468-
wrapper.hasStret);
469+
wrapper.hasStret,
470+
wrapper.sequence);
469471
if (sema) {
470472
dispatch_semaphore_signal(sema);
471473
}

dart_native/ios/dart_native.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Write native code using Dart. This package liberates you from native code and lo
1515
s.source = { :path => '.' }
1616

1717
# Debug
18-
# s.source_files = 'Classes/**/*', 'libffi/*.h', 'common/**/*'
19-
# s.vendored_libraries = 'libffi/libffi.a'
18+
s.source_files = 'Classes/**/*', 'libffi/*.h', 'common/**/*'
19+
s.vendored_libraries = 'libffi/libffi.a'
2020

2121
# Release
22-
s.source_files = 'Classes/DartNativePlugin.*'
23-
s.vendored_frameworks = 'DartNative.framework'
22+
# s.source_files = 'Classes/DartNativePlugin.*'
23+
# s.vendored_frameworks = 'DartNative.framework'
2424

2525
s.public_header_files = 'Classes/DartNativePlugin.h'
2626
s.dependency 'Flutter'

0 commit comments

Comments
 (0)