Skip to content

Commit

Permalink
[unimodules][ios] Fix bool variable representation (#4862)
Browse files Browse the repository at this point in the history
# Why

Resolve #4656

# How

BOOL type in objective-c can be represented by `bool` or `signed char` (according to [objc.h](https://opensource.apple.com/source/objc4/objc4-706/runtime/objc.h.auto.html)). 
We only check if BOOL variables are represented as a `bool`.  

# Test Plan

Test-suits passed on iPhone 5 and 8 simulator.
Also, you can check https://snack.expo.io/@lukaszkosmaty/[sqlite]-ios-fails-to-execute-%22create-table%22 (in particular, it works on iPhone 5).
  • Loading branch information
lukmccall authored and tsapeta committed Jul 9, 2019
1 parent ed54644 commit 38197ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -27,7 +27,8 @@ This is the log of notable changes to the Expo client that are developer-facing.

- fixed `BarCodeScanner` blocking UI when defining custom `barCodeTypes` on iOS by [@sjchmiela](https://github.com/sjchmiela)
- fixed picking images over 2000px on Android by [@bbarthec](https://github.com/bbarthec) ([#4731](https://github.com/expo/expo/pull/4731))
- fixed `Calendar.getEventsAsync` crashing if `calendarId` is SQL keyword by [@lukmccall](https://github.com/lukmccall) ([#4836](https://github.com/expo/expo/pull/4836))
- fixed `Calendar.getEventsAsync` crashing if `calendarId` is SQL keyword by [@lukmccall](https://github.com/lukmccall) ([#4836](https://github.com/expo/expo/pull/4836))
- fixed `BOOL` interpretation on 32-bit iOS devices by [@lukmccall](https://github.com/lukmccall) ([#4862](https://github.com/expo/expo/pull/4862))

## 33.0.0

Expand Down
10 changes: 10 additions & 0 deletions packages/@unimodules/core/ios/UMCore/UMExportedModule.m
Expand Up @@ -149,12 +149,22 @@ - (void)callExportedMethod:(NSString *)methodName withArguments:(NSArray *)argum
if (obj != [NSNull null]) {
[invocation setArgument:&obj atIndex:(2 + idx)];
}

// According to objc.h, the BOOL type can be represented by `bool` or `signed char` so
// getArgumentTypeAtIndex can return _C_BOOL (when `bool`) or _C_CHR (when `signed char`)
#if OBJC_BOOL_IS_BOOL
if ([methodSignature getArgumentTypeAtIndex:(2 + idx)][0] == _C_BOOL) {
// We need this intermediary variable, see
// https://stackoverflow.com/questions/11061166/pointer-to-bool-in-objective-c
BOOL value = [obj boolValue];
[invocation setArgument:&value atIndex:(2 + idx)];
}
#else // BOOL is represented by `signed char`
if ([methodSignature getArgumentTypeAtIndex:(2 + idx)][0] == _C_CHR){
BOOL value = [obj charValue];
[invocation setArgument:&value atIndex:(2 + idx)];
}
#endif
}];
[invocation setArgument:&resolve atIndex:(2 + [arguments count])];
[invocation setArgument:&reject atIndex:([arguments count] + 2 + 1)];
Expand Down

0 comments on commit 38197ed

Please sign in to comment.