Issue #25923: Added the const qualifier to static constant arrays.

This commit is contained in:
Serhiy Storchaka 2015-12-25 19:53:18 +02:00
parent ea8c43152f
commit 2d06e84455
44 changed files with 139 additions and 134 deletions

View file

@ -870,7 +870,7 @@ get_operator(const node *n)
}
}
static const char* FORBIDDEN[] = {
static const char * const FORBIDDEN[] = {
"None",
"True",
"False",
@ -887,7 +887,7 @@ forbidden_name(struct compiling *c, identifier name, const node *n,
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");

View file

@ -747,7 +747,7 @@ pow5mult(Bigint *b, int k)
{
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 @@ pow5mult(Bigint *b, int k)
{
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);

View file

@ -656,7 +656,7 @@ fill_number(_PyUnicodeWriter *writer, const NumberFieldWidths *spec,
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

View file

@ -320,7 +320,7 @@ PyImport_GetModuleDict(void)
/* 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 @@ static char* sys_deletes[] = {
NULL
};
static char* sys_files[] = {
static const char * const sys_files[] = {
"stdin", "__stdin__",
"stdout", "__stdout__",
"stderr", "__stderr__",
@ -347,7 +347,7 @@ PyImport_Cleanup(void)
PyInterpreterState *interp = PyThreadState_GET()->interp;
PyObject *modules = interp->modules;
PyObject *weaklist = NULL;
char **p;
const char * const *p;
if (modules == NULL)
return; /* Already done */

View file

@ -23,8 +23,8 @@ extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
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

View file

@ -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 @@ static unsigned long smallmax[] = {
* 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 */

View file

@ -881,12 +881,12 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
#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 @@ static char *
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 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
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

View file

@ -785,11 +785,11 @@ print_exception(PyObject *f, PyObject *value)
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";

View file

@ -346,8 +346,10 @@ static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
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) {