@@ -36,8 +36,25 @@ extern void _PyIO_Fini(void);
3636
3737#if defined(__APPLE__ )
3838# include <AvailabilityMacros.h>
39+ # include <TargetConditionals.h>
3940# include <mach-o/loader.h>
40- # include <os/log.h>
41+ // The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
42+ // tvOS 10.0, and watchOS 3.0;
43+ # if defined(TARGET_OS_IPHONE ) && TARGET_OS_IPHONE
44+ # define HAS_APPLE_SYSTEM_LOG 1
45+ # elif defined(TARGET_OS_OSX ) && TARGET_OS_OSX
46+ # if defined(MAC_OS_X_VERSION_10_12 ) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
47+ # define HAS_APPLE_SYSTEM_LOG 1
48+ # else
49+ # define HAS_APPLE_SYSTEM_LOG 0
50+ # endif
51+ # else
52+ # define HAS_APPLE_SYSTEM_LOG 0
53+ # endif
54+
55+ # if HAS_APPLE_SYSTEM_LOG
56+ # include <os/log.h>
57+ # endif
4158#endif
4259
4360#ifdef HAVE_SIGNAL_H
@@ -74,7 +91,7 @@ static PyStatus add_main_module(PyInterpreterState *interp);
7491static PyStatus init_import_site (void );
7592static PyStatus init_set_builtins_open (void );
7693static PyStatus init_sys_streams (PyThreadState * tstate );
77- #if defined(__APPLE__ )
94+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
7895static PyStatus init_apple_streams (PyThreadState * tstate );
7996#endif
8097static void wait_for_thread_shutdown (PyThreadState * tstate );
@@ -1166,7 +1183,7 @@ init_interp_main(PyThreadState *tstate)
11661183 return status ;
11671184 }
11681185
1169- #if defined(__APPLE__ )
1186+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
11701187 if (config -> use_system_logger ) {
11711188 status = init_apple_streams (tstate );
11721189 if (_PyStatus_EXCEPTION (status )) {
@@ -2499,7 +2516,7 @@ init_sys_streams(PyThreadState *tstate)
24992516 return res ;
25002517}
25012518
2502- #if defined(__APPLE__ )
2519+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
25032520
25042521static PyObject *
25052522apple_log_write_impl (PyObject * self , PyObject * args )
@@ -2510,14 +2527,9 @@ apple_log_write_impl(PyObject *self, PyObject *args)
25102527 return NULL ;
25112528 }
25122529
2513- // Call the underlying Apple logging API. The os_log unified logging APIs
2514- // were introduced in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0;
2515- // this call is a no-op on older versions.
2516- #if TARGET_OS_IPHONE || (TARGET_OS_OSX && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 )
25172530 // Pass the user-provided text through explicit %s formatting
25182531 // to avoid % literals being interpreted as a formatting directive.
25192532 os_log_with_type (OS_LOG_DEFAULT , logtype , "%s" , text );
2520- #endif
25212533 Py_RETURN_NONE ;
25222534}
25232535
@@ -2552,7 +2564,6 @@ init_apple_streams(PyThreadState *tstate)
25522564 if (result == NULL ) {
25532565 goto error ;
25542566 }
2555-
25562567 goto done ;
25572568
25582569error :
@@ -2566,7 +2577,7 @@ init_apple_streams(PyThreadState *tstate)
25662577 return status ;
25672578}
25682579
2569- #endif // __APPLE__
2580+ #endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
25702581
25712582
25722583static void
0 commit comments