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

@ -103,8 +103,8 @@ static void **PyCurses_API;
#endif #endif
/* general error messages */ /* general error messages */
static char *catchall_ERR = "curses function returned ERR"; static const char catchall_ERR[] = "curses function returned ERR";
static char *catchall_NULL = "curses function returned NULL"; static const char catchall_NULL[] = "curses function returned NULL";
/* Function Prototype Macros - They are ugly but very, very useful. ;-) /* Function Prototype Macros - They are ugly but very, very useful. ;-)

View file

@ -169,7 +169,7 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
#pragma float_control (pop) #pragma float_control (pop)
#define Py_NAN __icc_nan() #define Py_NAN __icc_nan()
#else /* ICC_NAN_RELAXED as default for Intel Compiler */ #else /* ICC_NAN_RELAXED as default for Intel Compiler */
static union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f}; static const union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
#define Py_NAN (__nan_store.__icc_nan) #define Py_NAN (__nan_store.__icc_nan)
#endif /* ICC_NAN_STRICT */ #endif /* ICC_NAN_STRICT */
#endif /* __INTEL_COMPILER */ #endif /* __INTEL_COMPILER */

View file

@ -60,10 +60,10 @@ typedef enum {
typedef struct { typedef struct {
QuoteStyle style; QuoteStyle style;
char *name; const char *name;
} StyleDesc; } StyleDesc;
static StyleDesc quote_styles[] = { static const StyleDesc quote_styles[] = {
{ QUOTE_MINIMAL, "QUOTE_MINIMAL" }, { QUOTE_MINIMAL, "QUOTE_MINIMAL" },
{ QUOTE_ALL, "QUOTE_ALL" }, { QUOTE_ALL, "QUOTE_ALL" },
{ QUOTE_NONNUMERIC, "QUOTE_NONNUMERIC" }, { QUOTE_NONNUMERIC, "QUOTE_NONNUMERIC" },
@ -286,7 +286,7 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
static int static int
dialect_check_quoting(int quoting) dialect_check_quoting(int quoting)
{ {
StyleDesc *qs; const StyleDesc *qs;
for (qs = quote_styles; qs->name; qs++) { for (qs = quote_styles; qs->name; qs++) {
if ((int)qs->style == quoting) if ((int)qs->style == quoting)
@ -1633,7 +1633,7 @@ PyMODINIT_FUNC
PyInit__csv(void) PyInit__csv(void)
{ {
PyObject *module; PyObject *module;
StyleDesc *style; const StyleDesc *style;
if (PyType_Ready(&Dialect_Type) < 0) if (PyType_Ready(&Dialect_Type) < 0)
return NULL; return NULL;

View file

@ -435,7 +435,7 @@ UnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return StructUnionType_new(type, args, kwds, 0); return StructUnionType_new(type, args, kwds, 0);
} }
static char from_address_doc[] = static const char from_address_doc[] =
"C.from_address(integer) -> C instance\naccess a C instance at the specified address"; "C.from_address(integer) -> C instance\naccess a C instance at the specified address";
static PyObject * static PyObject *
@ -453,7 +453,7 @@ CDataType_from_address(PyObject *type, PyObject *value)
return PyCData_AtAddress(type, buf); return PyCData_AtAddress(type, buf);
} }
static char from_buffer_doc[] = static const char from_buffer_doc[] =
"C.from_buffer(object, offset=0) -> C instance\ncreate a C instance from a writeable buffer"; "C.from_buffer(object, offset=0) -> C instance\ncreate a C instance from a writeable buffer";
static int static int
@ -524,7 +524,7 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
return result; return result;
} }
static char from_buffer_copy_doc[] = static const char from_buffer_copy_doc[] =
"C.from_buffer_copy(object, offset=0) -> C instance\ncreate a C instance from a readable buffer"; "C.from_buffer_copy(object, offset=0) -> C instance\ncreate a C instance from a readable buffer";
static PyObject * static PyObject *
@ -566,7 +566,7 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
return result; return result;
} }
static char in_dll_doc[] = static const char in_dll_doc[] =
"C.in_dll(dll, name) -> C instance\naccess a C instance in a dll"; "C.in_dll(dll, name) -> C instance\naccess a C instance in a dll";
static PyObject * static PyObject *
@ -623,7 +623,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
return PyCData_AtAddress(type, address); return PyCData_AtAddress(type, address);
} }
static char from_param_doc[] = static const char from_param_doc[] =
"Convert a Python object into a function call parameter."; "Convert a Python object into a function call parameter.";
static PyObject * static PyObject *
@ -1481,7 +1481,7 @@ _type_ attribute.
*/ */
static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv?g"; static const char SIMPLE_TYPE_CHARS[] = "cbBhHiIlLdfuzZqQPXOv?g";
static PyObject * static PyObject *
c_wchar_p_from_param(PyObject *type, PyObject *value) c_wchar_p_from_param(PyObject *type, PyObject *value)
@ -5118,7 +5118,7 @@ static const char module_docs[] =
#ifdef MS_WIN32 #ifdef MS_WIN32
static char comerror_doc[] = "Raised when a COM method call failed."; static const char comerror_doc[] = "Raised when a COM method call failed.";
int int
comerror_init(PyObject *self, PyObject *args, PyObject *kwds) comerror_init(PyObject *self, PyObject *args, PyObject *kwds)

View file

@ -1201,7 +1201,7 @@ _parse_voidp(PyObject *obj, void **address)
#ifdef MS_WIN32 #ifdef MS_WIN32
static char format_error_doc[] = static const char format_error_doc[] =
"FormatError([integer]) -> string\n\ "FormatError([integer]) -> string\n\
\n\ \n\
Convert a win32 error code into a string. If the error code is not\n\ Convert a win32 error code into a string. If the error code is not\n\
@ -1225,7 +1225,7 @@ static PyObject *format_error(PyObject *self, PyObject *args)
return result; return result;
} }
static char load_library_doc[] = static const char load_library_doc[] =
"LoadLibrary(name) -> handle\n\ "LoadLibrary(name) -> handle\n\
\n\ \n\
Load an executable (usually a DLL), and return a handle to it.\n\ Load an executable (usually a DLL), and return a handle to it.\n\
@ -1254,7 +1254,7 @@ static PyObject *load_library(PyObject *self, PyObject *args)
#endif #endif
} }
static char free_library_doc[] = static const char free_library_doc[] =
"FreeLibrary(handle) -> void\n\ "FreeLibrary(handle) -> void\n\
\n\ \n\
Free the handle of an executable previously loaded by LoadLibrary.\n"; Free the handle of an executable previously loaded by LoadLibrary.\n";
@ -1269,7 +1269,7 @@ static PyObject *free_library(PyObject *self, PyObject *args)
return Py_None; return Py_None;
} }
static char copy_com_pointer_doc[] = static const char copy_com_pointer_doc[] =
"CopyComPointer(src, dst) -> HRESULT value\n"; "CopyComPointer(src, dst) -> HRESULT value\n";
static PyObject * static PyObject *
@ -1439,7 +1439,7 @@ call_cdeclfunction(PyObject *self, PyObject *args)
/***************************************************************** /*****************************************************************
* functions * functions
*/ */
static char sizeof_doc[] = static const char sizeof_doc[] =
"sizeof(C type) -> integer\n" "sizeof(C type) -> integer\n"
"sizeof(C instance) -> integer\n" "sizeof(C instance) -> integer\n"
"Return the size in bytes of a C instance"; "Return the size in bytes of a C instance";
@ -1460,7 +1460,7 @@ sizeof_func(PyObject *self, PyObject *obj)
return NULL; return NULL;
} }
static char alignment_doc[] = static const char alignment_doc[] =
"alignment(C type) -> integer\n" "alignment(C type) -> integer\n"
"alignment(C instance) -> integer\n" "alignment(C instance) -> integer\n"
"Return the alignment requirements of a C instance"; "Return the alignment requirements of a C instance";
@ -1483,7 +1483,7 @@ align_func(PyObject *self, PyObject *obj)
return NULL; return NULL;
} }
static char byref_doc[] = static const char byref_doc[] =
"byref(C instance[, offset=0]) -> byref-object\n" "byref(C instance[, offset=0]) -> byref-object\n"
"Return a pointer lookalike to a C instance, only usable\n" "Return a pointer lookalike to a C instance, only usable\n"
"as function argument"; "as function argument";
@ -1527,7 +1527,7 @@ byref(PyObject *self, PyObject *args)
return (PyObject *)parg; return (PyObject *)parg;
} }
static char addressof_doc[] = static const char addressof_doc[] =
"addressof(C instance) -> integer\n" "addressof(C instance) -> integer\n"
"Return the address of the C instance internal buffer"; "Return the address of the C instance internal buffer";

View file

@ -6,7 +6,7 @@
/* Release Number */ /* Release Number */
static char *PyCursesVersion = "2.1"; static const char PyCursesVersion[] = "2.1";
/* Includes */ /* Includes */

View file

@ -184,12 +184,12 @@ divide_nearest(PyObject *m, PyObject *n)
* and the number of days before that month in the same year. These * and the number of days before that month in the same year. These
* are correct for non-leap years only. * are correct for non-leap years only.
*/ */
static int _days_in_month[] = { static const int _days_in_month[] = {
0, /* unused; this vector uses 1-based indexing */ 0, /* unused; this vector uses 1-based indexing */
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}; };
static int _days_before_month[] = { static const int _days_before_month[] = {
0, /* unused; this vector uses 1-based indexing */ 0, /* unused; this vector uses 1-based indexing */
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
}; };
@ -1009,10 +1009,10 @@ append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo)
static PyObject * static PyObject *
format_ctime(PyDateTime_Date *date, int hours, int minutes, int seconds) format_ctime(PyDateTime_Date *date, int hours, int minutes, int seconds)
{ {
static const char *DayNames[] = { static const char * const DayNames[] = {
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
}; };
static const char *MonthNames[] = { static const char * const MonthNames[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}; };
@ -2307,7 +2307,7 @@ static PyMethodDef delta_methods[] = {
{NULL, NULL}, {NULL, NULL},
}; };
static char delta_doc[] = static const char delta_doc[] =
PyDoc_STR("Difference between two datetime values."); PyDoc_STR("Difference between two datetime values.");
static PyNumberMethods delta_as_number = { static PyNumberMethods delta_as_number = {
@ -2886,7 +2886,7 @@ static PyMethodDef date_methods[] = {
{NULL, NULL} {NULL, NULL}
}; };
static char date_doc[] = static const char date_doc[] =
PyDoc_STR("date(year, month, day) --> date object"); PyDoc_STR("date(year, month, day) --> date object");
static PyNumberMethods date_as_number = { static PyNumberMethods date_as_number = {
@ -3155,7 +3155,7 @@ static PyMethodDef tzinfo_methods[] = {
{NULL, NULL} {NULL, NULL}
}; };
static char tzinfo_doc[] = static const char tzinfo_doc[] =
PyDoc_STR("Abstract base class for time zone info objects."); PyDoc_STR("Abstract base class for time zone info objects.");
static PyTypeObject PyDateTime_TZInfoType = { static PyTypeObject PyDateTime_TZInfoType = {
@ -3387,7 +3387,7 @@ static PyMethodDef timezone_methods[] = {
{NULL, NULL} {NULL, NULL}
}; };
static char timezone_doc[] = static const char timezone_doc[] =
PyDoc_STR("Fixed offset from UTC implementation of tzinfo."); PyDoc_STR("Fixed offset from UTC implementation of tzinfo.");
static PyTypeObject PyDateTime_TimeZoneType = { static PyTypeObject PyDateTime_TimeZoneType = {
@ -3877,7 +3877,7 @@ static PyMethodDef time_methods[] = {
{NULL, NULL} {NULL, NULL}
}; };
static char time_doc[] = static const char time_doc[] =
PyDoc_STR("time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object\n\ PyDoc_STR("time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object\n\
\n\ \n\
All arguments are optional. tzinfo may be None, or an instance of\n\ All arguments are optional. tzinfo may be None, or an instance of\n\
@ -5065,7 +5065,7 @@ static PyMethodDef datetime_methods[] = {
{NULL, NULL} {NULL, NULL}
}; };
static char datetime_doc[] = static const char datetime_doc[] =
PyDoc_STR("datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])\n\ PyDoc_STR("datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])\n\
\n\ \n\
The year, month and day arguments are required. tzinfo may be None, or an\n\ The year, month and day arguments are required. tzinfo may be None, or an\n\

View file

@ -14,16 +14,16 @@
*/ */
#if defined(HAVE_NDBM_H) #if defined(HAVE_NDBM_H)
#include <ndbm.h> #include <ndbm.h>
static char *which_dbm = "GNU gdbm"; /* EMX port of GDBM */ static const char which_dbm[] = "GNU gdbm"; /* EMX port of GDBM */
#elif defined(HAVE_GDBM_NDBM_H) #elif defined(HAVE_GDBM_NDBM_H)
#include <gdbm/ndbm.h> #include <gdbm/ndbm.h>
static char *which_dbm = "GNU gdbm"; static const char which_dbm[] = "GNU gdbm";
#elif defined(HAVE_GDBM_DASH_NDBM_H) #elif defined(HAVE_GDBM_DASH_NDBM_H)
#include <gdbm-ndbm.h> #include <gdbm-ndbm.h>
static char *which_dbm = "GNU gdbm"; static const char which_dbm[] = "GNU gdbm";
#elif defined(HAVE_BERKDB_H) #elif defined(HAVE_BERKDB_H)
#include <db.h> #include <db.h>
static char *which_dbm = "Berkeley DB"; static const char which_dbm[] = "Berkeley DB";
#else #else
#error "No ndbm.h available!" #error "No ndbm.h available!"
#endif #endif

View file

@ -615,7 +615,7 @@ dbmopen_impl(PyModuleDef *module, const char *name, const char *flags,
return newdbmobject(name, iflags, mode); return newdbmobject(name, iflags, mode);
} }
static char dbmmodule_open_flags[] = "rwcn" static const char dbmmodule_open_flags[] = "rwcn"
#ifdef GDBM_FAST #ifdef GDBM_FAST
"f" "f"
#endif #endif

View file

@ -772,7 +772,7 @@ typedef struct {
encodefunc_t encodefunc; encodefunc_t encodefunc;
} encodefuncentry; } encodefuncentry;
static encodefuncentry encodefuncs[] = { static const encodefuncentry encodefuncs[] = {
{"ascii", (encodefunc_t) ascii_encode}, {"ascii", (encodefunc_t) ascii_encode},
{"iso8859-1", (encodefunc_t) latin1_encode}, {"iso8859-1", (encodefunc_t) latin1_encode},
{"utf-8", (encodefunc_t) utf8_encode}, {"utf-8", (encodefunc_t) utf8_encode},
@ -1022,7 +1022,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
goto error; goto error;
} }
else if (PyUnicode_Check(res)) { else if (PyUnicode_Check(res)) {
encodefuncentry *e = encodefuncs; const encodefuncentry *e = encodefuncs;
while (e->name != NULL) { while (e->name != NULL) {
if (!PyUnicode_CompareWithASCIIString(res, e->name)) { if (!PyUnicode_CompareWithASCIIString(res, e->name)) {
self->encodefunc = e->encodefunc; self->encodefunc = e->encodefunc;

View file

@ -99,7 +99,7 @@ static PY_UINT32_T
genrand_int32(RandomObject *self) genrand_int32(RandomObject *self)
{ {
PY_UINT32_T y; PY_UINT32_T y;
static PY_UINT32_T mag01[2]={0x0U, MATRIX_A}; static const PY_UINT32_T mag01[2] = {0x0U, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */ /* mag01[x] = x * MATRIX_A for x=0,1 */
PY_UINT32_T *mt; PY_UINT32_T *mt;

View file

@ -1622,7 +1622,7 @@ pysqlite_connection_exit(pysqlite_Connection* self, PyObject* args)
Py_RETURN_FALSE; Py_RETURN_FALSE;
} }
static char connection_doc[] = static const char connection_doc[] =
PyDoc_STR("SQLite database connection object."); PyDoc_STR("SQLite database connection object.");
static PyGetSetDef connection_getset[] = { static PyGetSetDef connection_getset[] = {

View file

@ -27,7 +27,7 @@
PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self); PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self);
static char* errmsg_fetch_across_rollback = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from."; static const char errmsg_fetch_across_rollback[] = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from.";
static pysqlite_StatementKind detect_statement_type(const char* statement) static pysqlite_StatementKind detect_statement_type(const char* statement)
{ {
@ -1050,7 +1050,7 @@ static struct PyMemberDef cursor_members[] =
{NULL} {NULL}
}; };
static char cursor_doc[] = static const char cursor_doc[] =
PyDoc_STR("SQLite database cursor class."); PyDoc_STR("SQLite database cursor class.");
PyTypeObject pysqlite_CursorType = { PyTypeObject pysqlite_CursorType = {

View file

@ -261,13 +261,13 @@ static PyMethodDef module_methods[] = {
}; };
struct _IntConstantPair { struct _IntConstantPair {
char* constant_name; const char *constant_name;
int constant_value; int constant_value;
}; };
typedef struct _IntConstantPair IntConstantPair; typedef struct _IntConstantPair IntConstantPair;
static IntConstantPair _int_constants[] = { static const IntConstantPair _int_constants[] = {
{"PARSE_DECLTYPES", PARSE_DECLTYPES}, {"PARSE_DECLTYPES", PARSE_DECLTYPES},
{"PARSE_COLNAMES", PARSE_COLNAMES}, {"PARSE_COLNAMES", PARSE_COLNAMES},

View file

@ -35,7 +35,7 @@
* other compatibility work. * other compatibility work.
*/ */
static char copyright[] = static const char copyright[] =
" SRE 2.2.2 Copyright (c) 1997-2002 by Secret Labs AB "; " SRE 2.2.2 Copyright (c) 1997-2002 by Secret Labs AB ";
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN

View file

@ -723,7 +723,7 @@ np_void_p(char *p, PyObject *v, const formatdef *f)
return 0; return 0;
} }
static formatdef native_table[] = { static const formatdef native_table[] = {
{'x', sizeof(char), 0, NULL}, {'x', sizeof(char), 0, NULL},
{'b', sizeof(char), 0, nu_byte, np_byte}, {'b', sizeof(char), 0, nu_byte, np_byte},
{'B', sizeof(char), 0, nu_ubyte, np_ubyte}, {'B', sizeof(char), 0, nu_ubyte, np_ubyte},
@ -2280,7 +2280,7 @@ PyInit__struct(void)
/* Check endian and swap in faster functions */ /* Check endian and swap in faster functions */
{ {
formatdef *native = native_table; const formatdef *native = native_table;
formatdef *other, *ptr; formatdef *other, *ptr;
#if PY_LITTLE_ENDIAN #if PY_LITTLE_ENDIAN
other = lilendian_table; other = lilendian_table;

View file

@ -13,7 +13,7 @@ PyObject *Struct = NULL;
PyObject *calcsize = NULL; PyObject *calcsize = NULL;
/* cache simple format string */ /* cache simple format string */
static const char *simple_fmt = "B"; static const char simple_fmt[] = "B";
PyObject *simple_format = NULL; PyObject *simple_format = NULL;
#define SIMPLE_FORMAT(fmt) (fmt == NULL || strcmp(fmt, "B") == 0) #define SIMPLE_FORMAT(fmt) (fmt == NULL || strcmp(fmt, "B") == 0)
#define FIX_FORMAT(fmt) (fmt == NULL ? "B" : fmt) #define FIX_FORMAT(fmt) (fmt == NULL ? "B" : fmt)

View file

@ -887,7 +887,7 @@ static PyObject *
getargs_keywords(PyObject *self, PyObject *args, PyObject *kwargs) getargs_keywords(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL}; static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL};
static char *fmt="(ii)i|(i(ii))(iii)i"; static const char fmt[] = "(ii)i|(i(ii))(iii)i";
int int_args[10]={-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; int int_args[10]={-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
@ -3769,7 +3769,7 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
"T_LONGLONG", "T_ULONGLONG", "T_LONGLONG", "T_ULONGLONG",
#endif #endif
NULL}; NULL};
static char *fmt = "|bbBhHiIlknfds#" static const char fmt[] = "|bbBhHiIlknfds#"
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
"LK" "LK"
#endif #endif

View file

@ -31,7 +31,7 @@ struct arraydescr {
int itemsize; int itemsize;
PyObject * (*getitem)(struct arrayobject *, Py_ssize_t); PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *); int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
char *formats; const char *formats;
int is_integer_type; int is_integer_type;
int is_signed; int is_signed;
}; };
@ -40,7 +40,7 @@ typedef struct arrayobject {
PyObject_VAR_HEAD PyObject_VAR_HEAD
char *ob_item; char *ob_item;
Py_ssize_t allocated; Py_ssize_t allocated;
struct arraydescr *ob_descr; const struct arraydescr *ob_descr;
PyObject *weakreflist; /* List of weak references */ PyObject *weakreflist; /* List of weak references */
int ob_exports; /* Number of exported buffers */ int ob_exports; /* Number of exported buffers */
} arrayobject; } arrayobject;
@ -511,7 +511,7 @@ d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
* Don't forget to update typecode_to_mformat_code() if you add a new * Don't forget to update typecode_to_mformat_code() if you add a new
* typecode. * typecode.
*/ */
static struct arraydescr descriptors[] = { static const struct arraydescr descriptors[] = {
{'b', 1, b_getitem, b_setitem, "b", 1, 1}, {'b', 1, b_getitem, b_setitem, "b", 1, 1},
{'B', 1, BB_getitem, BB_setitem, "B", 1, 0}, {'B', 1, BB_getitem, BB_setitem, "B", 1, 0},
{'u', sizeof(Py_UNICODE), u_getitem, u_setitem, "u", 0, 0}, {'u', sizeof(Py_UNICODE), u_getitem, u_setitem, "u", 0, 0},
@ -539,7 +539,7 @@ class array.array "arrayobject *" "&Arraytype"
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ad43d37e942a8854]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ad43d37e942a8854]*/
static PyObject * static PyObject *
newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr) newarrayobject(PyTypeObject *type, Py_ssize_t size, const struct arraydescr *descr)
{ {
arrayobject *op; arrayobject *op;
size_t nbytes; size_t nbytes;
@ -1946,7 +1946,7 @@ array__array_reconstructor_impl(PyModuleDef *module, PyTypeObject *arraytype,
{ {
PyObject *converted_items; PyObject *converted_items;
PyObject *result; PyObject *result;
struct arraydescr *descr; const struct arraydescr *descr;
if (!PyType_Check(arraytype)) { if (!PyType_Check(arraytype)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
@ -2084,7 +2084,7 @@ array__array_reconstructor_impl(PyModuleDef *module, PyTypeObject *arraytype,
Py_ssize_t itemcount = Py_SIZE(items) / mf_descr.size; Py_ssize_t itemcount = Py_SIZE(items) / mf_descr.size;
const unsigned char *memstr = const unsigned char *memstr =
(unsigned char *)PyBytes_AS_STRING(items); (unsigned char *)PyBytes_AS_STRING(items);
struct arraydescr *descr; const struct arraydescr *descr;
/* If possible, try to pack array's items using a data type /* If possible, try to pack array's items using a data type
* that fits better. This may result in an array with narrower * that fits better. This may result in an array with narrower
@ -2554,7 +2554,7 @@ array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
view->format = NULL; view->format = NULL;
view->internal = NULL; view->internal = NULL;
if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) { if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) {
view->format = self->ob_descr->formats; view->format = (char *)self->ob_descr->formats;
#ifdef Py_UNICODE_WIDE #ifdef Py_UNICODE_WIDE
if (self->ob_descr->typecode == 'u') { if (self->ob_descr->typecode == 'u') {
view->format = "w"; view->format = "w";
@ -2595,7 +2595,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
int c; int c;
PyObject *initial = NULL, *it = NULL; PyObject *initial = NULL, *it = NULL;
struct arraydescr *descr; const struct arraydescr *descr;
if (type == &Arraytype && !_PyArg_NoKeywords("array.array()", kwds)) if (type == &Arraytype && !_PyArg_NoKeywords("array.array()", kwds))
return NULL; return NULL;
@ -2987,7 +2987,7 @@ array_modexec(PyObject *m)
char buffer[Py_ARRAY_LENGTH(descriptors)], *p; char buffer[Py_ARRAY_LENGTH(descriptors)], *p;
PyObject *typecodes; PyObject *typecodes;
Py_ssize_t size = 0; Py_ssize_t size = 0;
struct arraydescr *descr; const struct arraydescr *descr;
if (PyType_Ready(&Arraytype) < 0) if (PyType_Ready(&Arraytype) < 0)
return -1; return -1;

View file

@ -51,13 +51,15 @@ fbound(double val, double minval, double maxval)
#define SEG_SHIFT (4) /* Left shift for segment number. */ #define SEG_SHIFT (4) /* Left shift for segment number. */
#define SEG_MASK (0x70) /* Segment field mask. */ #define SEG_MASK (0x70) /* Segment field mask. */
static PyInt16 seg_aend[8] = {0x1F, 0x3F, 0x7F, 0xFF, static const PyInt16 seg_aend[8] = {
0x1FF, 0x3FF, 0x7FF, 0xFFF}; 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
static PyInt16 seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF, };
0x3FF, 0x7FF, 0xFFF, 0x1FFF}; static const PyInt16 seg_uend[8] = {
0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF
};
static PyInt16 static PyInt16
search(PyInt16 val, PyInt16 *table, int size) search(PyInt16 val, const PyInt16 *table, int size)
{ {
int i; int i;
@ -70,7 +72,7 @@ search(PyInt16 val, PyInt16 *table, int size)
#define st_ulaw2linear16(uc) (_st_ulaw2linear16[uc]) #define st_ulaw2linear16(uc) (_st_ulaw2linear16[uc])
#define st_alaw2linear16(uc) (_st_alaw2linear16[uc]) #define st_alaw2linear16(uc) (_st_alaw2linear16[uc])
static PyInt16 _st_ulaw2linear16[256] = { static const PyInt16 _st_ulaw2linear16[256] = {
-32124, -31100, -30076, -29052, -28028, -27004, -25980, -32124, -31100, -30076, -29052, -28028, -27004, -25980,
-24956, -23932, -22908, -21884, -20860, -19836, -18812, -24956, -23932, -22908, -21884, -20860, -19836, -18812,
-17788, -16764, -15996, -15484, -14972, -14460, -13948, -17788, -16764, -15996, -15484, -14972, -14460, -13948,
@ -176,7 +178,7 @@ st_14linear2ulaw(PyInt16 pcm_val) /* 2's complement (14-bit range) */
} }
static PyInt16 _st_alaw2linear16[256] = { static const PyInt16 _st_alaw2linear16[256] = {
-5504, -5248, -6016, -5760, -4480, -4224, -4992, -5504, -5248, -6016, -5760, -4480, -4224, -4992,
-4736, -7552, -7296, -8064, -7808, -6528, -6272, -4736, -7552, -7296, -8064, -7808, -6528, -6272,
-7040, -6784, -2752, -2624, -3008, -2880, -2240, -7040, -6784, -2752, -2624, -3008, -2880, -2240,
@ -270,12 +272,12 @@ st_linear2alaw(PyInt16 pcm_val) /* 2's complement (13-bit range) */
/* End of code taken from sox */ /* End of code taken from sox */
/* Intel ADPCM step variation table */ /* Intel ADPCM step variation table */
static int indexTable[16] = { static const int indexTable[16] = {
-1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8,
}; };
static int stepsizeTable[89] = { static const int stepsizeTable[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,

View file

@ -74,7 +74,7 @@ static PyObject *Incomplete;
#define SKIP 0x7E #define SKIP 0x7E
#define FAIL 0x7D #define FAIL 0x7D
static unsigned char table_a2b_hqx[256] = { static const unsigned char table_a2b_hqx[256] = {
/* ^@ ^A ^B ^C ^D ^E ^F ^G */ /* ^@ ^A ^B ^C ^D ^E ^F ^G */
/* 0*/ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, /* 0*/ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
/* \b \t \n ^K ^L \r ^N ^O */ /* \b \t \n ^K ^L \r ^N ^O */
@ -125,10 +125,10 @@ static unsigned char table_a2b_hqx[256] = {
FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
}; };
static unsigned char table_b2a_hqx[] = static const unsigned char table_b2a_hqx[] =
"!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"; "!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr";
static char table_a2b_base64[] = { static const char table_a2b_base64[] = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
@ -144,12 +144,12 @@ static char table_a2b_base64[] = {
/* Max binary chunk size; limited only by available memory */ /* Max binary chunk size; limited only by available memory */
#define BASE64_MAXBIN ((PY_SSIZE_T_MAX - 3) / 2) #define BASE64_MAXBIN ((PY_SSIZE_T_MAX - 3) / 2)
static unsigned char table_b2a_base64[] = static const unsigned char table_b2a_base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static unsigned short crctab_hqx[256] = { static const unsigned short crctab_hqx[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
@ -977,7 +977,7 @@ binascii_crc_hqx_impl(PyModuleDef *module, Py_buffer *data, unsigned int crc)
using byte-swap instructions. using byte-swap instructions.
********************************************************************/ ********************************************************************/
static unsigned int crc_32_tab[256] = { static const unsigned int crc_32_tab[256] = {
0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U, 0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U, 0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U, 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
@ -1201,7 +1201,7 @@ binascii_unhexlify_impl(PyModuleDef *module, Py_buffer *hexstr)
return binascii_a2b_hex_impl(module, hexstr); return binascii_a2b_hex_impl(module, hexstr);
} }
static int table_hex[128] = { static const int table_hex[128] = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,

View file

@ -136,7 +136,7 @@ static int get_addr(const char *, int, struct addrinfo **,
struct addrinfo *, int); struct addrinfo *, int);
static int str_isnumber(const char *); static int str_isnumber(const char *);
static char *ai_errlist[] = { static const char * const ai_errlist[] = {
"success.", "success.",
"address family for hostname not supported.", /* EAI_ADDRFAMILY */ "address family for hostname not supported.", /* EAI_ADDRFAMILY */
"temporary failure in name resolution.", /* EAI_AGAIN */ "temporary failure in name resolution.", /* EAI_AGAIN */

View file

@ -477,8 +477,8 @@ calculate_path(void)
{ {
extern wchar_t *Py_GetProgramName(void); extern wchar_t *Py_GetProgramName(void);
static wchar_t delimiter[2] = {DELIM, '\0'}; static const wchar_t delimiter[2] = {DELIM, '\0'};
static wchar_t separator[2] = {SEP, '\0'}; static const wchar_t separator[2] = {SEP, '\0'};
char *_rtpypath = Py_GETENV("PYTHONPATH"); /* XXX use wide version on Windows */ char *_rtpypath = Py_GETENV("PYTHONPATH"); /* XXX use wide version on Windows */
wchar_t *rtpypath = NULL; wchar_t *rtpypath = NULL;
wchar_t *home = Py_GetPythonHome(); wchar_t *home = Py_GetPythonHome();

View file

@ -42,11 +42,11 @@ static int orig_argc;
#define PROGRAM_OPTS BASE_OPTS #define PROGRAM_OPTS BASE_OPTS
/* Short usage message (with %s for argv0) */ /* Short usage message (with %s for argv0) */
static char *usage_line = static const char usage_line[] =
"usage: %ls [option] ... [-c cmd | -m mod | file | -] [arg] ...\n"; "usage: %ls [option] ... [-c cmd | -m mod | file | -] [arg] ...\n";
/* Long usage message, split into parts < 512 bytes */ /* Long usage message, split into parts < 512 bytes */
static char *usage_1 = "\ static const char usage_1[] = "\
Options and arguments (and corresponding environment variables):\n\ Options and arguments (and corresponding environment variables):\n\
-b : issue warnings about str(bytes_instance), str(bytearray_instance)\n\ -b : issue warnings about str(bytes_instance), str(bytearray_instance)\n\
and comparing bytes/bytearray with str. (-bb: issue errors)\n\ and comparing bytes/bytearray with str. (-bb: issue errors)\n\
@ -56,7 +56,7 @@ Options and arguments (and corresponding environment variables):\n\
-E : ignore PYTHON* environment variables (such as PYTHONPATH)\n\ -E : ignore PYTHON* environment variables (such as PYTHONPATH)\n\
-h : print this help message and exit (also --help)\n\ -h : print this help message and exit (also --help)\n\
"; ";
static char *usage_2 = "\ static const char usage_2[] = "\
-i : inspect interactively after running script; forces a prompt even\n\ -i : inspect interactively after running script; forces a prompt even\n\
if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\ if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
-I : isolate Python from the user's environment (implies -E and -s)\n\ -I : isolate Python from the user's environment (implies -E and -s)\n\
@ -67,7 +67,7 @@ static char *usage_2 = "\
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\ -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
-S : don't imply 'import site' on initialization\n\ -S : don't imply 'import site' on initialization\n\
"; ";
static char *usage_3 = "\ static const char usage_3[] = "\
-u : unbuffered binary stdout and stderr, stdin always buffered;\n\ -u : unbuffered binary stdout and stderr, stdin always buffered;\n\
also PYTHONUNBUFFERED=x\n\ also PYTHONUNBUFFERED=x\n\
see man page for details on internal buffering relating to '-u'\n\ see man page for details on internal buffering relating to '-u'\n\
@ -79,7 +79,7 @@ static char *usage_3 = "\
-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\ -x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
-X opt : set implementation-specific option\n\ -X opt : set implementation-specific option\n\
"; ";
static char *usage_4 = "\ static const char usage_4[] = "\
file : program read from script file\n\ file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\ - : program read from stdin (default; interactive mode if a tty)\n\
arg ...: arguments passed to program in sys.argv[1:]\n\n\ arg ...: arguments passed to program in sys.argv[1:]\n\n\
@ -88,14 +88,14 @@ PYTHONSTARTUP: file executed on interactive startup (no default)\n\
PYTHONPATH : '%c'-separated list of directories prefixed to the\n\ PYTHONPATH : '%c'-separated list of directories prefixed to the\n\
default module search path. The result is sys.path.\n\ default module search path. The result is sys.path.\n\
"; ";
static char *usage_5 = static const char usage_5[] =
"PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n" "PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n"
" The default module search path uses %s.\n" " The default module search path uses %s.\n"
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n" "PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n" "PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n"
"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n\ "PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n\
"; ";
static char *usage_6 = "\ static const char usage_6[] = "\
PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n\ PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n\
to seed the hashes of str, bytes and datetime objects. It can also be\n\ to seed the hashes of str, bytes and datetime objects. It can also be\n\
set to an integer in the range [0,4294967295] to get hash values with a\n\ set to an integer in the range [0,4294967295] to get hash values with a\n\

View file

@ -53,7 +53,7 @@ extern grammar _PyParser_Grammar; /* From graminit.c */
/* String constants used to initialize module attributes. /* String constants used to initialize module attributes.
* *
*/ */
static char parser_copyright_string[] = static const char parser_copyright_string[] =
"Copyright 1995-1996 by Virginia Polytechnic Institute & State\n\ "Copyright 1995-1996 by Virginia Polytechnic Institute & State\n\
University, Blacksburg, Virginia, USA, and Fred L. Drake, Jr., Reston,\n\ University, Blacksburg, Virginia, USA, and Fred L. Drake, Jr., Reston,\n\
Virginia, USA. Portions copyright 1991-1995 by Stichting Mathematisch\n\ Virginia, USA. Portions copyright 1991-1995 by Stichting Mathematisch\n\
@ -63,7 +63,7 @@ Centrum, Amsterdam, The Netherlands.";
PyDoc_STRVAR(parser_doc_string, PyDoc_STRVAR(parser_doc_string,
"This is an interface to Python's internal parser."); "This is an interface to Python's internal parser.");
static char parser_version_string[] = "0.5"; static const char parser_version_string[] = "0.5";
typedef PyObject* (*SeqMaker) (Py_ssize_t length); typedef PyObject* (*SeqMaker) (Py_ssize_t length);

View file

@ -9479,7 +9479,7 @@ os__getdiskusage_impl(PyModuleDef *module, Py_UNICODE *path)
* sufficiently pervasive that it's not worth the loss of readability. * sufficiently pervasive that it's not worth the loss of readability.
*/ */
struct constdef { struct constdef {
char *name; const char *name;
int value; int value;
}; };
@ -10822,7 +10822,7 @@ os_getxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute,
for (i = 0; ; i++) { for (i = 0; ; i++) {
void *ptr; void *ptr;
ssize_t result; ssize_t result;
static Py_ssize_t buffer_sizes[] = {128, XATTR_SIZE_MAX, 0}; static const Py_ssize_t buffer_sizes[] = {128, XATTR_SIZE_MAX, 0};
Py_ssize_t buffer_size = buffer_sizes[i]; Py_ssize_t buffer_size = buffer_sizes[i];
if (!buffer_size) { if (!buffer_size) {
path_error(path); path_error(path);
@ -10988,7 +10988,7 @@ os_listxattr_impl(PyModuleDef *module, path_t *path, int follow_symlinks)
for (i = 0; ; i++) { for (i = 0; ; i++) {
char *start, *trace, *end; char *start, *trace, *end;
ssize_t length; ssize_t length;
static Py_ssize_t buffer_sizes[] = { 256, XATTR_LIST_MAX, 0 }; static const Py_ssize_t buffer_sizes[] = { 256, XATTR_LIST_MAX, 0 };
Py_ssize_t buffer_size = buffer_sizes[i]; Py_ssize_t buffer_size = buffer_sizes[i];
if (!buffer_size) { if (!buffer_size) {
/* ERANGE */ /* ERANGE */
@ -12821,7 +12821,7 @@ static struct PyModuleDef posixmodule = {
}; };
static char *have_functions[] = { static const char * const have_functions[] = {
#ifdef HAVE_FACCESSAT #ifdef HAVE_FACCESSAT
"HAVE_FACCESSAT", "HAVE_FACCESSAT",
@ -12956,7 +12956,7 @@ INITFUNC(void)
{ {
PyObject *m, *v; PyObject *m, *v;
PyObject *list; PyObject *list;
char **trace; const char * const *trace;
#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS) #if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
win32_can_symlink = enable_symlink(); win32_can_symlink = enable_symlink();

View file

@ -1842,7 +1842,7 @@ kqueue_event_init(kqueue_event_Object *self, PyObject *args, PyObject *kwds)
PyObject *pfd; PyObject *pfd;
static char *kwlist[] = {"ident", "filter", "flags", "fflags", static char *kwlist[] = {"ident", "filter", "flags", "fflags",
"data", "udata", NULL}; "data", "udata", NULL};
static char *fmt = "O|hHI" DATA_FMT_UNIT UINTPTRT_FMT_UNIT ":kevent"; static const char fmt[] = "O|hHI" DATA_FMT_UNIT UINTPTRT_FMT_UNIT ":kevent";
EV_SET(&(self->e), 0, EVFILT_READ, EV_ADD, 0, 0, 0); /* defaults */ EV_SET(&(self->e), 0, EVFILT_READ, EV_ADD, 0, 0, 0); /* defaults */

View file

@ -732,10 +732,10 @@ _asctime(struct tm *timeptr)
{ {
/* Inspired by Open Group reference implementation available at /* Inspired by Open Group reference implementation available at
* http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html */ * http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html */
static char wday_name[7][4] = { static const char wday_name[7][4] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
}; };
static char mon_name[12][4] = { static const char mon_name[12][4] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}; };

View file

@ -884,7 +884,7 @@ _gethash(const char *s, int len, int scale)
return h; return h;
} }
static char *hangul_syllables[][3] = { static const char * const hangul_syllables[][3] = {
{ "G", "A", "" }, { "G", "A", "" },
{ "GG", "AE", "G" }, { "GG", "AE", "G" },
{ "N", "YA", "GG" }, { "N", "YA", "GG" },
@ -1057,7 +1057,7 @@ find_syllable(const char *str, int *len, int *pos, int count, int column)
int i, len1; int i, len1;
*len = -1; *len = -1;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
char *s = hangul_syllables[i][column]; const char *s = hangul_syllables[i][column];
len1 = Py_SAFE_DOWNCAST(strlen(s), size_t, int); len1 = Py_SAFE_DOWNCAST(strlen(s), size_t, int);
if (len1 <= *len) if (len1 <= *len)
continue; continue;

View file

@ -644,7 +644,7 @@ PyObject_Bytes(PyObject *v)
/* Map rich comparison operators to their swapped version, e.g. LT <--> GT */ /* Map rich comparison operators to their swapped version, e.g. LT <--> GT */
int _Py_SwappedOp[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE}; int _Py_SwappedOp[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
static char *opstrings[] = {"<", "<=", "==", "!=", ">", ">="}; static const char * const opstrings[] = {"<", "<=", "==", "!=", ">", ">="};
/* Perform a rich comparison, raising TypeError when the requested comparison /* Perform a rich comparison, raising TypeError when the requested comparison
operator is not supported. */ operator is not supported. */

View file

@ -4,9 +4,9 @@
#include "Python.h" #include "Python.h"
#include "structmember.h" #include "structmember.h"
static char visible_length_key[] = "n_sequence_fields"; static const char visible_length_key[] = "n_sequence_fields";
static char real_length_key[] = "n_fields"; static const char real_length_key[] = "n_fields";
static char unnamed_fields_key[] = "n_unnamed_fields"; static const char unnamed_fields_key[] = "n_unnamed_fields";
/* Fields with this name have only a field index, not a field name. /* Fields with this name have only a field index, not a field name.
They are only allowed for indices < n_visible_fields. */ They are only allowed for indices < n_visible_fields. */

View file

@ -2690,7 +2690,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
return NULL; return NULL;
} }
static short slotoffsets[] = { static const short slotoffsets[] = {
-1, /* invalid slot */ -1, /* invalid slot */
#include "typeslots.inc" #include "typeslots.inc"
}; };

View file

@ -272,7 +272,7 @@ raise_encode_exception(PyObject **exceptionObject,
const char *reason); const char *reason);
/* Same for linebreaks */ /* Same for linebreaks */
static unsigned char ascii_linebreak[] = { static const unsigned char ascii_linebreak[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x000A, * LINE FEED */ /* 0x000A, * LINE FEED */
/* 0x000B, * LINE TABULATION */ /* 0x000B, * LINE TABULATION */
@ -4135,7 +4135,7 @@ unicode_decode_call_errorhandler_wchar(
Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr, Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr,
PyObject **output, Py_ssize_t *outpos) PyObject **output, Py_ssize_t *outpos)
{ {
static char *argparse = "O!n;decoding error handler must return (str, int) tuple"; static const char *argparse = "O!n;decoding error handler must return (str, int) tuple";
PyObject *restuple = NULL; PyObject *restuple = NULL;
PyObject *repunicode = NULL; PyObject *repunicode = NULL;
@ -4243,7 +4243,7 @@ unicode_decode_call_errorhandler_writer(
Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr, Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr,
_PyUnicodeWriter *writer /* PyObject **output, Py_ssize_t *outpos */) _PyUnicodeWriter *writer /* PyObject **output, Py_ssize_t *outpos */)
{ {
static char *argparse = "O!n;decoding error handler must return (str, int) tuple"; static const char *argparse = "O!n;decoding error handler must return (str, int) tuple";
PyObject *restuple = NULL; PyObject *restuple = NULL;
PyObject *repunicode = NULL; PyObject *repunicode = NULL;
@ -6560,7 +6560,7 @@ unicode_encode_call_errorhandler(const char *errors,
Py_ssize_t startpos, Py_ssize_t endpos, Py_ssize_t startpos, Py_ssize_t endpos,
Py_ssize_t *newpos) Py_ssize_t *newpos)
{ {
static char *argparse = "On;encoding error handler must return (str/bytes, int) tuple"; static const char *argparse = "On;encoding error handler must return (str/bytes, int) tuple";
Py_ssize_t len; Py_ssize_t len;
PyObject *restuple; PyObject *restuple;
PyObject *resunicode; PyObject *resunicode;
@ -8572,7 +8572,7 @@ unicode_translate_call_errorhandler(const char *errors,
Py_ssize_t startpos, Py_ssize_t endpos, Py_ssize_t startpos, Py_ssize_t endpos,
Py_ssize_t *newpos) Py_ssize_t *newpos)
{ {
static char *argparse = "O!n;translating error handler must return (str, int) tuple"; static const char *argparse = "O!n;translating error handler must return (str, int) tuple";
Py_ssize_t i_newpos; Py_ssize_t i_newpos;
PyObject *restuple; PyObject *restuple;
@ -12156,7 +12156,7 @@ unicode_lower(PyObject *self)
#define BOTHSTRIP 2 #define BOTHSTRIP 2
/* Arrays indexed by above */ /* Arrays indexed by above */
static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"}; static const char * const stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
#define STRIPNAME(i) (stripformat[i]+3) #define STRIPNAME(i) (stripformat[i]+3)

View file

@ -161,10 +161,10 @@ PyParser_ParseFileFlagsEx(FILE *fp, const char *filename,
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
#if 0 #if 0
static char with_msg[] = static const char with_msg[] =
"%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n"; "%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n";
static char as_msg[] = static const char as_msg[] =
"%s:%d: Warning: 'as' will become a reserved keyword in Python 2.6\n"; "%s:%d: Warning: 'as' will become a reserved keyword in Python 2.6\n";
static void static void

View file

@ -134,7 +134,7 @@ addnfa(nfagrammar *gr, char *name)
#ifdef Py_DEBUG #ifdef Py_DEBUG
static char REQNFMT[] = "metacompile: less than %d children\n"; static const char REQNFMT[] = "metacompile: less than %d children\n";
#define REQN(i, count) do { \ #define REQN(i, count) do { \
if (i < count) { \ if (i < count) { \

View file

@ -870,7 +870,7 @@ get_operator(const node *n)
} }
} }
static const char* FORBIDDEN[] = { static const char * const FORBIDDEN[] = {
"None", "None",
"True", "True",
"False", "False",
@ -887,7 +887,7 @@ forbidden_name(struct compiling *c, identifier name, const node *n,
return 1; return 1;
} }
if (full_checks) { if (full_checks) {
const char **p; const char * const *p;
for (p = FORBIDDEN; *p; p++) { for (p = FORBIDDEN; *p; p++) {
if (PyUnicode_CompareWithASCIIString(name, *p) == 0) { if (PyUnicode_CompareWithASCIIString(name, *p) == 0) {
ast_error(c, n, "assignment to keyword"); ast_error(c, n, "assignment to keyword");

View file

@ -747,7 +747,7 @@ pow5mult(Bigint *b, int k)
{ {
Bigint *b1, *p5, *p51; Bigint *b1, *p5, *p51;
int i; int i;
static int p05[3] = { 5, 25, 125 }; static const int p05[3] = { 5, 25, 125 };
if ((i = k & 3)) { if ((i = k & 3)) {
b = multadd(b, p05[i-1], 0); b = multadd(b, p05[i-1], 0);
@ -803,7 +803,7 @@ pow5mult(Bigint *b, int k)
{ {
Bigint *b1, *p5, *p51; Bigint *b1, *p5, *p51;
int i; int i;
static int p05[3] = { 5, 25, 125 }; static const int p05[3] = { 5, 25, 125 };
if ((i = k & 3)) { if ((i = k & 3)) {
b = multadd(b, p05[i-1], 0); b = multadd(b, p05[i-1], 0);

View file

@ -656,7 +656,7 @@ fill_number(_PyUnicodeWriter *writer, const NumberFieldWidths *spec,
return 0; 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 /* Find the decimal point character(s?), thousands_separator(s?), and
grouping description, either for the current locale if type is 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 */ /* List of names to clear in sys */
static char* sys_deletes[] = { static const char * const sys_deletes[] = {
"path", "argv", "ps1", "ps2", "path", "argv", "ps1", "ps2",
"last_type", "last_value", "last_traceback", "last_type", "last_value", "last_traceback",
"path_hooks", "path_importer_cache", "meta_path", "path_hooks", "path_importer_cache", "meta_path",
@ -330,7 +330,7 @@ static char* sys_deletes[] = {
NULL NULL
}; };
static char* sys_files[] = { static const char * const sys_files[] = {
"stdin", "__stdin__", "stdin", "__stdin__",
"stdout", "__stdout__", "stdout", "__stdout__",
"stderr", "__stderr__", "stderr", "__stderr__",
@ -347,7 +347,7 @@ PyImport_Cleanup(void)
PyInterpreterState *interp = PyThreadState_GET()->interp; PyInterpreterState *interp = PyThreadState_GET()->interp;
PyObject *modules = interp->modules; PyObject *modules = interp->modules;
PyObject *weaklist = NULL; PyObject *weaklist = NULL;
char **p; const char * const *p;
if (modules == NULL) if (modules == NULL)
return; /* Already done */ return; /* Already done */

View file

@ -23,8 +23,8 @@ extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
const char *pathname, FILE *fp); const char *pathname, FILE *fp);
#endif #endif
static const char *ascii_only_prefix = "PyInit"; static const char * const ascii_only_prefix = "PyInit";
static const char *nonascii_prefix = "PyInitU"; static const char * const nonascii_prefix = "PyInitU";
/* Get the variable part of a module's export symbol name. /* Get the variable part of a module's export symbol name.
* Returns a bytes instance. For non-ASCII-named modules, the name is * 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 * smallmax[base] is the largest unsigned long i such that
* i * base doesn't overflow unsigned long. * i * base doesn't overflow unsigned long.
*/ */
static unsigned long smallmax[] = { static const unsigned long smallmax[] = {
0, /* bases 0 and 1 are invalid */ 0, /* bases 0 and 1 are invalid */
0, 0,
ULONG_MAX / 2, ULONG_MAX / 2,
@ -62,14 +62,14 @@ static unsigned long smallmax[] = {
* Note that this is pessimistic if sizeof(long) > 4. * Note that this is pessimistic if sizeof(long) > 4.
*/ */
#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 */ 0, 0, 32, 20, 16, 13, 12, 11, 10, 10, /* 0 - 9 */
9, 9, 8, 8, 8, 8, 8, 7, 7, 7, /* 10 - 19 */ 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, /* 10 - 19 */
7, 7, 7, 7, 6, 6, 6, 6, 6, 6, /* 20 - 29 */ 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, /* 20 - 29 */
6, 6, 6, 6, 6, 6, 6}; /* 30 - 36 */ 6, 6, 6, 6, 6, 6, 6}; /* 30 - 36 */
#elif SIZEOF_LONG == 8 #elif SIZEOF_LONG == 8
/* [int(math.floor(math.log(2**64, i))) for i in range(2, 37)] */ /* [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 */ 0, 0, 64, 40, 32, 27, 24, 22, 21, 20, /* 0 - 9 */
19, 18, 17, 17, 16, 16, 16, 15, 15, 15, /* 10 - 19 */ 19, 18, 17, 17, 16, 16, 16, 15, 15, 15, /* 10 - 19 */
14, 14, 14, 14, 13, 13, 13, 13, 13, 13, /* 20 - 29 */ 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 #define OFS_E 2
/* The lengths of these are known to the code below, so don't change them */ /* 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", "inf",
"nan", "nan",
"e", "e",
}; };
static char *uc_float_strings[] = { static const char * const uc_float_strings[] = {
"INF", "INF",
"NAN", "NAN",
"E", "E",
@ -925,7 +925,8 @@ static char *
format_float_short(double d, char format_code, format_float_short(double d, char format_code,
int mode, int precision, int mode, int precision,
int always_add_sign, int add_dot_0_if_integer, 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 *buf = NULL;
char *p = NULL; char *p = NULL;
@ -1176,7 +1177,7 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
int flags, int flags,
int *type) int *type)
{ {
char **float_strings = lc_float_strings; const char * const *float_strings = lc_float_strings;
int mode; int mode;
/* Validate format_code, and map upper and lower case. Compute the /* 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(); PyErr_Clear();
} }
static const char *cause_message = static const char cause_message[] =
"\nThe above exception was the direct cause " "\nThe above exception was the direct cause "
"of the following exception:\n\n"; "of the following exception:\n\n";
static const char *context_message = static const char context_message[] =
"\nDuring handling of the above exception, " "\nDuring handling of the above exception, "
"another exception occurred:\n\n"; "another exception occurred:\n\n";

View file

@ -346,8 +346,10 @@ static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
static int static int
trace_init(void) trace_init(void)
{ {
static char *whatnames[7] = {"call", "exception", "line", "return", static const char * const whatnames[7] = {
"c_call", "c_exception", "c_return"}; "call", "exception", "line", "return",
"c_call", "c_exception", "c_return"
};
PyObject *name; PyObject *name;
int i; int i;
for (i = 0; i < 7; ++i) { for (i = 0; i < 7; ++i) {