46
46
47
47
#if defined(__APPLE__ )
48
48
# include <AvailabilityMacros.h>
49
+ # include <TargetConditionals.h>
49
50
# 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
51
68
#endif
52
69
53
70
#ifdef HAVE_SIGNAL_H
@@ -77,7 +94,7 @@ static PyStatus init_sys_streams(PyThreadState *tstate);
77
94
#ifdef __ANDROID__
78
95
static PyStatus init_android_streams (PyThreadState * tstate );
79
96
#endif
80
- #if defined(__APPLE__ )
97
+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
81
98
static PyStatus init_apple_streams (PyThreadState * tstate );
82
99
#endif
83
100
static void wait_for_thread_shutdown (PyThreadState * tstate );
@@ -1262,7 +1279,7 @@ init_interp_main(PyThreadState *tstate)
1262
1279
return status ;
1263
1280
}
1264
1281
#endif
1265
- #if defined(__APPLE__ )
1282
+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
1266
1283
if (config -> use_system_logger ) {
1267
1284
status = init_apple_streams (tstate );
1268
1285
if (_PyStatus_EXCEPTION (status )) {
@@ -2946,7 +2963,7 @@ init_android_streams(PyThreadState *tstate)
2946
2963
2947
2964
#endif // __ANDROID__
2948
2965
2949
- #if defined(__APPLE__ )
2966
+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
2950
2967
2951
2968
static PyObject *
2952
2969
apple_log_write_impl (PyObject * self , PyObject * args )
@@ -2957,14 +2974,9 @@ apple_log_write_impl(PyObject *self, PyObject *args)
2957
2974
return NULL ;
2958
2975
}
2959
2976
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 )
2964
2977
// Pass the user-provided text through explicit %s formatting
2965
2978
// to avoid % literals being interpreted as a formatting directive.
2966
2979
os_log_with_type (OS_LOG_DEFAULT , logtype , "%s" , text );
2967
- #endif
2968
2980
Py_RETURN_NONE ;
2969
2981
}
2970
2982
@@ -2999,7 +3011,6 @@ init_apple_streams(PyThreadState *tstate)
2999
3011
if (result == NULL ) {
3000
3012
goto error ;
3001
3013
}
3002
-
3003
3014
goto done ;
3004
3015
3005
3016
error :
@@ -3013,7 +3024,7 @@ init_apple_streams(PyThreadState *tstate)
3013
3024
return status ;
3014
3025
}
3015
3026
3016
- #endif // __APPLE__
3027
+ #endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
3017
3028
3018
3029
3019
3030
static void
0 commit comments