Skip to content

Commit f81a68e

Browse files
committed
More affordances for older macOS SDKs.
1 parent 4887907 commit f81a68e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Python/pylifecycle.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,23 @@
4646

4747
#if defined(__APPLE__)
4848
# include <AvailabilityMacros.h>
49+
# include <TargetConditionals.h>
4950
# include <mach-o/loader.h>
5051
// The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
5152
// tvOS 10.0, and watchOS 3.0;
52-
# if TARGET_OS_IPHONE || (TARGET_OS_OSX && defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
53+
# if defined(TARGET_OS_IPHONE) && TARGET_IOS_IPHONE
54+
# define HAS_APPLE_SYSTEM_LOG 1
55+
# elif defined(TARGET_OS_OSX) && TARGET_OS_OSX
56+
# if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
57+
# define HAS_APPLE_SYSTEM_LOG 1
58+
# else
59+
# define HAS_APPLE_SYSTEM_LOG 0
60+
# endif
61+
# else
62+
# define HAS_APPLE_SYSTEM_LOG 0
63+
# endif
64+
65+
# if HAS_APPLE_SYSTEM_LOG
5366
# include <os/log.h>
5467
# endif
5568
#endif
@@ -2964,7 +2977,7 @@ apple_log_write_impl(PyObject *self, PyObject *args)
29642977
// Call the underlying Apple logging API. The os_log unified logging APIs
29652978
// were introduced in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0;
29662979
// this call is a no-op on older versions.
2967-
#if TARGET_OS_IPHONE || (TARGET_OS_OSX && defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
2980+
#if HAS_APPLE_SYSTEM_LOG
29682981
// Pass the user-provided text through explicit %s formatting
29692982
// to avoid % literals being interpreted as a formatting directive.
29702983
os_log_with_type(OS_LOG_DEFAULT, logtype, "%s", text);

0 commit comments

Comments
 (0)