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

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Oct 30, 2023
1 parent f299b24 commit 6aaf857
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions lib/src/code_generator/func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,44 @@ class Func extends LookUpBinding {
functionType.getCType(w, writeArgumentNames: false);
final dartType = _exposedFunctionTypealias?.getFfiDartType(w) ??
functionType.getFfiDartType(w, writeArgumentNames: false);
final needsWrapper = !functionType.sameDartAndFfiDartType;
final needsWrapper = !functionType.sameDartAndFfiDartType && !isInternal;

final isLeafString = isLeaf ? 'isLeaf:true' : '';
final funcVarName = w.wrapperLevelUniqueNamer.makeUnique('_$name');
final ffiReturnType = functionType.returnType.getFfiDartType(w);
final dartReturnType = functionType.returnType.getDartType(w);
final ffiArgDeclString = functionType.dartTypeParameters
.map((p) => '${p.type.getFfiDartType(w)} ${p.name},\n')
.join('');

String dartArgDeclString = functionType.dartTypeParameters
.map((p) => '${p.type.getDartType(w)} ${p.name},\n')
.join('');
late final String dartReturnType;
late final String dartArgDeclString;
late final String funcImplCall;
if (needsWrapper) {
dartArgDeclString = '${w.className} lib, $dartArgDeclString';
dartReturnType = functionType.returnType.getDartType(w);
dartArgDeclString = functionType.dartTypeParameters
.map((p) => '${p.type.getDartType(w)} ${p.name},\n')
.join('');

final argString = functionType.dartTypeParameters
.map((p) =>
'${p.type.convertDartTypeToFfiDartType(w, p.name, objCRetain: false)},\n')
.join('');
funcImplCall =
functionType.returnType.convertFfiDartTypeToDartType(
w,
'$funcVarName($argString)',
'this',
objCRetain: true,
);
} else {
dartReturnType = ffiReturnType;
dartArgDeclString = ffiArgDeclString;
final argString = functionType.dartTypeParameters
.map((p) => '${p.name},\n')
.join('');
funcImplCall = '$funcVarName($argString)';
}

final wrappedArgString = functionType.dartTypeParameters
.map((p) =>
'${p.type.convertDartTypeToFfiDartType(w, p.name, objCRetain: false)},\n')
.join('');
final wrappedFuncCall =
functionType.returnType.convertFfiDartTypeToDartType(
w,
'$funcVarName($wrappedArgString)',
'lib',
objCRetain: true,
);

if (ffiNativeConfig.enabled) {
final assetString = ffiNativeConfig.asset != null
? ", asset: '${ffiNativeConfig.asset}'"
Expand All @@ -148,7 +157,7 @@ external $ffiReturnType $nativeFuncName($ffiArgDeclString);
''');
if (needsWrapper) {
s.write('''
$dartReturnType $enclosingFuncName($dartArgDeclString) => $wrappedFuncCall;
$dartReturnType $enclosingFuncName($dartArgDeclString) => $funcImplCall;
''');
}
Expand All @@ -158,7 +167,7 @@ $dartReturnType $enclosingFuncName($dartArgDeclString) => $wrappedFuncCall;
// Write enclosing function.
s.write('''
$dartReturnType $enclosingFuncName($dartArgDeclString) {
return $wrappedFuncCall;
return $funcImplCall;
}
''');
Expand Down

0 comments on commit 6aaf857

Please sign in to comment.