Browse Source

macOS stdlib and version calculation changes.

woollybah 6 năm trước cách đây
mục cha
commit
fe631025ef

+ 4 - 0
CHANGELOG

@@ -1,3 +1,7 @@
+## [3.28] - 2018-10-03
+### Changed
+ - macOS version calculation.
+ - macOS stdlib changes.
 ## [3.27] - 2018-09-06
 ## [3.27] - 2018-09-06
 ### Fixed
 ### Fixed
  - Fixed conditional compiler processing.
  - Fixed conditional compiler processing.

+ 10 - 3
bmk_config.bmx

@@ -10,7 +10,7 @@ Import brl.map
 
 
 Import "stringbuffer_core.bmx"
 Import "stringbuffer_core.bmx"
 
 
-Const BMK_VERSION:String = "3.27"
+Const BMK_VERSION:String = "3.28"
 
 
 Const ALL_SRC_EXTS$="bmx;i;c;m;h;cpp;cxx;mm;hpp;hxx;s;cc;asm;S"
 Const ALL_SRC_EXTS$="bmx;i;c;m;h;cpp;cxx;mm;hpp;hxx;s;cc;asm;S"
 
 
@@ -66,8 +66,15 @@ Global app_type$
 
 
 ?MacOS
 ?MacOS
 
 
-'cfg_platform="macos"
-Gestalt Asc("s")Shl 24|Asc("y")Shl 16|Asc("s")Shl 8|Asc("v"),macos_version
+Function GetVersion:Int()
+	Local major:Int
+	Local minor:Int
+	Local patch:Int
+	NSOSVersion(major, minor, patch)
+	Return major Shl 8 | minor Shl 4 | patch
+End Function
+
+macos_version = GetVersion()
 
 
 ?MacOsPPC
 ?MacOsPPC
 If is_pid_native(0) opt_arch="ppc" Else opt_arch="x86"
 If is_pid_native(0) opt_arch="ppc" Else opt_arch="x86"

+ 6 - 0
bmk_cores_macos.bmx

@@ -1,5 +1,11 @@
 SuperStrict
 SuperStrict
 
 
+?Not bmxng
+Import "macos/*.h"
+Import "macos/macos.m"
+Import "macos/NSProcessInfo_PECocoaBackports.m"
+?
+
 Extern
 Extern
 ?x64
 ?x64
 	Function sysctlbyname:Int(name:Byte Ptr, count:Int Ptr, size:Long Ptr, a:Byte Ptr, b:Int)
 	Function sysctlbyname:Int(name:Byte Ptr, count:Int Ptr, size:Long Ptr, a:Byte Ptr, b:Int)

+ 83 - 0
macos/NSProcessInfo_PECocoaBackports.h

@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014 Petroules Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <TargetConditionals.h>
+#import <AvailabilityMacros.h>
+
+#if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || \
+(defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
+#import <Availability.h>
+#endif
+
+#import "PECocoaBackportsGlobal.h"
+
+#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+#if __IPHONE_OS_VERSION_MAX_ALLOWED < 80000
+#ifndef DECLARE_OPERATING_SYSTEM_VERSION
+#define DECLARE_OPERATING_SYSTEM_VERSION 1
+#endif
+#endif
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
+#ifndef LOAD_OPERATING_SYSTEM_VERSION
+#define LOAD_OPERATING_SYSTEM_VERSION 1
+#endif
+#endif
+#elif defined(TARGET_OS_MAC) && TARGET_OS_MAC
+#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000
+#ifndef DECLARE_OPERATING_SYSTEM_VERSION
+#define DECLARE_OPERATING_SYSTEM_VERSION 1
+#endif
+#endif
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
+#ifndef LOAD_OPERATING_SYSTEM_VERSION
+#define LOAD_OPERATING_SYSTEM_VERSION 1
+#endif
+#endif
+#endif
+
+#ifndef DECLARE_OPERATING_SYSTEM_VERSION
+#define DECLARE_OPERATING_SYSTEM_VERSION 0
+#endif
+
+#ifndef LOAD_OPERATING_SYSTEM_VERSION
+#define LOAD_OPERATING_SYSTEM_VERSION 0
+#endif
+
+#if DECLARE_OPERATING_SYSTEM_VERSION
+typedef struct {
+    NSInteger majorVersion;
+    NSInteger minorVersion;
+    NSInteger patchVersion;
+} NSOperatingSystemVersion;
+#endif
+
+@interface NSProcessInfo (PECocoaBackports)
+
+#if DECLARE_OPERATING_SYSTEM_VERSION
+- (NSOperatingSystemVersion)operatingSystemVersion NS_AVAILABLE(10_5, 2_0);
+- (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version NS_AVAILABLE(10_5, 2_0);
+#endif
+
+@end

+ 102 - 0
macos/NSProcessInfo_PECocoaBackports.m

@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2014 Petroules Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "NSProcessInfo+PECocoaBackports.h"
+
+#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+#import <UIKit/UIKit.h>
+#elif defined(TARGET_OS_MAC) && TARGET_OS_MAC
+#import <CoreServices/CoreServices.h>
+#endif
+
+@interface NSProcessInfo (PECocoaBackportsPrivate)
+
+#if LOAD_OPERATING_SYSTEM_VERSION
+- (NSOperatingSystemVersion)PECocoaBackports_operatingSystemVersion;
+- (BOOL)PECocoaBackports_isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version;
+#endif
+
+@end
+
+@implementation NSProcessInfo (PECocoaBackportsPrivate)
+
++ (void)load
+{
+#if LOAD_OPERATING_SYSTEM_VERSION
+    // Public API since OS X 10.10 (present since 10.9) and iOS 8.0
+    class_addInstanceMethodIfNecessary([self class],
+                                       NSSelectorFromString(@"operatingSystemVersion"),
+                                       @selector(PECocoaBackports_operatingSystemVersion));
+    
+    // Public API since OS X 10.10 (present since 10.9) and iOS 8.0
+    class_addInstanceMethodIfNecessary([self class],
+                                       NSSelectorFromString(@"isOperatingSystemAtLeastVersion:"),
+                                       @selector(PECocoaBackports_isOperatingSystemAtLeastVersion:));
+#endif
+}
+
+#if LOAD_OPERATING_SYSTEM_VERSION
+- (NSOperatingSystemVersion)PECocoaBackports_operatingSystemVersion
+{
+    NSOperatingSystemVersion v = {0, 0, 0};
+    SInt32 major = 0, minor = 0, patch = 0;
+#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
+    NSArray *parts = [[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."];
+    major = parts.count > 0 ? [[parts objectAtIndex:0] intValue] : 0;
+    minor = parts.count > 1 ? [[parts objectAtIndex:1] intValue] : 0;
+    patch = parts.count > 2 ? [[parts objectAtIndex:2] intValue] : 0;
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+    [pool release];
+#endif
+#elif defined(TARGET_OS_MAC) && TARGET_OS_MAC
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+    if (Gestalt(gestaltSystemVersionMajor, &major) != noErr) return v;
+    if (Gestalt(gestaltSystemVersionMinor, &minor) != noErr) return v;
+    if (Gestalt(gestaltSystemVersionBugFix, &patch) != noErr) return v;
+#pragma clang diagnostic pop
+#endif
+    v.majorVersion = major;
+    v.minorVersion = minor;
+    v.patchVersion = patch;
+    return v;
+}
+
+- (BOOL)PECocoaBackports_isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version
+{
+    const NSOperatingSystemVersion systemVersion = [self operatingSystemVersion];
+    if (systemVersion.majorVersion == version.majorVersion) {
+        if (systemVersion.minorVersion == version.minorVersion) {
+            return systemVersion.patchVersion >= version.patchVersion;
+        }
+        return systemVersion.minorVersion >= version.minorVersion;
+    }
+    return systemVersion.majorVersion >= version.majorVersion;
+}
+#endif
+
+@end

+ 56 - 0
macos/PECocoaBackportsGlobal.h

@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2014 Petroules Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __PECocoaBackportsGlobal__
+#define __PECocoaBackportsGlobal__
+
+#import <objc/runtime.h>
+
+CF_INLINE void class_addInstanceMethodIfNecessary(Class clazz, SEL realSelector, SEL fakeSelector) {
+    if (!class_getInstanceMethod(clazz, realSelector)) {
+        Method method = class_getInstanceMethod(clazz, fakeSelector);
+        if (!class_addMethod(clazz, realSelector, method_getImplementation(method),
+                             method_getTypeEncoding(method))) {
+#if defined(DEBUG) && DEBUG
+            NSLog(@"PECocoaBackports: error adding -[%@ %@] (-[%@ %@])",
+                  NSStringFromClass(clazz), NSStringFromSelector(fakeSelector),
+                  NSStringFromClass(clazz), NSStringFromSelector(realSelector));
+#endif
+        } else {
+#if defined(DEBUG) && DEBUG
+            NSLog(@"PECocoaBackports: added -[%@ %@] (-[%@ %@])",
+                  NSStringFromClass(clazz), NSStringFromSelector(fakeSelector),
+                  NSStringFromClass(clazz), NSStringFromSelector(realSelector));
+#endif
+        }
+    } else {
+#if defined(DEBUG) && DEBUG
+        NSLog(@"PECocoaBackports: skipped adding -[%@ %@] (-[%@ %@]); already exists",
+              NSStringFromClass(clazz), NSStringFromSelector(fakeSelector),
+              NSStringFromClass(clazz), NSStringFromSelector(realSelector));
+#endif
+    }
+}
+
+#endif // __PECocoaBackportsGlobal__

+ 7 - 0
macos/macos.m

@@ -0,0 +1,7 @@
+
+void NSOSVersion(int * major, int * minor, int * patch) {
+	NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
+	*major = version.majorVersion;
+	*minor = version.minorVersion;
+	*patch = version.patchVersion;
+}