Skip to content

Commit 6007e43

Browse files
committed
[3.11] pythongh-130940: Remove PyConfig.use_system_logger (python#131129)
Removes ``PyConfig.use_system_logger``, resolving an ABI incompatibility introduced in 3.13.2. Changes the default behavior of iOS to *always* direct stdout/stderr to the system log.
1 parent ba74cc2 commit 6007e43

9 files changed

Lines changed: 19 additions & 54 deletions

File tree

Doc/c-api/init_config.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,17 +1174,6 @@ PyConfig
11741174
11751175
Default: ``1`` in Python config and ``0`` in isolated config.
11761176
1177-
.. c:member:: int use_system_logger
1178-
1179-
If non-zero, ``stdout`` and ``stderr`` will be redirected to the system
1180-
log.
1181-
1182-
Only available on macOS 10.12 and later, and on iOS.
1183-
1184-
Default: ``0`` (don't use system log).
1185-
1186-
.. versionadded:: 3.13.2
1187-
11881177
.. c:member:: int user_site_directory
11891178
11901179
If non-zero, add the user site directory to :data:`sys.path`.

Doc/using/ios.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ To add Python to an iOS Xcode project:
296296
* Buffered stdio (:c:member:`PyConfig.buffered_stdio`) is *disabled*;
297297
* Writing bytecode (:c:member:`PyConfig.write_bytecode`) is *disabled*;
298298
* Signal handlers (:c:member:`PyConfig.install_signal_handlers`) are *enabled*;
299-
* System logging (:c:member:`PyConfig.use_system_logger`) is *enabled*
300-
(optional, but strongly recommended);
301299
* ``PYTHONHOME`` for the interpreter is configured to point at the
302300
``python`` subfolder of your app's bundle; and
303301
* The ``PYTHONPATH`` for the interpreter includes:

Include/cpython/initconfig.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ typedef struct PyConfig {
177177
wchar_t *check_hash_pycs_mode;
178178
int use_frozen_modules;
179179
int safe_path;
180-
#ifdef __APPLE__
181-
int use_system_logger;
182-
#endif
183180

184181
/* --- Path configuration inputs ------------ */
185182
int pathconfig_warnings;

Lib/test/test_apple.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import unittest
22
from _apple_support import SystemLog
3-
from test.support import is_apple
3+
from test.support import is_apple_mobile
44
from unittest.mock import Mock, call
55

6-
if not is_apple:
7-
raise unittest.SkipTest("Apple-specific")
6+
if not is_apple_mobile:
7+
raise unittest.SkipTest("iOS-specific")
88

99

1010
# Test redirection of stdout and stderr to the Apple system log.

Lib/test/test_embed.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
508508
CONFIG_COMPAT.update({
509509
'legacy_windows_stdio': 0,
510510
})
511-
if support.is_apple:
512-
CONFIG_COMPAT['use_system_logger'] = False
513511

514512
CONFIG_PYTHON = dict(CONFIG_COMPAT,
515513
_config_init=API_PYTHON,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The ``PyConfig.use_system_logger`` attribute, introduced in Python 3.13.2, has
2+
been removed. The introduction of this attribute inadvertently introduced an
3+
ABI breakage on macOS and iOS. The use of the system logger is now enabled
4+
by default on iOS, and disabled by default on macOS.

Python/initconfig.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,6 @@ config_check_consistency(const PyConfig *config)
665665
assert(config->safe_path >= 0);
666666
// config->use_frozen_modules is initialized later
667667
// by _PyConfig_InitImportConfig().
668-
#ifdef __APPLE__
669-
assert(config->use_system_logger >= 0);
670-
#endif
671668
return 1;
672669
}
673670
#endif
@@ -761,9 +758,6 @@ _PyConfig_InitCompatConfig(PyConfig *config)
761758
config->safe_path = 0;
762759
config->_is_python_build = 0;
763760
config->code_debug_ranges = 1;
764-
#ifdef __APPLE__
765-
config->use_system_logger = 0;
766-
#endif
767761
}
768762

769763
/* Excluded from public struct PyConfig for backporting reasons. */
@@ -793,9 +787,6 @@ config_init_defaults(PyConfig *config)
793787
#ifdef MS_WINDOWS
794788
config->legacy_windows_stdio = 0;
795789
#endif
796-
#ifdef __APPLE__
797-
config->use_system_logger = 0;
798-
#endif
799790
}
800791

801792

@@ -829,9 +820,6 @@ PyConfig_InitIsolatedConfig(PyConfig *config)
829820
#ifdef MS_WINDOWS
830821
config->legacy_windows_stdio = 0;
831822
#endif
832-
#ifdef __APPLE__
833-
config->use_system_logger = 0;
834-
#endif
835823
}
836824

837825

Python/pylifecycle.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,15 @@ extern void _PyIO_Fini(void);
3939
# include <TargetConditionals.h>
4040
# include <mach-o/loader.h>
4141
// The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
42-
// tvOS 10.0, and watchOS 3.0;
42+
// tvOS 10.0, and watchOS 3.0; we enable the use of the system logger
43+
// automatically on non-macOS platforms.
4344
# 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
45+
# define USE_APPLE_SYSTEM_LOG 1
5146
# else
52-
# define HAS_APPLE_SYSTEM_LOG 0
47+
# define USE_APPLE_SYSTEM_LOG 0
5348
# endif
5449

55-
# if HAS_APPLE_SYSTEM_LOG
50+
# if USE_APPLE_SYSTEM_LOG
5651
# include <os/log.h>
5752
# endif
5853
#endif
@@ -91,7 +86,7 @@ static PyStatus add_main_module(PyInterpreterState *interp);
9186
static PyStatus init_import_site(void);
9287
static PyStatus init_set_builtins_open(void);
9388
static PyStatus init_sys_streams(PyThreadState *tstate);
94-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
89+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
9590
static PyStatus init_apple_streams(PyThreadState *tstate);
9691
#endif
9792
static void wait_for_thread_shutdown(PyThreadState *tstate);
@@ -1183,12 +1178,10 @@ init_interp_main(PyThreadState *tstate)
11831178
return status;
11841179
}
11851180

1186-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
1187-
if (config->use_system_logger) {
1188-
status = init_apple_streams(tstate);
1189-
if (_PyStatus_EXCEPTION(status)) {
1190-
return status;
1191-
}
1181+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
1182+
status = init_apple_streams(tstate);
1183+
if (_PyStatus_EXCEPTION(status)) {
1184+
return status;
11921185
}
11931186
#endif
11941187

@@ -2516,7 +2509,7 @@ init_sys_streams(PyThreadState *tstate)
25162509
return res;
25172510
}
25182511

2519-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
2512+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
25202513

25212514
static PyObject *
25222515
apple_log_write_impl(PyObject *self, PyObject *args)
@@ -2577,7 +2570,7 @@ init_apple_streams(PyThreadState *tstate)
25772570
return status;
25782571
}
25792572

2580-
#endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
2573+
#endif // __APPLE__ && USE_APPLE_SYSTEM_LOG
25812574

25822575

25832576
static void

iOS/testbed/iOSTestbedTests/iOSTestbedTests.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ - (void)testPython {
5353
// Enforce UTF-8 encoding for stderr, stdout, file-system encoding and locale.
5454
// See https://docs.python.org/3/library/os.html#python-utf-8-mode.
5555
preconfig.utf8_mode = 1;
56-
// Use the system logger for stdout/err
57-
config.use_system_logger = 1;
5856
// Don't buffer stdio. We want output to appears in the log immediately
5957
config.buffered_stdio = 0;
6058
// Don't write bytecode; we can't modify the app bundle

0 commit comments

Comments
 (0)