8000 gh-96512: Move int_max_str_digits setting to PyConfig by gpshead · Pull Request #96944 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-96512: Move int_max_str_digits setting to PyConfig #96944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments.
  • Loading branch information
gpshead committed Sep 23, 2022
commit 8b4561dbe582ebcc6e85ac9429f10decaeb7ed73
15 changes: 8 additions & 7 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -831,17 +831,18 @@ PyConfig
.. c:member:: int int_max_str_digits

Configures the :ref:`integer string conversion length limitation
<int_max_str_digits>`. ``-1`` means that
:data:`sys.int_info.default_max_str_digits` will be used. No other
negative value is accepted. ``0`` disables the limitation. Values
greater than zero but less than ``_PY_LONG_MAX_STR_DIGITS_THRESHOLD``
(640) also known as :data:`sys.int_info.str_digits_check_threshold`
are unsupported and will produce an error.
<int_max_str_digits>`. An initial value of ``-1`` means the value will
be taken from the command line or environment or otherwise default to
4300 (:data:`sys.int_info.default_max_str_digits`). A value of ``0``
disables the limitation. Values greater than zero but less than 640
(:data:`sys.int_info.str_digits_check_threshold`) are unsupported and
will produce an error.

Configured by the :option:`-X int_max_str_digits <-X>` command line
flag or the :envvar:`PYTHONINTMAXSTRDIGITS` environment varable.

Default: ``-1``.
Default: ``-1`` in Python mode. 4300
(:data:`sys.int_info.default_max_str_digits`) in isolated mode.

.. versionadded:: 3.12

Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'install_signal_handlers': 1,
'use_hash_seed': 0,
'hash_seed': 0,
'int_max_str_digits': 4300,
'int_max_str_digits': sys.int_info.default_max_str_digits,
'faulthandler': 0,
'tracemalloc': 0,
'perf_profiling': 0,
Expand Down Expand Up @@ -914,6 +914,7 @@ def test_init_compat_env(self):
'platlibdir': 'env_platlibdir',
'module_search_paths': self.IGNORE_CONFIG,
'safe_path': 1,
'int_max_str_digits': 4567,
}
self.check_all_configs("test_init_compat_env", config, preconfig,
api=API_COMPAT)
Expand Down Expand Up @@ -946,6 +947,7 @@ def test_init_python_env(self):
'platlibdir': 'env_platlibdir',
'module_search_paths': self.IGNORE_CONFIG,
'safe_path': 1,
'int_max_str_digits': 4567,
}
self.check_all_configs("test_init_python_env", config, preconfig,
api=API_PYTHON)
Expand Down
1 change: 1 addition & 0 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ static void set_most_env_vars(void)
putenv("PYTHONIOENCODING=iso8859-1:replace");
putenv("PYTHONPLATLIBDIR=env_platlibdir");
putenv("PYTHONSAFEPATH=1");
putenv("PYTHONINTMAXSTRDIGITS=4567");
}


Expand Down
8 changes: 4 additions & 4 deletions Python/clinic/sysmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ PyConfig_InitIsolatedConfig(PyConfig *config)
config->faulthandler = 0;
config->tracemalloc = 0;
config->perf_profiling = 0;
config->int_max_str_digits = _PY_LONG_DEFAULT_MAX_STR_DIGITS;
config->safe_path = 1;
config->pathconfig_warnings = 0;
#ifdef MS_WINDOWS
Expand Down Expand Up @@ -1823,10 +1824,7 @@ config_init_int_max_str_digits(PyConfig *config)
}
config->int_max_str_digits = maxdigits;
}
if (config->int_max_str_digits < -1) {
return _PyStatus_ERR("invalid value: PyConfig.int_max_str_digits < -1.");
}
if (config->int_max_str_digits == -1) {
if (config->int_max_str_digits < 0) {
config->int_max_str_digits = _PY_LONG_DEFAULT_MAX_STR_DIGITS;
}
return _PyStatus_OK();
Expand Down
11 changes: 3 additions & 8 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,22 +1723,17 @@ sys_get_int_max_str_digits_impl(PyObject *module)
/*[clinic input]
sys.set_int_max_str_digits

maxdigits: long
maxdigits: int

Set the maximum string digits limit for non-binary int<->str conversions.
[clinic start generated code]*/

static PyObject *
sys_set_int_max_str_digits_impl(PyObject *module, long maxdigits)
/*[clinic end generated code: output=40ea5d33a82c5c44 input=657c61a1822f6bcf]*/
sys_set_int_max_str_digits_impl(PyObject *module, int maxdigits)
/*[clinic end generated code: output=734d4c2511f2a56d input=d7e3f325db6910c5]*/
{
PyThreadState *tstate = _PyThreadState_GET();
if ((!maxdigits) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD)) {
if (maxdigits > INT_MAX) {
/* Silently cap our range; already effectively unlimited as no
* computation this large can finish. */
maxdigits = INT_MAX;
}
tstate->interp->config.int_max_str_digits = maxdigits;
Py_RETURN_NONE;
} else {
Expand Down
0