Skip to content

Commit a016382

Browse files
committed
[3.9] 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 8f3f426 commit a016382

File tree

8 files changed

+19
-49
lines changed

8 files changed

+19
-49
lines changed

Doc/c-api/init_config.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -666,17 +666,6 @@ PyConfig
666666
667667
If greater than 0, use :ref:`environment variables <using-on-envvars>`.
668668
669-
.. c:member:: int use_system_logger
670-
671-
If non-zero, ``stdout`` and ``stderr`` will be redirected to the system
672-
log.
673-
674-
Only available on macOS 10.12 and later, and on iOS.
675-
676-
Default: ``0`` (don't use system log).
677-
678-
.. versionadded:: 3.13.2
679-
680669
.. c:member:: int user_site_directory
681670
682671
If non-zero, add user site directory to :data:`sys.path`.

Include/cpython/initconfig.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,6 @@ typedef struct {
362362
363363
See PEP 552 "Deterministic pycs" for more details. */
364364
wchar_t *check_hash_pycs_mode;
365-
#ifdef __APPLE__
366-
int use_system_logger;
367-
#endif
368365

369366
/* --- Path configuration inputs ------------ */
370367

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
@@ -435,8 +435,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
435435
CONFIG_COMPAT.update({
436436
'legacy_windows_stdio': 0,
437437
})
438-
if support.is_apple:
439-
CONFIG_COMPAT['use_system_logger'] = False
440438

441439
CONFIG_PYTHON = dict(CONFIG_COMPAT,
442440
_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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,6 @@ _PyConfig_InitCompatConfig(PyConfig *config)
652652
config->legacy_windows_stdio = -1;
653653
#endif
654654
config->_use_peg_parser = 1;
655-
#ifdef __APPLE__
656-
config->use_system_logger = 0;
657-
#endif
658655
}
659656

660657
/* Excluded from public struct PyConfig for backporting reasons. */
@@ -684,9 +681,6 @@ config_init_defaults(PyConfig *config)
684681
#ifdef MS_WINDOWS
685682
config->legacy_windows_stdio = 0;
686683
#endif
687-
#ifdef __APPLE__
688-
config->use_system_logger = 0;
689-
#endif
690684
}
691685

692686

@@ -719,9 +713,6 @@ PyConfig_InitIsolatedConfig(PyConfig *config)
719713
#ifdef MS_WINDOWS
720714
config->legacy_windows_stdio = 0;
721715
#endif
722-
#ifdef __APPLE__
723-
config->use_system_logger = 0;
724-
#endif
725716
}
726717

727718

Python/pylifecycle.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,15 @@
2626
# include <TargetConditionals.h>
2727
# include <mach-o/loader.h>
2828
// The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
29-
// tvOS 10.0, and watchOS 3.0;
29+
// tvOS 10.0, and watchOS 3.0; we enable the use of the system logger
30+
// automatically on non-macOS platforms.
3031
# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
31-
# define HAS_APPLE_SYSTEM_LOG 1
32-
# elif defined(TARGET_OS_OSX) && TARGET_OS_OSX
33-
# if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
34-
# define HAS_APPLE_SYSTEM_LOG 1
35-
# else
36-
# define HAS_APPLE_SYSTEM_LOG 0
37-
# endif
32+
# define USE_APPLE_SYSTEM_LOG 1
3833
# else
39-
# define HAS_APPLE_SYSTEM_LOG 0
34+
# define USE_APPLE_SYSTEM_LOG 0
4035
# endif
4136

42-
# if HAS_APPLE_SYSTEM_LOG
37+
# if USE_APPLE_SYSTEM_LOG
4338
# include <os/log.h>
4439
# endif
4540
#endif
@@ -81,7 +76,7 @@ static PyStatus init_import_site(void);
8176
static PyStatus init_set_builtins_open(void);
8277
static PyStatus init_sys_streams(PyThreadState *tstate);
8378
static void call_py_exitfuncs(PyThreadState *tstate);
84-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
79+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
8580
static PyStatus init_apple_streams(PyThreadState *tstate);
8681
#endif
8782
static void wait_for_thread_shutdown(PyThreadState *tstate);
@@ -1057,12 +1052,10 @@ init_interp_main(PyThreadState *tstate)
10571052
return status;
10581053
}
10591054

1060-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
1061-
if (config->use_system_logger) {
1062-
status = init_apple_streams(tstate);
1063-
if (_PyStatus_EXCEPTION(status)) {
1064-
return status;
1065-
}
1055+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
1056+
status = init_apple_streams(tstate);
1057+
if (_PyStatus_EXCEPTION(status)) {
1058+
return status;
10661059
}
10671060
#endif
10681061

@@ -2095,7 +2088,7 @@ init_sys_streams(PyThreadState *tstate)
20952088
return res;
20962089
}
20972090

2098-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
2091+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
20992092

21002093
static PyObject *
21012094
apple_log_write_impl(PyObject *self, PyObject *args)
@@ -2156,7 +2149,7 @@ init_apple_streams(PyThreadState *tstate)
21562149
return status;
21572150
}
21582151

2159-
#endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
2152+
#endif // __APPLE__ && USE_APPLE_SYSTEM_LOG
21602153

21612154

21622155
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)