Skip to content

Commit

Permalink
Use isIosAtLeast instead of @available to support thin runtime checks…
Browse files Browse the repository at this point in the history
… instead of compiletime checks not compatible with iOS < 13
  • Loading branch information
teras committed Jul 7, 2020
1 parent 5e2b936 commit 78ec199
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,15 @@ - (BOOL) isOpaque__
// @property(nonatomic) UIUserInterfaceStyle overrideUserInterfaceStyle;
- (void) setOverrideUserInterfaceStyle___int:(int) overrideUserInterfaceStyle
{
if (@available(iOS 13.0, *)) {
if (isIosAtLeast(13,0)){
[self setOverrideUserInterfaceStyle:overrideUserInterfaceStyle];
}
}

// @property(nonatomic) UIUserInterfaceStyle overrideUserInterfaceStyle;
- (int) overrideUserInterfaceStyle__
{
if (@available(iOS 13.0, *)) {
if (isIosAtLeast(13,0)){
return [self overrideUserInterfaceStyle];
} else {
return 0;
Expand Down
8 changes: 4 additions & 4 deletions cmioslayer/gen/cmioslayer/reverse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13700,8 +13700,8 @@
"nextResponder()": null,
"observeValueForKeyPath(java.lang.String,java.lang.Object,java.util.Map,java.lang.Object)": null,
"overrideUserInterfaceStyle()": {
"reverse": "- (UIUserInterfaceStyle) overrideUserInterfaceStyle\n{\n if (@available(iOS 13.0, *)) {\n return [self overrideUserInterfaceStyle__];\n } else {\n return 0;\n }\n}\n\n",
"super": "- (int) overrideUserInterfaceStyle__\n{\n if (@available(iOS 13.0, *)) {\n return [super overrideUserInterfaceStyle];\n } else {\n return 0;\n }\n}\n\n"
"reverse": "- (UIUserInterfaceStyle) overrideUserInterfaceStyle\n{\n if (isIosAtLeast(13,0)){\n return [self overrideUserInterfaceStyle__];\n } else {\n return 0;\n }\n}\n\n",
"super": "- (int) overrideUserInterfaceStyle__\n{\n if (isIosAtLeast(13,0)){\n return [super overrideUserInterfaceStyle];\n } else {\n return 0;\n }\n}\n\n"
},
"pointInside(crossmobile.ios.coregraphics.CGPoint,crossmobile.ios.uikit.UIEvent)": {
"reverse": "- (BOOL) pointInside:(CGPoint) point withEvent:(UIEvent *) event\n{\n crossmobile_ios_coregraphics_CGPoint* point$conv = [[crossmobile_ios_coregraphics_CGPoint alloc] initWithCGPoint:point];\n BOOL re$ult = [self pointInside___crossmobile_ios_coregraphics_CGPoint_crossmobile_ios_uikit_UIEvent:point$conv :(event ? event : JAVA_NULL)];\n [point$conv release];\n return re$ult;\n}\n\n",
Expand Down Expand Up @@ -13895,8 +13895,8 @@
"super": "- (void) setOpaque___boolean:(BOOL) opaque \n{\n [super setOpaque:opaque];\n}\n\n"
},
"setOverrideUserInterfaceStyle(int)": {
"reverse": "- (void) setOverrideUserInterfaceStyle:(UIUserInterfaceStyle) overrideUserInterfaceStyle\n{\n if (@available(iOS 13.0, *)) {\n [self setOverrideUserInterfaceStyle___int:overrideUserInterfaceStyle];\n }\n}\n\n",
"super": "- (void) setOverrideUserInterfaceStyle___int:(int) overrideUserInterfaceStyle \n{\n if (@available(iOS 13.0, *)) {\n [super setOverrideUserInterfaceStyle:overrideUserInterfaceStyle];\n }\n}\n\n"
"reverse": "- (void) setOverrideUserInterfaceStyle:(UIUserInterfaceStyle) overrideUserInterfaceStyle\n{\n if (isIosAtLeast(13,0)){\n [self setOverrideUserInterfaceStyle___int:overrideUserInterfaceStyle];\n }\n}\n\n",
"super": "- (void) setOverrideUserInterfaceStyle___int:(int) overrideUserInterfaceStyle \n{\n if (isIosAtLeast(13,0)){\n [super setOverrideUserInterfaceStyle:overrideUserInterfaceStyle];\n }\n}\n\n"
},
"setPreservesSuperviewLayoutMargins(boolean)": {
"reverse": "- (void) setPreservesSuperviewLayoutMargins:(BOOL) preservesSuperviewLayoutMargins\n{\n [self setPreservesSuperviewLayoutMargins___boolean:preservesSuperviewLayoutMargins];\n}\n\n",
Expand Down
18 changes: 2 additions & 16 deletions cmioslayer/src/main/objc/cmioslayer/xmlvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,8 @@ extern id JAVA_NULL;
// Same as return_XMLVM_SELECTOR, but also define the actual selector
#define return_XMLVM_SELECTOR(SELECTOR) id __xmlvm_item = [SELECTOR]; return [XMLVM_NIL2NULL(__xmlvm_item) retain] ;

// Set a property and retain it. Usually this is called when a delegate is given as a parameter. This object will automatically be released when this object will be released
#define XMLVM_PROPERTY(PROPERTY,VALUE) XMLVM_PROPERTY_WITHCOMMAND(PROPERTY,VALUE,self.PROPERTY = __retainable)
// Like XMLVM_PROPERTY but specify the exact command to execute to set this property (if any)
#define XMLVM_PROPERTY_WITHCOMMAND(PROPERTY,VALUE,COMMAND) id __retainable=(VALUE==JAVA_NULL)?nil:VALUE; COMMAND; static char PROPERTY_key; objc_setAssociatedObject(self, &PROPERTY_key, __retainable, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

// Under old iPhone simulator there is a bug, in which associations are not supported. This is a workaround, which actually leaves a memory leak, but it doesn't harm (much).
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 40000
#if TARGET_IPHONE_SIMULATOR
#define objc_setAssociatedObject(A,B,ITEM,D) [ITEM retain];
#define OBJC_ASSOCIATION_RETAIN_NONATOMIC 1
#endif
#endif

// This is used to support optional protocol implementation in Java. Declare that an ObjC selector exists ONLY if the JAVA selector exists. CHECK is the current selector being asked.
#define XMLVM_REROUTE(CHECK,OBJC,JAVA) if (sel_isEqual(CHECK, @selector(OBJC))) return [super respondsToSelector:@selector(JAVA)];

// Use this instead of @available since this is a light runtime check instead of compiletime check
int isIosAtLeast(int major, int minor);

// Varargs
#if __LP64__
Expand Down
15 changes: 14 additions & 1 deletion cmioslayer/src/main/objc/cmioslayer/xmlvm.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "java_lang_Class.h"
#import "java_util_List.h"
#import <objc/message.h>
#import <UIKit/UIDevice.h>

id JAVA_NULL;

Expand Down Expand Up @@ -301,8 +302,20 @@ - (void*) toMallocedVarArg

@end

// Vararg versions
// Support selectors based on version
int isIosAtLeast(int req_major, int req_minor) {
static int dev_major = -1;
static int dev_minor = -1;
if (dev_major < 0) {
NSArray<NSString*>* components = [[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."];
dev_major = [[components firstObject] intValue];
dev_minor = [[components objectAtIndex:1] intValue];
}
return dev_major > req_major || (dev_major == req_major && dev_minor >= req_minor);
}


// Vararg versions
void gather_va_args(XMLVMArray* va_array, vartype**params, double** doubles, int va_maxsize) {
int maxvar_size = va_maxsize * MAXVAR_SIZE_MULTIPLIER;
vartype* p = malloc(maxvar_size*sizeof(vartype));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public enum ParamsCommon {
CM_KEYBOARD_SUPPORT("quit:pause:back:menu:home:rotate:multitouch"),
CM_SPLASH_DELAY("1"),

IPHONEOS_DEPLOYMENT_TARGET(SystemDependent.getDeploymentTarget()),

// The following tags are recalculated inside ParameterList
MAIN_CLASS("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ public static Map<String, String> getEnvWithFixedPaths() {
return Collections.singletonMap(key, path);
}

public static String getDeploymentTarget() {
if (IS_MACOSX) {
String[] parts = System.getProperty("os.version", "1.0").split("\\.");
try {
if (parts.length >= 2 && parts[0].equals("10") && Integer.parseInt(parts[1]) <= 13)
return "10.0";
} catch (NumberFormatException ignored) {
}
}
return "13.0";
}

public enum Execs {

JAVA("exe"),
Expand Down

0 comments on commit 78ec199

Please sign in to comment.