From 98b04156a90a19ba52a11ae8c3037a0e1d0d484e Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Wed, 12 Mar 2025 11:54:47 +0800 Subject: [PATCH 1/2] Remove PyConfig.use_system_logger. --- Doc/c-api/init_config.rst | 11 ------- Doc/using/ios.rst | 2 -- Include/cpython/initconfig.h | 3 -- Lib/test/test_apple.py | 6 ++-- Lib/test/test_embed.py | 2 -- ...-03-12-11-53-32.gh-issue-130940.81K1Tg.rst | 4 +++ Python/initconfig.c | 15 --------- Python/pylifecycle.c | 31 +++++++------------ iOS/testbed/iOSTestbedTests/iOSTestbedTests.m | 2 -- 9 files changed, 19 insertions(+), 57 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index cd78fe18e35d1c..612aa2aa711253 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -1271,17 +1271,6 @@ PyConfig Default: ``1`` in Python config and ``0`` in isolated config. - .. c:member:: int use_system_logger - - If non-zero, ``stdout`` and ``stderr`` will be redirected to the system - log. - - Only available on macOS 10.12 and later, and on iOS. - - Default: ``0`` (don't use system log). - - .. versionadded:: 3.13.2 - .. c:member:: int user_site_directory If non-zero, add the user site directory to :data:`sys.path`. diff --git a/Doc/using/ios.rst b/Doc/using/ios.rst index aa43f75ec35a6c..dff694941d0aeb 100644 --- a/Doc/using/ios.rst +++ b/Doc/using/ios.rst @@ -296,8 +296,6 @@ To add Python to an iOS Xcode project: * Buffered stdio (:c:member:`PyConfig.buffered_stdio`) is *disabled*; * Writing bytecode (:c:member:`PyConfig.write_bytecode`) is *disabled*; * Signal handlers (:c:member:`PyConfig.install_signal_handlers`) are *enabled*; - * System logging (:c:member:`PyConfig.use_system_logger`) is *enabled* - (optional, but strongly recommended); * ``PYTHONHOME`` for the interpreter is configured to point at the ``python`` subfolder of your app's bundle; and * The ``PYTHONPATH`` for the interpreter includes: diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h index 20f5c9ad9bb9a8..5da5ef9e5431b1 100644 --- a/Include/cpython/initconfig.h +++ b/Include/cpython/initconfig.h @@ -179,9 +179,6 @@ typedef struct PyConfig { int use_frozen_modules; int safe_path; int int_max_str_digits; -#ifdef __APPLE__ - int use_system_logger; -#endif int cpu_count; #ifdef Py_GIL_DISABLED diff --git a/Lib/test/test_apple.py b/Lib/test/test_apple.py index ab5296afad1d3f..f14db75e2f21fd 100644 --- a/Lib/test/test_apple.py +++ b/Lib/test/test_apple.py @@ -1,10 +1,10 @@ import unittest from _apple_support import SystemLog -from test.support import is_apple +from test.support import is_apple_mobile from unittest.mock import Mock, call -if not is_apple: - raise unittest.SkipTest("Apple-specific") +if not is_apple_mobile: + raise unittest.SkipTest("iOS-specific") # Test redirection of stdout and stderr to the Apple system log. diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index ed459794952581..a354f856c8057d 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -627,8 +627,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): CONFIG_COMPAT.update({ 'legacy_windows_stdio': 0, }) - if support.is_apple: - CONFIG_COMPAT['use_system_logger'] = False CONFIG_PYTHON = dict(CONFIG_COMPAT, _config_init=API_PYTHON, diff --git a/Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst b/Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst new file mode 100644 index 00000000000000..b1a36875fb8711 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst @@ -0,0 +1,4 @@ +The ``PyConfig.use_system_logger`` attribute, introduced in Python 3.12.2, has +been removed. The introduction of this attribute inadvertently introduced an +ABI breakage on macOS and iOS. The use of the system logger is now enabled +by default on iOS, and disabled by default on macOS. diff --git a/Python/initconfig.c b/Python/initconfig.c index 9b446eccab9a57..8060a1647c0ebe 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -130,9 +130,6 @@ static const PyConfigSpec PYCONFIG_SPEC[] = { #ifdef Py_DEBUG SPEC(run_presite, WSTR_OPT), #endif -#ifdef __APPLE__ - SPEC(use_system_logger, BOOL), -#endif {NULL, 0, 0}, }; @@ -751,9 +748,6 @@ config_check_consistency(const PyConfig *config) assert(config->cpu_count != 0); // config->use_frozen_modules is initialized later // by _PyConfig_InitImportConfig(). -#ifdef __APPLE__ - assert(config->use_system_logger >= 0); -#endif #ifdef Py_STATS assert(config->_pystats >= 0); #endif @@ -856,9 +850,6 @@ _PyConfig_InitCompatConfig(PyConfig *config) config->_is_python_build = 0; config->code_debug_ranges = 1; config->cpu_count = -1; -#ifdef __APPLE__ - config->use_system_logger = 0; -#endif #ifdef Py_GIL_DISABLED config->enable_gil = _PyConfig_GIL_DEFAULT; #endif @@ -887,9 +878,6 @@ config_init_defaults(PyConfig *config) #ifdef MS_WINDOWS config->legacy_windows_stdio = 0; #endif -#ifdef __APPLE__ - config->use_system_logger = 0; -#endif } @@ -925,9 +913,6 @@ PyConfig_InitIsolatedConfig(PyConfig *config) #ifdef MS_WINDOWS config->legacy_windows_stdio = 0; #endif -#ifdef __APPLE__ - config->use_system_logger = 0; -#endif } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index c96455e65aa3ba..a8852a88f94a37 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -47,20 +47,15 @@ # include # include // The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0, -// tvOS 10.0, and watchOS 3.0; +// tvOS 10.0, and watchOS 3.0; we enable the use of the system logger +// automatically on non-macOS platforms. # 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 -# define HAS_APPLE_SYSTEM_LOG 1 -# else -# define HAS_APPLE_SYSTEM_LOG 0 -# endif +# define USE_APPLE_SYSTEM_LOG 1 # else -# define HAS_APPLE_SYSTEM_LOG 0 +# define USE_APPLE_SYSTEM_LOG 0 # endif -# if HAS_APPLE_SYSTEM_LOG +# if USE_APPLE_SYSTEM_LOG # include # endif #endif @@ -92,7 +87,7 @@ static PyStatus init_sys_streams(PyThreadState *tstate); #ifdef __ANDROID__ static PyStatus init_android_streams(PyThreadState *tstate); #endif -#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG +#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG static PyStatus init_apple_streams(PyThreadState *tstate); #endif static void wait_for_thread_shutdown(PyThreadState *tstate); @@ -1280,12 +1275,10 @@ init_interp_main(PyThreadState *tstate) return status; } #endif -#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG - if (config->use_system_logger) { - status = init_apple_streams(tstate); - if (_PyStatus_EXCEPTION(status)) { - return status; - } +#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG + status = init_apple_streams(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; } #endif @@ -2971,7 +2964,7 @@ init_android_streams(PyThreadState *tstate) #endif // __ANDROID__ -#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG +#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG static PyObject * apple_log_write_impl(PyObject *self, PyObject *args) @@ -3032,7 +3025,7 @@ init_apple_streams(PyThreadState *tstate) return status; } -#endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG +#endif // __APPLE__ && USE_APPLE_SYSTEM_LOG static void diff --git a/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m b/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m index dd6e76f9496fe0..d417b4cd63e2d4 100644 --- a/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m +++ b/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m @@ -53,8 +53,6 @@ - (void)testPython { // Enforce UTF-8 encoding for stderr, stdout, file-system encoding and locale. // See https://docs.python.org/3/library/os.html#python-utf-8-mode. preconfig.utf8_mode = 1; - // Use the system logger for stdout/err - config.use_system_logger = 1; // Don't buffer stdio. We want output to appears in the log immediately config.buffered_stdio = 0; // Don't write bytecode; we can't modify the app bundle From 3c9bb716b3174a97a997280b4f3597bd6d19c985 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Wed, 12 Mar 2025 14:29:11 +0800 Subject: [PATCH 2/2] Correct Python version number reference. --- .../next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst b/Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst index b1a36875fb8711..366c057f5a1c05 100644 --- a/Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst +++ b/Misc/NEWS.d/next/Library/2025-03-12-11-53-32.gh-issue-130940.81K1Tg.rst @@ -1,4 +1,4 @@ -The ``PyConfig.use_system_logger`` attribute, introduced in Python 3.12.2, has +The ``PyConfig.use_system_logger`` attribute, introduced in Python 3.13.2, has been removed. The introduction of this attribute inadvertently introduced an ABI breakage on macOS and iOS. The use of the system logger is now enabled by default on iOS, and disabled by default on macOS.