Skip to content

Commit d109d70

Browse files
committed
[3.12] 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 fe30c8c commit d109d70

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
@@ -1212,17 +1212,6 @@ PyConfig
12121212
12131213
Default: ``1`` in Python config and ``0`` in isolated config.
12141214
1215-
.. c:member:: int use_system_logger
1216-
1217-
If non-zero, ``stdout`` and ``stderr`` will be redirected to the system
1218-
log.
1219-
1220-
Only available on macOS 10.12 and later, and on iOS.
1221-
1222-
Default: ``0`` (don't use system log).
1223-
1224-
.. versionadded:: 3.13.2
1225-
12261215
.. c:member:: int user_site_directory
12271216
12281217
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
@@ -180,9 +180,6 @@ typedef struct PyConfig {
180180
int use_frozen_modules;
181181
int safe_path;
182182
int int_max_str_digits;
183-
#ifdef __APPLE__
184-
int use_system_logger;
185-
#endif
186183

187184
/* --- Path configuration inputs ------------ */
188185
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
@@ -578,8 +578,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
578578
CONFIG_COMPAT.update({
579579
'legacy_windows_stdio': 0,
580580
})
581-
if support.is_apple:
582-
CONFIG_COMPAT['use_system_logger'] = False
583581

584582
CONFIG_PYTHON = dict(CONFIG_COMPAT,
585583
_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
@@ -681,9 +681,6 @@ config_check_consistency(const PyConfig *config)
681681
assert(config->int_max_str_digits >= 0);
682682
// config->use_frozen_modules is initialized later
683683
// by _PyConfig_InitImportConfig().
684-
#ifdef __APPLE__
685-
assert(config->use_system_logger >= 0);
686-
#endif
687684
return 1;
688685
}
689686
#endif
@@ -778,9 +775,6 @@ _PyConfig_InitCompatConfig(PyConfig *config)
778775
config->int_max_str_digits = -1;
779776
config->_is_python_build = 0;
780777
config->code_debug_ranges = 1;
781-
#ifdef __APPLE__
782-
config->use_system_logger = 0;
783-
#endif
784778
}
785779

786780

@@ -806,9 +800,6 @@ config_init_defaults(PyConfig *config)
806800
#ifdef MS_WINDOWS
807801
config->legacy_windows_stdio = 0;
808802
#endif
809-
#ifdef __APPLE__
810-
config->use_system_logger = 0;
811-
#endif
812803
}
813804

814805

@@ -844,9 +835,6 @@ PyConfig_InitIsolatedConfig(PyConfig *config)
844835
#ifdef MS_WINDOWS
845836
config->legacy_windows_stdio = 0;
846837
#endif
847-
#ifdef __APPLE__
848-
config->use_system_logger = 0;
849-
#endif
850838
}
851839

852840

Python/pylifecycle.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,15 @@
3838
# include <TargetConditionals.h>
3939
# include <mach-o/loader.h>
4040
// The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
41-
// tvOS 10.0, and watchOS 3.0;
41+
// tvOS 10.0, and watchOS 3.0; we enable the use of the system logger
42+
// automatically on non-macOS platforms.
4243
# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
43-
# define HAS_APPLE_SYSTEM_LOG 1
44-
# elif defined(TARGET_OS_OSX) && TARGET_OS_OSX
45-
# if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
46-
# define HAS_APPLE_SYSTEM_LOG 1
47-
# else
48-
# define HAS_APPLE_SYSTEM_LOG 0
49-
# endif
44+
# define USE_APPLE_SYSTEM_LOG 1
5045
# else
51-
# define HAS_APPLE_SYSTEM_LOG 0
46+
# define USE_APPLE_SYSTEM_LOG 0
5247
# endif
5348

54-
# if HAS_APPLE_SYSTEM_LOG
49+
# if USE_APPLE_SYSTEM_LOG
5550
# include <os/log.h>
5651
# endif
5752
#endif
@@ -85,7 +80,7 @@ static PyStatus add_main_module(PyInterpreterState *interp);
8580
static PyStatus init_import_site(void);
8681
static PyStatus init_set_builtins_open(void);
8782
static PyStatus init_sys_streams(PyThreadState *tstate);
88-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
83+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
8984
static PyStatus init_apple_streams(PyThreadState *tstate);
9085
#endif
9186
static void wait_for_thread_shutdown(PyThreadState *tstate);
@@ -1204,12 +1199,10 @@ init_interp_main(PyThreadState *tstate)
12041199
return status;
12051200
}
12061201

1207-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
1208-
if (config->use_system_logger) {
1209-
status = init_apple_streams(tstate);
1210-
if (_PyStatus_EXCEPTION(status)) {
1211-
return status;
1212-
}
1202+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
1203+
status = init_apple_streams(tstate);
1204+
if (_PyStatus_EXCEPTION(status)) {
1205+
return status;
12131206
}
12141207
#endif
12151208

@@ -2676,7 +2669,7 @@ init_sys_streams(PyThreadState *tstate)
26762669
return res;
26772670
}
26782671

2679-
#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
2672+
#if defined(__APPLE__) && USE_APPLE_SYSTEM_LOG
26802673

26812674
static PyObject *
26822675
apple_log_write_impl(PyObject *self, PyObject *args)
@@ -2737,7 +2730,7 @@ init_apple_streams(PyThreadState *tstate)
27372730
return status;
27382731
}
27392732

2740-
#endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
2733+
#endif // __APPLE__ && USE_APPLE_SYSTEM_LOG
27412734

27422735

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