Skip to content

Commit aab880d

Browse files
committed
Merge branch 'feature/invoke_perf_opt' into develop
* feature/invoke_perf_opt: fix git clone fix: travis ci fix: demo crash fix: debug run scheme feat: retType support string fix: memory issue for type encoding feat: return string for nsstring by default. fix: memory leak feat: optimized 1/3 cost.
2 parents c226842 + 534960e commit aab880d

29 files changed

+439
-222
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- unzip -qq gradle-3.5-bin.zip
2828
- export GRADLE_HOME=$PWD/gradle-3.5
2929
- export PATH=$GRADLE_HOME/bin:$PATH
30-
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
30+
- git clone https://github.com/flutter/flutter.git --depth 1 --branch 1.22.6
3131
- export PATH=./flutter/bin:$PATH
3232
- flutter doctor
3333
- yes | sdkmanager "platforms;android-29"
@@ -44,7 +44,7 @@ jobs:
4444
- brew install libimobiledevice
4545
- brew install ideviceinstaller
4646
- brew install ios-deploy
47-
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
47+
- git clone https://github.com/flutter/flutter.git --depth 1 --branch 1.22.6
4848
- export PATH=./flutter/bin:$PATH
4949
- flutter doctor
5050
script:

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
97C146EC1CF9000F007C117D /* Resources */,
160160
9705A1C41CF9048500538489 /* Embed Frameworks */,
161161
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
162-
3199B333F30D678225AFDF10 /* [CP] Embed Pods Frameworks */,
162+
EBECF6F1409D0440724C4F6A /* [CP] Embed Pods Frameworks */,
163163
);
164164
buildRules = (
165165
);
@@ -240,53 +240,53 @@
240240
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
241241
showEnvVarsInLog = 0;
242242
};
243-
3199B333F30D678225AFDF10 /* [CP] Embed Pods Frameworks */ = {
243+
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
244244
isa = PBXShellScriptBuildPhase;
245245
buildActionMask = 2147483647;
246246
files = (
247247
);
248248
inputPaths = (
249-
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
250-
"${PODS_ROOT}/../Flutter/Flutter.framework",
251-
"${PODS_ROOT}/../.symlinks/plugins/dart_native/ios/DartNative.framework",
252249
);
253-
name = "[CP] Embed Pods Frameworks";
250+
name = "Thin Binary";
254251
outputPaths = (
255-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
256-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DartNative.framework",
257252
);
258253
runOnlyForDeploymentPostprocessing = 0;
259254
shellPath = /bin/sh;
260-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
261-
showEnvVarsInLog = 0;
255+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n";
262256
};
263-
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
257+
9740EEB61CF901F6004384FC /* Run Script */ = {
264258
isa = PBXShellScriptBuildPhase;
265259
buildActionMask = 2147483647;
266260
files = (
267261
);
268262
inputPaths = (
269263
);
270-
name = "Thin Binary";
264+
name = "Run Script";
271265
outputPaths = (
272266
);
273267
runOnlyForDeploymentPostprocessing = 0;
274268
shellPath = /bin/sh;
275-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n";
269+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n";
276270
};
277-
9740EEB61CF901F6004384FC /* Run Script */ = {
271+
EBECF6F1409D0440724C4F6A /* [CP] Embed Pods Frameworks */ = {
278272
isa = PBXShellScriptBuildPhase;
279273
buildActionMask = 2147483647;
280274
files = (
281275
);
282276
inputPaths = (
277+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
278+
"${PODS_ROOT}/../Flutter/Flutter.framework",
279+
"${PODS_ROOT}/../.symlinks/plugins/dart_native/ios/DartNative.framework",
283280
);
284-
name = "Run Script";
281+
name = "[CP] Embed Pods Frameworks";
285282
outputPaths = (
283+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
284+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DartNative.framework",
286285
);
287286
runOnlyForDeploymentPostprocessing = 0;
288287
shellPath = /bin/sh;
289-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n";
288+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
289+
showEnvVarsInLog = 0;
290290
};
291291
/* End PBXShellScriptBuildPhase section */
292292

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
buildConfiguration = "Debug"
4444
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4545
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
46+
enableASanStackUseAfterReturn = "YES"
4647
launchStyle = "0"
4748
useCustomWorkingDirectory = "NO"
4849
ignoresPersistentStateOnLaunch = "NO"
@@ -59,13 +60,6 @@
5960
ReferencedContainer = "container:Runner.xcodeproj">
6061
</BuildableReference>
6162
</BuildableProductRunnable>
62-
<AdditionalOptions>
63-
<AdditionalOption
64-
key = "NSZombieEnabled"
65-
value = "YES"
66-
isEnabled = "YES">
67-
</AdditionalOption>
68-
</AdditionalOptions>
6963
</LaunchAction>
7064
<ProfileAction
7165
buildConfiguration = "Profile"

dart_native/example/lib/ios/ios_main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class _IOSAppState extends State<IOSApp> {
2323
Future<void> initPlatformState() async {
2424
RuntimeSon stub = RuntimeSon();
2525
DelegateStub delegate = DelegateStub();
26-
testIOS(stub, delegate);
2726
// Benchmark
2827
String testString =
2928
'This is a long string: sdlfdksjflksndhiofuu2893873(*(%¥#@)*&……¥撒肥料开发时傅雷家书那份会计师东方丽景三等奖';
@@ -41,6 +40,7 @@ class _IOSAppState extends State<IOSApp> {
4140
}
4241

4342
print("DartNative Cost: ${DateTime.now().millisecondsSinceEpoch - time}");
43+
testIOS(stub, delegate);
4444
}
4545

4646
@override

dart_native/example/lib/ios/runtimestub.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,7 @@ class RuntimeStub extends NSObject {
244244
}
245245

246246
String fooNSString(String str) {
247-
Pointer<Void> result =
248-
perform(SEL('fooNSString:'), args: [str], decodeRetVal: false);
249-
return NSString.fromPointer(result).raw;
247+
return perform(SEL('fooNSString:'), args: [str]);
250248
}
251249

252250
Future<dynamic> fooNSStringAsync(String str) async {
@@ -257,9 +255,7 @@ class RuntimeStub extends NSObject {
257255

258256
String fooNSMutableString(String str) {
259257
NSMutableString _str = NSMutableString(str);
260-
Pointer<Void> result =
261-
perform(SEL('fooNSMutableString:'), args: [_str], decodeRetVal: false);
262-
return NSMutableString.fromPointer(result).raw;
258+
return perform(SEL('fooNSMutableString:'), args: [_str]);
263259
}
264260

265261
bool fooWithError(NSObjectRef<NSError> error) {

dart_native/example/lib/ios/unit_test.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,32 +148,21 @@ testIOS(RuntimeStub stub, DelegateStub delegate) {
148148
Class('NSThread')
149149
.performAsync(SEL('currentThread'), onQueue: DispatchQueue.global())
150150
.then((currentThread) {
151-
NSObject description = currentThread.perform(SEL('description'));
152-
String threadResult = NSString.fromPointer(description.pointer).raw;
153-
print('currentThread: $threadResult');
151+
print('currentThread: ${currentThread.description}');
154152
});
155153

156154
NSNotificationCenter.defaultCenter.addObserver(
157155
delegate, delegate.handleNotification, 'SampleDartNotification', nil);
158156

159-
Isolate.spawn(_checkTimer, stub.pointer.address);
160-
Isolate.spawn(_checkTimer1, stub.pointer.address);
157+
Isolate.spawn(_checkTimer, 'isolate0');
158+
Isolate.spawn(_checkTimer, 'isolate1');
161159
}
162160

163-
void _checkTimer(int addr) async {
164-
RuntimeStub stub = RuntimeStub.fromPointer(Pointer.fromAddress(addr));
161+
void _checkTimer(String isolateID) async {
162+
RuntimeStub stub = RuntimeStub();
165163
Timer.periodic(new Duration(seconds: 1), (Timer t) {
166164
stub.fooCompletion(() {
167-
print('hello completion block on another isolate!');
168-
});
169-
});
170-
}
171-
172-
void _checkTimer1(int addr) async {
173-
RuntimeStub stub = RuntimeStub.fromPointer(Pointer.fromAddress(addr));
174-
Timer.periodic(new Duration(seconds: 1), (Timer t) {
175-
stub.fooCompletion(() {
176-
print('hello completion block on third isolate!');
165+
print('hello completion block on $isolateID!');
177166
});
178167
});
179168
}

dart_native/ios/Classes/DNBlockWrapper.m

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ - (void)dealloc {
148148
ffi_closure_free(_closure);
149149
free(_descriptor);
150150
for (int i = 0; i < _numberOfArguments; i++) {
151-
free((void *)_typeEncodings[i]);
151+
if (*_typeEncodings[i] == '{') {
152+
free((void *)_typeEncodings[i]);
153+
}
152154
}
153155
free(_typeEncodings);
154156
NotifyDeallocToDart(_sequence, _dartPort);
@@ -280,16 +282,7 @@ - (NSString *)_parseTypeNames:(NSString *)typeNames
280282
}
281283
}
282284

283-
const char *encodeSource = encode.UTF8String;
284-
size_t typeLength = strlen(encodeSource) + 1;
285-
size_t size = sizeof(char) * typeLength;
286-
char *typePtr = (char *)malloc(size);
287-
if (typePtr == NULL) {
288-
DN_ERROR(DNCreateTypeEncodingError, @"malloc for type encoding fail: %s", encodeSource);
289-
return nil;
290-
}
291-
strlcpy(typePtr, encode.UTF8String, typeLength);
292-
self.typeEncodings[i] = typePtr;
285+
self.typeEncodings[i] = native_type_encoding(encode.UTF8String);
293286

294287
int length = DNTypeLengthWithTypeName(typeStr);
295288

dart_native/ios/Classes/DNInvocation.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ - (void *)_copyPointer:(void **)pointer encode:(const char *)encode key:(NSNumbe
157157
}
158158

159159
- (void)_retainPointer:(void **)pointer encode:(const char *)encode key:(NSNumber *)key {
160-
if (!pointer) {
160+
if (!pointer || *encode == 'v') {
161161
return;
162162
}
163163
void *p = *pointer;

dart_native/ios/Classes/DNMethodIMP.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ static void DNFFIIMPClosureFunc(ffi_cif *cif, void *ret, void **args, void *user
167167
args[i + indexOffset] = temp;
168168
}
169169
}
170-
171-
const char **types = native_types_encoding(methodIMP.typeEncoding, NULL, 0);
170+
int typesCount = 0;
171+
const char **types = native_types_encoding(methodIMP.typeEncoding, &typesCount, 0);
172172
if (!types) {
173173
return;
174174
}
@@ -190,6 +190,11 @@ static void DNFFIIMPClosureFunc(ffi_cif *cif, void *ret, void **args, void *user
190190
[invocation retainArguments];
191191
NotifyMethodPerformToDart(invocation, methodIMP, numberOfArguments, types);
192192
}
193+
for (int i = 0; i < typesCount; i++) {
194+
if (*types[i] == '{') {
195+
free((void *)types[i]);
196+
}
197+
}
193198
free(types);
194199
retObjectAddr = (int64_t)*(void **)retAddr;
195200
DNHandleReturnValue(ret, methodIMP, invocation);

dart_native/ios/Classes/DNObjectDealloc.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ + (void)attachHost:(NSObject *)host
5454
}
5555
}
5656

57+
static int64_t fuxk;
58+
5759
- (instancetype)initWithHost:(NSObject *)host
5860
dartPort:(Dart_Port)dartPort {
5961
self = [super init];

0 commit comments

Comments
 (0)