3535
3636#if defined(__APPLE__ )
3737# include <AvailabilityMacros.h>
38+ # include <TargetConditionals.h>
3839# include <mach-o/loader.h>
39- # include <os/log.h>
40+ // The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
41+ // tvOS 10.0, and watchOS 3.0;
42+ # if defined(TARGET_OS_IPHONE ) && TARGET_OS_IPHONE
43+ # define HAS_APPLE_SYSTEM_LOG 1
44+ # elif defined(TARGET_OS_OSX ) && TARGET_OS_OSX
45+ # if defined(MAC_OS_X_VERSION_10_12 ) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
46+ # define HAS_APPLE_SYSTEM_LOG 1
47+ # else
48+ # define HAS_APPLE_SYSTEM_LOG 0
49+ # endif
50+ # else
51+ # define HAS_APPLE_SYSTEM_LOG 0
52+ # endif
53+
54+ # if HAS_APPLE_SYSTEM_LOG
55+ # include <os/log.h>
56+ # endif
4057#endif
4158
4259#ifdef HAVE_SIGNAL_H
@@ -68,7 +85,7 @@ static PyStatus add_main_module(PyInterpreterState *interp);
6885static PyStatus init_import_site (void );
6986static PyStatus init_set_builtins_open (void );
7087static PyStatus init_sys_streams (PyThreadState * tstate );
71- #if defined(__APPLE__ )
88+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
7289static PyStatus init_apple_streams (PyThreadState * tstate );
7390#endif
7491static void wait_for_thread_shutdown (PyThreadState * tstate );
@@ -1187,7 +1204,7 @@ init_interp_main(PyThreadState *tstate)
11871204 return status ;
11881205 }
11891206
1190- #if defined(__APPLE__ )
1207+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
11911208 if (config -> use_system_logger ) {
11921209 status = init_apple_streams (tstate );
11931210 if (_PyStatus_EXCEPTION (status )) {
@@ -2659,7 +2676,7 @@ init_sys_streams(PyThreadState *tstate)
26592676 return res ;
26602677}
26612678
2662- #if defined(__APPLE__ )
2679+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
26632680
26642681static PyObject *
26652682apple_log_write_impl (PyObject * self , PyObject * args )
@@ -2670,14 +2687,9 @@ apple_log_write_impl(PyObject *self, PyObject *args)
26702687 return NULL ;
26712688 }
26722689
2673- // Call the underlying Apple logging API. The os_log unified logging APIs
2674- // were introduced in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0;
2675- // this call is a no-op on older versions.
2676- #if TARGET_OS_IPHONE || (TARGET_OS_OSX && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 )
26772690 // Pass the user-provided text through explicit %s formatting
26782691 // to avoid % literals being interpreted as a formatting directive.
26792692 os_log_with_type (OS_LOG_DEFAULT , logtype , "%s" , text );
2680- #endif
26812693 Py_RETURN_NONE ;
26822694}
26832695
@@ -2712,7 +2724,6 @@ init_apple_streams(PyThreadState *tstate)
27122724 if (result == NULL ) {
27132725 goto error ;
27142726 }
2715-
27162727 goto done ;
27172728
27182729error :
@@ -2726,7 +2737,7 @@ init_apple_streams(PyThreadState *tstate)
27262737 return status ;
27272738}
27282739
2729- #endif // __APPLE__
2740+ #endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
27302741
27312742
27322743static void
0 commit comments