]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-98417: Store int_max_str_digits on the Interpreter State (GH-98418)
authorEric Snow <ericsnowcurrently@gmail.com>
Wed, 19 Oct 2022 20:27:46 +0000 (14:27 -0600)
committerGitHub <noreply@github.com>
Wed, 19 Oct 2022 20:27:46 +0000 (13:27 -0700)
Include/internal/pycore_interp.h
Objects/longobject.c
Python/pylifecycle.c
Python/sysmodule.c

index c11e897305d42bb8369f8f52b7b83ee3b33fe7bf..e643c7e9e4edd15079ff092c9b83c8b54cd052b2 100644 (file)
@@ -69,6 +69,11 @@ struct atexit_state {
 };
 
 
+struct _Py_long_state {
+    int max_str_digits;
+};
+
+
 /* interpreter state */
 
 /* PyInterpreterState holds the global state for one of the runtime's
@@ -164,6 +169,7 @@ struct _is {
 
     struct _Py_unicode_state unicode;
     struct _Py_float_state float_state;
+    struct _Py_long_state long_state;
     /* Using a cache is very effective since typically only a single slice is
        created and then deleted again. */
     PySliceObject *slice_cache;
index 8b13df4181ecff1a207da675aa6b2b78226e8059..304fabfad744a4b88e4f5389767641707dae9987 100644 (file)
@@ -1767,7 +1767,7 @@ long_to_decimal_string_internal(PyObject *aa,
     if (size_a >= 10 * _PY_LONG_MAX_STR_DIGITS_THRESHOLD
                   / (3 * PyLong_SHIFT) + 2) {
         PyInterpreterState *interp = _PyInterpreterState_GET();
-        int max_str_digits = interp->config.int_max_str_digits;
+        int max_str_digits = interp->long_state.max_str_digits;
         if ((max_str_digits > 0) &&
             (max_str_digits / (3 * PyLong_SHIFT) <= (size_a - 11) / 10)) {
             PyErr_Format(PyExc_ValueError, _MAX_STR_DIGITS_ERROR_FMT_TO_STR,
@@ -1837,7 +1837,7 @@ long_to_decimal_string_internal(PyObject *aa,
     }
     if (strlen > _PY_LONG_MAX_STR_DIGITS_THRESHOLD) {
         PyInterpreterState *interp = _PyInterpreterState_GET();
-        int max_str_digits = interp->config.int_max_str_digits;
+        int max_str_digits = interp->long_state.max_str_digits;
         Py_ssize_t strlen_nosign = strlen - negative;
         if ((max_str_digits > 0) && (strlen_nosign > max_str_digits)) {
             Py_DECREF(scratch);
@@ -2578,7 +2578,7 @@ long_from_string_base(const char **str, int base, PyLongObject **res)
          * quadratic algorithm. */
         if (digits > _PY_LONG_MAX_STR_DIGITS_THRESHOLD) {
             PyInterpreterState *interp = _PyInterpreterState_GET();
-            int max_str_digits = interp->config.int_max_str_digits;
+            int max_str_digits = interp->long_state.max_str_digits;
             if ((max_str_digits > 0) && (digits > max_str_digits)) {
                 PyErr_Format(PyExc_ValueError, _MAX_STR_DIGITS_ERROR_FMT_TO_INT,
                              max_str_digits, digits);
index c550f13bc14820c4b2d02134daf6a9d7c02914e2..4195a9dbca812f361b129c8fd7c1bd2a36257132 100644 (file)
@@ -480,6 +480,8 @@ interpreter_update_config(PyThreadState *tstate, int only_update_path_config)
         }
     }
 
+    tstate->interp->long_state.max_str_digits = config->int_max_str_digits;
+
     // Update the sys module for the new configuration
     if (_PySys_UpdateConfig(tstate) < 0) {
         return -1;
index 2c66415ee3d3f4b4735eb26658c5cfa4692f6897..708145651812b285fd4dcb6dd119c8ba9d24a23c 100644 (file)
@@ -1717,7 +1717,7 @@ sys_get_int_max_str_digits_impl(PyObject *module)
 /*[clinic end generated code: output=0042f5e8ae0e8631 input=8dab13e2023e60d5]*/
 {
     PyInterpreterState *interp = _PyInterpreterState_GET();
-    return PyLong_FromLong(interp->config.int_max_str_digits);
+    return PyLong_FromLong(interp->long_state.max_str_digits);
 }
 
 /*[clinic input]
@@ -1734,7 +1734,7 @@ sys_set_int_max_str_digits_impl(PyObject *module, int maxdigits)
 {
     PyThreadState *tstate = _PyThreadState_GET();
     if ((!maxdigits) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD)) {
-        tstate->interp->config.int_max_str_digits = maxdigits;
+        tstate->interp->long_state.max_str_digits = maxdigits;
         Py_RETURN_NONE;
     } else {
         PyErr_Format(