Skip to content

Commit 7fea048

Browse files
authored
[ffigen] Fix some subtle AST iteration order bugs (#2669)
1 parent 6fe224f commit 7fea048

26 files changed

+905
-1976
lines changed

pkgs/ffigen/example/objective_c/avf_audio_bindings.dart

Lines changed: 12 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ import 'dart:ffi' as ffi;
1212
import 'package:objective_c/objective_c.dart' as objc;
1313
import 'package:ffi/ffi.dart' as pkg_ffi;
1414

15-
@ffi.Native<
16-
ffi.Pointer<objc.ObjCObject> Function(
17-
ffi.Pointer<objc.ObjCObject>,
18-
ffi.Pointer<ffi.Void>,
19-
)
20-
>()
21-
external ffi.Pointer<objc.ObjCObject> _AVFAudio_protocolTrampoline_1mbt9g9(
22-
ffi.Pointer<objc.ObjCObject> target,
23-
ffi.Pointer<ffi.Void> arg0,
24-
);
25-
2615
final class AudioStreamBasicDescription extends ffi.Struct {
2716
@ffi.Double()
2817
external double mSampleRate;
@@ -641,141 +630,6 @@ final _objc_msgSend_1cwp428 = objc.msgSendPointer
641630
)
642631
>();
643632
late final _sel_alloc = objc.registerName("alloc");
644-
late final _sel_self = objc.registerName("self");
645-
646-
/// Construction methods for `objc.ObjCBlock<ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)>`.
647-
abstract final class ObjCBlock_objcObjCObject_ffiVoid {
648-
/// Returns a block that wraps the given raw block pointer.
649-
static objc.ObjCBlock<
650-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
651-
>
652-
castFromPointer(
653-
ffi.Pointer<objc.ObjCBlockImpl> pointer, {
654-
bool retain = false,
655-
bool release = false,
656-
}) =>
657-
objc.ObjCBlock<
658-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
659-
>(pointer, retain: retain, release: release);
660-
661-
/// Creates a block from a C function pointer.
662-
///
663-
/// This block must be invoked by native code running on the same thread as
664-
/// the isolate that registered it. Invoking the block on the wrong thread
665-
/// will result in a crash.
666-
static objc.ObjCBlock<
667-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
668-
>
669-
fromFunctionPointer(
670-
ffi.Pointer<
671-
ffi.NativeFunction<
672-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void> arg0)
673-
>
674-
>
675-
ptr,
676-
) =>
677-
objc.ObjCBlock<
678-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
679-
>(
680-
objc.newPointerBlock(_fnPtrCallable, ptr.cast()),
681-
retain: false,
682-
release: true,
683-
);
684-
685-
/// Creates a block from a Dart function.
686-
///
687-
/// This block must be invoked by native code running on the same thread as
688-
/// the isolate that registered it. Invoking the block on the wrong thread
689-
/// will result in a crash.
690-
///
691-
/// If `keepIsolateAlive` is true, this block will keep this isolate alive
692-
/// until it is garbage collected by both Dart and ObjC.
693-
static objc.ObjCBlock<
694-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
695-
>
696-
fromFunction(
697-
objc.ObjCObjectBase Function(ffi.Pointer<ffi.Void>) fn, {
698-
bool keepIsolateAlive = true,
699-
}) =>
700-
objc.ObjCBlock<
701-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
702-
>(
703-
objc.newClosureBlock(
704-
_closureCallable,
705-
(ffi.Pointer<ffi.Void> arg0) => fn(arg0).ref.retainAndAutorelease(),
706-
keepIsolateAlive,
707-
),
708-
retain: false,
709-
release: true,
710-
);
711-
712-
static ffi.Pointer<objc.ObjCObject> _fnPtrTrampoline(
713-
ffi.Pointer<objc.ObjCBlockImpl> block,
714-
ffi.Pointer<ffi.Void> arg0,
715-
) => block.ref.target
716-
.cast<
717-
ffi.NativeFunction<
718-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void> arg0)
719-
>
720-
>()
721-
.asFunction<
722-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
723-
>()(arg0);
724-
static ffi.Pointer<ffi.Void> _fnPtrCallable =
725-
ffi.Pointer.fromFunction<
726-
ffi.Pointer<objc.ObjCObject> Function(
727-
ffi.Pointer<objc.ObjCBlockImpl>,
728-
ffi.Pointer<ffi.Void>,
729-
)
730-
>(_fnPtrTrampoline)
731-
.cast();
732-
static ffi.Pointer<objc.ObjCObject> _closureTrampoline(
733-
ffi.Pointer<objc.ObjCBlockImpl> block,
734-
ffi.Pointer<ffi.Void> arg0,
735-
) =>
736-
(objc.getBlockClosure(block)
737-
as ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>))(
738-
arg0,
739-
);
740-
static ffi.Pointer<ffi.Void> _closureCallable =
741-
ffi.Pointer.fromFunction<
742-
ffi.Pointer<objc.ObjCObject> Function(
743-
ffi.Pointer<objc.ObjCBlockImpl>,
744-
ffi.Pointer<ffi.Void>,
745-
)
746-
>(_closureTrampoline)
747-
.cast();
748-
}
749-
750-
/// Call operator for `objc.ObjCBlock<ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)>`.
751-
extension ObjCBlock_objcObjCObject_ffiVoid$CallExtension
752-
on
753-
objc.ObjCBlock<
754-
ffi.Pointer<objc.ObjCObject> Function(ffi.Pointer<ffi.Void>)
755-
> {
756-
objc.ObjCObjectBase call(ffi.Pointer<ffi.Void> arg0) => objc.ObjCObjectBase(
757-
ref.pointer.ref.invoke
758-
.cast<
759-
ffi.NativeFunction<
760-
ffi.Pointer<objc.ObjCObject> Function(
761-
ffi.Pointer<objc.ObjCBlockImpl> block,
762-
ffi.Pointer<ffi.Void> arg0,
763-
)
764-
>
765-
>()
766-
.asFunction<
767-
ffi.Pointer<objc.ObjCObject> Function(
768-
ffi.Pointer<objc.ObjCBlockImpl>,
769-
ffi.Pointer<ffi.Void>,
770-
)
771-
>()(ref.pointer, arg0),
772-
retain: true,
773-
release: true,
774-
);
775-
}
776-
777-
late final _sel_retain = objc.registerName("retain");
778-
late final _sel_autorelease = objc.registerName("autorelease");
779633

780634
/// AVAudioPlayer
781635
class AVAudioPlayer extends objc.NSObject {
@@ -818,11 +672,11 @@ class AVAudioPlayer extends objc.NSObject {
818672
}
819673

820674
/// allocWithZone:
821-
static AVAudioPlayer allocWithZone(ffi.Pointer<objc.NSZone> zone) {
675+
static AVAudioPlayer allocWithZone(ffi.Pointer<objc.NSZone> zone$1) {
822676
final $ret = _objc_msgSend_1cwp428(
823677
_class_AVAudioPlayer,
824678
_sel_allocWithZone_,
825-
zone,
679+
zone$1,
826680
);
827681
return AVAudioPlayer.castFromPointer($ret, retain: false, release: true);
828682
}
@@ -838,12 +692,6 @@ class AVAudioPlayer extends objc.NSObject {
838692
}
839693

840694
extension AVAudioPlayer$Methods on AVAudioPlayer {
841-
/// autorelease
842-
AVAudioPlayer autorelease() {
843-
final $ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_autorelease);
844-
return AVAudioPlayer.castFromPointer($ret, retain: true, release: true);
845-
}
846-
847695
/// averagePowerForChannel:
848696
double averagePowerForChannel(int channelNumber) {
849697
objc.checkOsVersionInternal(
@@ -996,7 +844,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
996844

997845
/// initWithContentsOfURL:error:
998846
AVAudioPlayer? initWithContentsOfURL(
999-
objc.NSURL url, {
847+
objc.NSURL url$1, {
1000848
required ffi.Pointer<ffi.Pointer<objc.ObjCObject>> error,
1001849
}) {
1002850
objc.checkOsVersionInternal(
@@ -1007,7 +855,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
1007855
final $ret = _objc_msgSend_1lhpu4m(
1008856
this.ref.retainAndReturnPointer(),
1009857
_sel_initWithContentsOfURL_error_,
1010-
url.ref.pointer,
858+
url$1.ref.pointer,
1011859
error,
1012860
);
1013861
return $ret.address == 0
@@ -1017,7 +865,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
1017865

1018866
/// initWithContentsOfURL:fileTypeHint:error:
1019867
AVAudioPlayer? initWithContentsOfURL$1(
1020-
objc.NSURL url, {
868+
objc.NSURL url$1, {
1021869
objc.NSString? fileTypeHint,
1022870
required ffi.Pointer<ffi.Pointer<objc.ObjCObject>> error,
1023871
}) {
@@ -1029,7 +877,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
1029877
final $ret = _objc_msgSend_1pnyuds(
1030878
this.ref.retainAndReturnPointer(),
1031879
_sel_initWithContentsOfURL_fileTypeHint_error_,
1032-
url.ref.pointer,
880+
url$1.ref.pointer,
1033881
fileTypeHint?.ref.pointer ?? ffi.nullptr,
1034882
error,
1035883
);
@@ -1040,7 +888,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
1040888

1041889
/// initWithData:error:
1042890
AVAudioPlayer? initWithData(
1043-
objc.NSData data, {
891+
objc.NSData data$1, {
1044892
required ffi.Pointer<ffi.Pointer<objc.ObjCObject>> error,
1045893
}) {
1046894
objc.checkOsVersionInternal(
@@ -1051,7 +899,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
1051899
final $ret = _objc_msgSend_1lhpu4m(
1052900
this.ref.retainAndReturnPointer(),
1053901
_sel_initWithData_error_,
1054-
data.ref.pointer,
902+
data$1.ref.pointer,
1055903
error,
1056904
);
1057905
return $ret.address == 0
@@ -1061,7 +909,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
1061909

1062910
/// initWithData:fileTypeHint:error:
1063911
AVAudioPlayer? initWithData$1(
1064-
objc.NSData data, {
912+
objc.NSData data$1, {
1065913
objc.NSString? fileTypeHint,
1066914
required ffi.Pointer<ffi.Pointer<objc.ObjCObject>> error,
1067915
}) {
@@ -1073,7 +921,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
1073921
final $ret = _objc_msgSend_1pnyuds(
1074922
this.ref.retainAndReturnPointer(),
1075923
_sel_initWithData_fileTypeHint_error_,
1076-
data.ref.pointer,
924+
data$1.ref.pointer,
1077925
fileTypeHint?.ref.pointer ?? ffi.nullptr,
1078926
error,
1079927
);
@@ -1224,18 +1072,6 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
12241072
: _objc_msgSend_2cgrxl(this.ref.pointer, _sel_rate);
12251073
}
12261074

1227-
/// retain
1228-
AVAudioPlayer retain() {
1229-
final $ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_retain);
1230-
return AVAudioPlayer.castFromPointer($ret, retain: true, release: true);
1231-
}
1232-
1233-
/// self
1234-
AVAudioPlayer self() {
1235-
final $ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_self);
1236-
return AVAudioPlayer.castFromPointer($ret, retain: true, release: true);
1237-
}
1238-
12391075
/// setChannelAssignments:
12401076
set channelAssignments(objc.NSArray? value) {
12411077
objc.checkOsVersionInternal(
@@ -1363,7 +1199,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
13631199
}
13641200

13651201
/// setVolume:fadeDuration:
1366-
void setVolume(double volume, {required double fadeDuration}) {
1202+
void setVolume(double volume$1, {required double fadeDuration}) {
13671203
objc.checkOsVersionInternal(
13681204
'AVAudioPlayer.setVolume:fadeDuration:',
13691205
iOS: (false, (10, 0, 0)),
@@ -1372,7 +1208,7 @@ extension AVAudioPlayer$Methods on AVAudioPlayer {
13721208
_objc_msgSend_1p4uk9e(
13731209
this.ref.pointer,
13741210
_sel_setVolume_fadeDuration_,
1375-
volume,
1211+
volume$1,
13761212
fadeDuration,
13771213
);
13781214
}

pkgs/ffigen/example/objective_c/avf_audio_bindings.dart.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@
5050

5151

5252
Protocol* _AVFAudio_AVAudioPlayerDelegate(void) { return @protocol(AVAudioPlayerDelegate); }
53-
54-
typedef id (^_ProtocolTrampoline)(void * sel);
55-
__attribute__((visibility("default"))) __attribute__((used))
56-
id _AVFAudio_protocolTrampoline_1mbt9g9(id target, void * sel) {
57-
return ((_ProtocolTrampoline)((id (*)(id, SEL, SEL))objc_msgSend)(target, @selector(getDOBJCDartProtocolMethodForSelector:), sel))(sel);
58-
}
5953
#undef BLOCKING_BLOCK_IMPL
6054

6155
#pragma clang diagnostic pop

0 commit comments

Comments
 (0)