Skip to content

Commit 47932ff

Browse files
committed
gh-129033: Remove _PyInterpreterState_SetConfig() function
Remove _PyInterpreterState_GetConfigCopy() and _PyInterpreterState_SetConfig() private functions. PEP 741 "Python Configuration C API" added a better public C API: PyConfig_Get() and PyConfig_Set().
1 parent 07c3518 commit 47932ff

File tree

9 files changed

+6
-483
lines changed

9 files changed

+6
-483
lines changed

Include/internal/pycore_interp.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -341,43 +341,6 @@ extern void _PyInterpreterState_SetWhence(
341341

342342
extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);
343343

344-
// Get a copy of the current interpreter configuration.
345-
//
346-
// Return 0 on success. Raise an exception and return -1 on error.
347-
//
348-
// The caller must initialize 'config', using PyConfig_InitPythonConfig()
349-
// for example.
350-
//
351-
// Python must be preinitialized to call this method.
352-
// The caller must hold the GIL.
353-
//
354-
// Once done with the configuration, PyConfig_Clear() must be called to clear
355-
// it.
356-
//
357-
// Export for '_testinternalcapi' shared extension.
358-
PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
359-
struct PyConfig *config);
360-
361-
// Set the configuration of the current interpreter.
362-
//
363-
// This function should be called during or just after the Python
364-
// initialization.
365-
//
366-
// Update the sys module with the new configuration. If the sys module was
367-
// modified directly after the Python initialization, these changes are lost.
368-
//
369-
// Some configuration like faulthandler or warnoptions can be updated in the
370-
// configuration, but don't reconfigure Python (don't enable/disable
371-
// faulthandler and don't reconfigure warnings filters).
372-
//
373-
// Return 0 on success. Raise an exception and return -1 on error.
374-
//
375-
// The configuration should come from _PyInterpreterState_GetConfigCopy().
376-
//
377-
// Export for '_testinternalcapi' shared extension.
378-
PyAPI_FUNC(int) _PyInterpreterState_SetConfig(
379-
const struct PyConfig *config);
380-
381344

382345
/*
383346
Runtime Feature Flags

Lib/test/_test_embed_set_config.py

Lines changed: 0 additions & 291 deletions
This file was deleted.

Lib/test/support/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,10 @@ def requires_lzma(reason='requires lzma'):
505505

506506
def has_no_debug_ranges():
507507
try:
508-
import _testinternalcapi
508+
import _testcapi
509509
except ImportError:
510510
raise unittest.SkipTest("_testinternalcapi required")
511-
config = _testinternalcapi.get_config()
511+
return not _testcapi.config_get('code_debug_ranges')
512512
return not bool(config['code_debug_ranges'])
513513

514514
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):

Lib/test/test_embed.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,14 +1748,6 @@ def test_init_warnoptions(self):
17481748
self.check_all_configs("test_init_warnoptions", config, preconfig,
17491749
api=API_PYTHON)
17501750

1751-
def test_init_set_config(self):
1752-
config = {
1753-
'bytes_warning': 2,
1754-
'warnoptions': ['error::BytesWarning'],
1755-
}
1756-
self.check_all_configs("test_init_set_config", config,
1757-
api=API_ISOLATED)
1758-
17591751
@unittest.skipIf(support.check_bolt_optimized, "segfaults on BOLT instrumented binaries")
17601752
def test_initconfig_api(self):
17611753
preconfig = {
@@ -1847,22 +1839,6 @@ def test_init_in_background_thread(self):
18471839
self.assertEqual(err, "")
18481840

18491841

1850-
class SetConfigTests(unittest.TestCase):
1851-
def test_set_config(self):
1852-
# bpo-42260: Test _PyInterpreterState_SetConfig()
1853-
import_helper.import_module('_testcapi')
1854-
cmd = [sys.executable, '-X', 'utf8', '-I', '-m', 'test._test_embed_set_config']
1855-
proc = subprocess.run(cmd,
1856-
stdout=subprocess.PIPE,
1857-
stderr=subprocess.PIPE,
1858-
encoding='utf-8', errors='backslashreplace')
1859-
if proc.returncode and support.verbose:
1860-
print(proc.stdout)
1861-
print(proc.stderr)
1862-
self.assertEqual(proc.returncode, 0,
1863-
(proc.returncode, proc.stdout, proc.stderr))
1864-
1865-
18661842
class AuditingTests(EmbeddingTestsMixin, unittest.TestCase):
18671843
def test_open_code_hook(self):
18681844
self.run_embedded_interpreter("test_open_code_hook")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Remove ``_PyInterpreterState_GetConfigCopy()`` and
2+
``_PyInterpreterState_SetConfig()`` private functions. Use instead
3+
:c:func:`PyConfig_Get` and :c:func:`PyConfig_Set`, public C API added by
4+
:pep:`741` "Python Configuration C API". Patch by Victor Stinner.

0 commit comments

Comments
 (0)