Skip to content

Commit f6cbd84

Browse files
authored
Update future swig file preprocessor logic (#934)
* Log additional info * Update future swig file * More updates * Update future.i * Revert "Log additional info" This reverts commit 9bded62. * Update future.i * Update firestore.i * Avoid duplicate future void definitions * Update firestore.i
1 parent fc5a712 commit f6cbd84

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

app/src/swig/app.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ static firebase::AppOptions* AppOptionsLoadFromJsonConfig(const char* config) {
351351

352352
%SWIG_FUTURE(FutureString, string, internal,
353353
std::string, FirebaseException) // Future<std::string>
354+
#ifndef USE_FIRESTORE_FUTURE_VOID
354355
%SWIG_FUTURE(FutureVoid, void, internal, void, FirebaseException)
356+
#endif // USE_FIRESTORE_FUTURE_VOID
355357
%SWIG_FUTURE(FutureBool, bool, internal, bool, FirebaseException) // Future<bool>
356358

357359
// Internal

app/src/swig/future.i

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ namespace firebase {
5353
%include "app/src/swig/null_check_this.i"
5454
%include "app/src/swig/serial_dispose.i"
5555

56-
// This is defined so that it's possible to conditionally generate code that is
57-
// aware of type void. This allows us to different code for the void type as
58-
// required by "%extend Future<CTYPE>::result" below.
59-
%ignore TYPE_void;
60-
#define TYPE_void 1
61-
6256
// The Future implementation is assembled in a series of three macros,
6357
// The HEADER, the GET_TASK implementation, and the FOOTER. This componentized
6458
// approach allows for custom GET_TASK implementations for various SDKs
@@ -110,10 +104,8 @@ namespace firebase {
110104
// 4) The user's callback executes.
111105

112106

113-
// Detect when the CTYPE is void by checking "TYPE_" + CTYPE, which yields:
114-
// TYPE_void. TYPE_void is only defined for "void" which allows this macro
115-
// mostly to be used but with some specializations for void.
116-
#ifdef TYPE_## %mangle(CTYPE)
107+
// void is a special type since it isn't a real returnable type.
108+
#if "CTYPE"=="void"
117109

118110
%typemap(cstype, out="System.Threading.Tasks.Task")
119111
firebase::Future<CTYPE> "CSNAME";
@@ -136,7 +128,7 @@ namespace firebase {
136128
return CSNAME.GetTask(new CSNAME(future, true));
137129
}
138130

139-
#endif // TYPE_## %mangle(CTYPE)
131+
#endif // "CTYPE"=="void"
140132

141133
// Replace the default Dispose() method to delete the callback data if
142134
// allocated.
@@ -181,15 +173,15 @@ namespace firebase {
181173
%define %SWIG_FUTURE_GET_TASK(CSNAME, CSTYPE, CTYPE, EXTYPE)
182174
// Helper for csout typemap to convert futures into tasks.
183175
// This would be internal, but we need to share it accross assemblies.
184-
#ifdef TYPE_## %mangle(CTYPE)
176+
#if "CTYPE"=="void"
185177
static public System.Threading.Tasks.Task GetTask(CSNAME fu) {
186178
System.Threading.Tasks.TaskCompletionSource<int> tcs =
187179
new System.Threading.Tasks.TaskCompletionSource<int>();
188180
#else
189181
static public System.Threading.Tasks.Task<CSTYPE> GetTask(CSNAME fu) {
190182
System.Threading.Tasks.TaskCompletionSource<CSTYPE> tcs =
191183
new System.Threading.Tasks.TaskCompletionSource<CSTYPE>();
192-
#endif // TYPE_## %mangle(CTYPE)
184+
#endif // "CTYPE"=="void"
193185

194186
// Check if an exception has occurred previously and propagate it if it has.
195187
// This has to be done before accessing the future because the future object
@@ -223,11 +215,11 @@ namespace firebase {
223215
tcs.SetException(new EXTYPE(error, fu.error_message()));
224216
} else {
225217
// Success!
226-
#ifdef TYPE_## %mangle(CTYPE)
218+
#if "CTYPE"=="void"
227219
tcs.SetResult(0);
228220
#else
229221
tcs.SetResult(fu.GetResult());
230-
#endif // TYPE_## %mangle(CTYPE)
222+
#endif // "CTYPE"=="void"
231223
}
232224
}
233225
} catch (System.Exception e) {
@@ -402,10 +394,8 @@ namespace firebase {
402394
delete reinterpret_cast<CSNAME##CallbackData*>(data);
403395
}
404396

405-
// Detect when the CTYPE is void by checking "TYPE_" + CTYPE, which yields:
406-
// TYPE_void. TYPE_void is only defined for "void" which allows the result()
407-
// method to only be generated for non-void types.
408-
#ifndef TYPE_## %mangle(CTYPE)
397+
// Only generate the return logic for non-void types.
398+
#if "CTYPE"!="void"
409399

410400
// This method copies the value return by Future::result() so that it's
411401
// possible to marshal the return value to C#.
@@ -417,7 +407,7 @@ namespace firebase {
417407
return *$self->result();
418408
}
419409

420-
#endif // !TYPE_void
410+
#endif // "CTYPE"!="void"
421411
}
422412

423413
} // namespace firebase

firestore/src/swig/firestore.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
// processing meant for `public` methods doesn't get applied.
6868
%csmethodmodifiers firebase::firestore::Firestore::GetInstance "internal";
6969

70+
// Override the default FutureVoid with a version that throws FirestoreException.
71+
// Do this before app.i, since that will define FutureVoid, and newer versions
72+
// of swig only use the first definition of templates.
73+
#define USE_FIRESTORE_FUTURE_VOID 1
74+
7075
%import "app/src/swig/app.i"
7176
%import "firestore/src/swig/proxy_helpers.i"
7277
%include "app/src/swig/init_result.i"

0 commit comments

Comments
 (0)