20
20
#include < utility>
21
21
#include < vector>
22
22
23
- #include " Firestore/core/interfaceForSwift /api/Pipeline .h"
24
- #include " Firestore/core/interfaceForSwift /api/PipelineResult .h"
23
+ #include " Firestore/core/src /api/pipeline .h"
24
+ #include " Firestore/core/src /api/pipeline_result .h"
25
25
#include " Firestore/core/src/core/event_listener.h"
26
26
#include " Firestore/core/src/util/error_apple.h"
27
27
#include " Firestore/core/src/util/statusor.h"
34
34
35
35
@implementation FIRCallbackWrapper
36
36
37
- // In public Swift documentation for integrating Swift and C++, using raw pointers in C++ is
38
- // generally considered unsafe. However, during an experiment where the result was passed as a value
39
- // instead of a pointer, a double free error occurred. This issue could not be traced effectively
40
- // because the implementation resides within the Swift-C++ transition layer. In this specific use
41
- // case, the C++ OnEvent() scope is destroyed after the Swift callback has been destroyed. Due to
42
- // this ordering, using a raw pointer is a safe workaround for now.
43
37
+ (PipelineSnapshotListener)wrapPipelineCallback : (std::shared_ptr<api::Firestore>)firestore
44
- completion : (void (^)(CppPipelineResult *_Nullable result,
38
+ completion : (void (^)(PipelineResultVector result,
45
39
NSError *_Nullable error))completion {
46
- class Converter : public EventListener <CppPipelineResult > {
40
+ class Converter : public EventListener <std::vector<PipelineResult> > {
47
41
public:
48
42
explicit Converter (std::shared_ptr<api::Firestore> firestore, PipelineBlock completion)
49
43
: firestore_(firestore), completion_(completion) {
50
44
}
51
45
52
- void OnEvent (StatusOr<CppPipelineResult > maybe_snapshot) override {
46
+ void OnEvent (StatusOr<std::vector<PipelineResult> > maybe_snapshot) override {
53
47
if (maybe_snapshot.ok ()) {
54
- completion_ (&maybe_snapshot.ValueOrDie (), nullptr );
48
+ completion_ (
49
+ std::initializer_list<PipelineResult>{PipelineResult::GetTestResult (firestore_)},
50
+ nullptr );
55
51
} else {
56
- completion_ (nullptr , MakeNSError (maybe_snapshot.status ()));
52
+ completion_ (std::initializer_list<PipelineResult>{} , MakeNSError (maybe_snapshot.status ()));
57
53
}
58
54
}
59
55
@@ -62,7 +58,7 @@ void OnEvent(StatusOr<CppPipelineResult> maybe_snapshot) override {
62
58
PipelineBlock completion_;
63
59
};
64
60
65
- return std::make_shared <Converter>(firestore, completion);
61
+ return absl::make_unique <Converter>(firestore, completion);
66
62
}
67
63
68
64
@end
0 commit comments