4646
4747#if defined(__APPLE__ )
4848# include <AvailabilityMacros.h>
49+ # include <TargetConditionals.h>
4950# include <mach-o/loader.h>
50- # include <os/log.h>
51+ // The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
52+ // tvOS 10.0, and watchOS 3.0;
53+ # if defined(TARGET_OS_IPHONE ) && TARGET_OS_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
66+ # include <os/log.h>
67+ # endif
5168#endif
5269
5370#ifdef HAVE_SIGNAL_H
@@ -77,7 +94,7 @@ static PyStatus init_sys_streams(PyThreadState *tstate);
7794#ifdef __ANDROID__
7895static PyStatus init_android_streams (PyThreadState * tstate );
7996#endif
80- #if defined(__APPLE__ )
97+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
8198static PyStatus init_apple_streams (PyThreadState * tstate );
8299#endif
83100static void wait_for_thread_shutdown (PyThreadState * tstate );
@@ -1262,7 +1279,7 @@ init_interp_main(PyThreadState *tstate)
12621279 return status ;
12631280 }
12641281#endif
1265- #if defined(__APPLE__ )
1282+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
12661283 if (config -> use_system_logger ) {
12671284 status = init_apple_streams (tstate );
12681285 if (_PyStatus_EXCEPTION (status )) {
@@ -2946,7 +2963,7 @@ init_android_streams(PyThreadState *tstate)
29462963
29472964#endif // __ANDROID__
29482965
2949- #if defined(__APPLE__ )
2966+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
29502967
29512968static PyObject *
29522969apple_log_write_impl (PyObject * self , PyObject * args )
@@ -2957,14 +2974,9 @@ apple_log_write_impl(PyObject *self, PyObject *args)
29572974 return NULL ;
29582975 }
29592976
2960- // Call the underlying Apple logging API. The os_log unified logging APIs
2961- // were introduced in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0;
2962- // this call is a no-op on older versions.
2963- #if TARGET_OS_IPHONE || (TARGET_OS_OSX && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 )
29642977 // Pass the user-provided text through explicit %s formatting
29652978 // to avoid % literals being interpreted as a formatting directive.
29662979 os_log_with_type (OS_LOG_DEFAULT , logtype , "%s" , text );
2967- #endif
29682980 Py_RETURN_NONE ;
29692981}
29702982
@@ -2999,7 +3011,6 @@ init_apple_streams(PyThreadState *tstate)
29993011 if (result == NULL ) {
30003012 goto error ;
30013013 }
3002-
30033014 goto done ;
30043015
30053016error :
@@ -3013,7 +3024,7 @@ init_apple_streams(PyThreadState *tstate)
30133024 return status ;
30143025}
30153026
3016- #endif // __APPLE__
3027+ #endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
30173028
30183029
30193030static void
0 commit comments