Skip to content

Commit

Permalink
Skip the entire Apple system logging configuration if os-log isn't av…
Browse files Browse the repository at this point in the history
…ailable.
  • Loading branch information
freakboy3742 committed Dec 22, 2024
1 parent f81a68e commit 0a689b3
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# include <mach-o/loader.h>
// The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
// tvOS 10.0, and watchOS 3.0;
# if defined(TARGET_OS_IPHONE) && TARGET_IOS_IPHONE
# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
# define HAS_APPLE_SYSTEM_LOG 1
# elif defined(TARGET_OS_OSX) && TARGET_OS_OSX
# if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
Expand Down Expand Up @@ -94,7 +94,7 @@ static PyStatus init_sys_streams(PyThreadState *tstate);
#ifdef __ANDROID__
static PyStatus init_android_streams(PyThreadState *tstate);
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
static PyStatus init_apple_streams(PyThreadState *tstate);
#endif
static void wait_for_thread_shutdown(PyThreadState *tstate);
Expand Down Expand Up @@ -1279,7 +1279,7 @@ init_interp_main(PyThreadState *tstate)
return status;
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
if (config->use_system_logger) {
status = init_apple_streams(tstate);
if (_PyStatus_EXCEPTION(status)) {
Expand Down Expand Up @@ -2963,7 +2963,7 @@ init_android_streams(PyThreadState *tstate)

#endif // __ANDROID__

#if defined(__APPLE__)
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG

static PyObject *
apple_log_write_impl(PyObject *self, PyObject *args)
Expand All @@ -2974,14 +2974,9 @@ apple_log_write_impl(PyObject *self, PyObject *args)
return NULL;
}

// Call the underlying Apple logging API. The os_log unified logging APIs
// were introduced in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0;
// this call is a no-op on older versions.
#if HAS_APPLE_SYSTEM_LOG
// Pass the user-provided text through explicit %s formatting
// to avoid % literals being interpreted as a formatting directive.
os_log_with_type(OS_LOG_DEFAULT, logtype, "%s", text);
#endif
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -3016,7 +3011,6 @@ init_apple_streams(PyThreadState *tstate)
if (result == NULL) {
goto error;
}

goto done;

error:
Expand All @@ -3030,7 +3024,7 @@ init_apple_streams(PyThreadState *tstate)
return status;
}

#endif // __APPLE__
#endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG


static void
Expand Down

0 comments on commit 0a689b3

Please sign in to comment.