Issue #25923: Added the const qualifier to static constant arrays.
diff --git a/Python/ast.c b/Python/ast.c
index 77ebc83..328ee5d 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -870,7 +870,7 @@
}
}
-static const char* FORBIDDEN[] = {
+static const char * const FORBIDDEN[] = {
"None",
"True",
"False",
@@ -887,7 +887,7 @@
return 1;
}
if (full_checks) {
- const char **p;
+ const char * const *p;
for (p = FORBIDDEN; *p; p++) {
if (PyUnicode_CompareWithASCIIString(name, *p) == 0) {
ast_error(c, n, "assignment to keyword");
diff --git a/Python/dtoa.c b/Python/dtoa.c
index 3da546e..3121cd6 100644
--- a/Python/dtoa.c
+++ b/Python/dtoa.c
@@ -747,7 +747,7 @@
{
Bigint *b1, *p5, *p51;
int i;
- static int p05[3] = { 5, 25, 125 };
+ static const int p05[3] = { 5, 25, 125 };
if ((i = k & 3)) {
b = multadd(b, p05[i-1], 0);
@@ -803,7 +803,7 @@
{
Bigint *b1, *p5, *p51;
int i;
- static int p05[3] = { 5, 25, 125 };
+ static const int p05[3] = { 5, 25, 125 };
if ((i = k & 3)) {
b = multadd(b, p05[i-1], 0);
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
index 056bb76..a428fbe 100644
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -656,7 +656,7 @@
return 0;
}
-static char no_grouping[1] = {CHAR_MAX};
+static const char no_grouping[1] = {CHAR_MAX};
/* Find the decimal point character(s?), thousands_separator(s?), and
grouping description, either for the current locale if type is
diff --git a/Python/import.c b/Python/import.c
index edf030d..8d7bfe9 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -320,7 +320,7 @@
/* List of names to clear in sys */
-static char* sys_deletes[] = {
+static const char * const sys_deletes[] = {
"path", "argv", "ps1", "ps2",
"last_type", "last_value", "last_traceback",
"path_hooks", "path_importer_cache", "meta_path",
@@ -330,7 +330,7 @@
NULL
};
-static char* sys_files[] = {
+static const char * const sys_files[] = {
"stdin", "__stdin__",
"stdout", "__stdout__",
"stderr", "__stderr__",
@@ -347,7 +347,7 @@
PyInterpreterState *interp = PyThreadState_GET()->interp;
PyObject *modules = interp->modules;
PyObject *weaklist = NULL;
- char **p;
+ const char * const *p;
if (modules == NULL)
return; /* Already done */
diff --git a/Python/importdl.c b/Python/importdl.c
index 1aa585d..ac03289 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -23,8 +23,8 @@
const char *pathname, FILE *fp);
#endif
-static const char *ascii_only_prefix = "PyInit";
-static const char *nonascii_prefix = "PyInitU";
+static const char * const ascii_only_prefix = "PyInit";
+static const char * const nonascii_prefix = "PyInitU";
/* Get the variable part of a module's export symbol name.
* Returns a bytes instance. For non-ASCII-named modules, the name is
diff --git a/Python/mystrtoul.c b/Python/mystrtoul.c
index 98429d4..a85790e 100644
--- a/Python/mystrtoul.c
+++ b/Python/mystrtoul.c
@@ -17,7 +17,7 @@
* smallmax[base] is the largest unsigned long i such that
* i * base doesn't overflow unsigned long.
*/
-static unsigned long smallmax[] = {
+static const unsigned long smallmax[] = {
0, /* bases 0 and 1 are invalid */
0,
ULONG_MAX / 2,
@@ -62,14 +62,14 @@
* Note that this is pessimistic if sizeof(long) > 4.
*/
#if SIZEOF_LONG == 4
-static int digitlimit[] = {
+static const int digitlimit[] = {
0, 0, 32, 20, 16, 13, 12, 11, 10, 10, /* 0 - 9 */
9, 9, 8, 8, 8, 8, 8, 7, 7, 7, /* 10 - 19 */
7, 7, 7, 7, 6, 6, 6, 6, 6, 6, /* 20 - 29 */
6, 6, 6, 6, 6, 6, 6}; /* 30 - 36 */
#elif SIZEOF_LONG == 8
/* [int(math.floor(math.log(2**64, i))) for i in range(2, 37)] */
-static int digitlimit[] = {
+static const int digitlimit[] = {
0, 0, 64, 40, 32, 27, 24, 22, 21, 20, /* 0 - 9 */
19, 18, 17, 17, 16, 16, 16, 15, 15, 15, /* 10 - 19 */
14, 14, 14, 14, 13, 13, 13, 13, 13, 13, /* 20 - 29 */
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 209c908..5f3af92 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -881,12 +881,12 @@
#define OFS_E 2
/* The lengths of these are known to the code below, so don't change them */
-static char *lc_float_strings[] = {
+static const char * const lc_float_strings[] = {
"inf",
"nan",
"e",
};
-static char *uc_float_strings[] = {
+static const char * const uc_float_strings[] = {
"INF",
"NAN",
"E",
@@ -925,7 +925,8 @@
format_float_short(double d, char format_code,
int mode, int precision,
int always_add_sign, int add_dot_0_if_integer,
- int use_alt_formatting, char **float_strings, int *type)
+ int use_alt_formatting, const char * const *float_strings,
+ int *type)
{
char *buf = NULL;
char *p = NULL;
@@ -1176,7 +1177,7 @@
int flags,
int *type)
{
- char **float_strings = lc_float_strings;
+ const char * const *float_strings = lc_float_strings;
int mode;
/* Validate format_code, and map upper and lower case. Compute the
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 1a5dab5..cfe197b 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -785,11 +785,11 @@
PyErr_Clear();
}
-static const char *cause_message =
+static const char cause_message[] =
"\nThe above exception was the direct cause "
"of the following exception:\n\n";
-static const char *context_message =
+static const char context_message[] =
"\nDuring handling of the above exception, "
"another exception occurred:\n\n";
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index e0aa233..f784f75 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -346,8 +346,10 @@
static int
trace_init(void)
{
- static char *whatnames[7] = {"call", "exception", "line", "return",
- "c_call", "c_exception", "c_return"};
+ static const char * const whatnames[7] = {
+ "call", "exception", "line", "return",
+ "c_call", "c_exception", "c_return"
+ };
PyObject *name;
int i;
for (i = 0; i < 7; ++i) {