Skip to content

Commit

Permalink
Issue python#25923: Added the const qualifier to static constant arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Dec 25, 2015
1 parent ea8c431 commit 2d06e84
Show file tree
Hide file tree
Showing 44 changed files with 139 additions and 134 deletions.
4 changes: 2 additions & 2 deletions Include/py_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ static void **PyCurses_API;
#endif

/* general error messages */
static char *catchall_ERR = "curses function returned ERR";
static char *catchall_NULL = "curses function returned NULL";
static const char catchall_ERR[] = "curses function returned ERR";
static const char catchall_NULL[] = "curses function returned NULL";

/* Function Prototype Macros - They are ugly but very, very useful. ;-)
Expand Down
2 changes: 1 addition & 1 deletion Include/pymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
#pragma float_control (pop)
#define Py_NAN __icc_nan()
#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)
#endif /* ICC_NAN_STRICT */
#endif /* __INTEL_COMPILER */
Expand Down
8 changes: 4 additions & 4 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ typedef enum {

typedef struct {
QuoteStyle style;
char *name;
const char *name;
} StyleDesc;

static StyleDesc quote_styles[] = {
static const StyleDesc quote_styles[] = {
{ QUOTE_MINIMAL, "QUOTE_MINIMAL" },
{ QUOTE_ALL, "QUOTE_ALL" },
{ QUOTE_NONNUMERIC, "QUOTE_NONNUMERIC" },
Expand Down Expand Up @@ -286,7 +286,7 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
static int
dialect_check_quoting(int quoting)
{
StyleDesc *qs;
const StyleDesc *qs;

for (qs = quote_styles; qs->name; qs++) {
if ((int)qs->style == quoting)
Expand Down Expand Up @@ -1633,7 +1633,7 @@ PyMODINIT_FUNC
PyInit__csv(void)
{
PyObject *module;
StyleDesc *style;
const StyleDesc *style;

if (PyType_Ready(&Dialect_Type) < 0)
return NULL;
Expand Down
14 changes: 7 additions & 7 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ UnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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";

static PyObject *
Expand All @@ -453,7 +453,7 @@ CDataType_from_address(PyObject *type, PyObject *value)
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";

static int
Expand Down Expand Up @@ -524,7 +524,7 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
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";

static PyObject *
Expand Down Expand Up @@ -566,7 +566,7 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
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";

static PyObject *
Expand Down Expand Up @@ -623,7 +623,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
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.";

static PyObject *
Expand Down Expand Up @@ -1481,7 +1481,7 @@ _type_ attribute.
*/

static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv?g";
static const char SIMPLE_TYPE_CHARS[] = "cbBhHiIlLdfuzZqQPXOv?g";

static PyObject *
c_wchar_p_from_param(PyObject *type, PyObject *value)
Expand Down Expand Up @@ -5118,7 +5118,7 @@ static const char module_docs[] =

#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
comerror_init(PyObject *self, PyObject *args, PyObject *kwds)
Expand Down
16 changes: 8 additions & 8 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ _parse_voidp(PyObject *obj, void **address)

#ifdef MS_WIN32

static char format_error_doc[] =
static const char format_error_doc[] =
"FormatError([integer]) -> string\n\
\n\
Convert a win32 error code into a string. If the error code is not\n\
Expand All @@ -1225,7 +1225,7 @@ static PyObject *format_error(PyObject *self, PyObject *args)
return result;
}

static char load_library_doc[] =
static const char load_library_doc[] =
"LoadLibrary(name) -> handle\n\
\n\
Load an executable (usually a DLL), and return a handle to it.\n\
Expand Down Expand Up @@ -1254,7 +1254,7 @@ static PyObject *load_library(PyObject *self, PyObject *args)
#endif
}

static char free_library_doc[] =
static const char free_library_doc[] =
"FreeLibrary(handle) -> void\n\
\n\
Free the handle of an executable previously loaded by LoadLibrary.\n";
Expand All @@ -1269,7 +1269,7 @@ static PyObject *free_library(PyObject *self, PyObject *args)
return Py_None;
}

static char copy_com_pointer_doc[] =
static const char copy_com_pointer_doc[] =
"CopyComPointer(src, dst) -> HRESULT value\n";

static PyObject *
Expand Down Expand Up @@ -1439,7 +1439,7 @@ call_cdeclfunction(PyObject *self, PyObject *args)
/*****************************************************************
* functions
*/
static char sizeof_doc[] =
static const char sizeof_doc[] =
"sizeof(C type) -> integer\n"
"sizeof(C instance) -> integer\n"
"Return the size in bytes of a C instance";
Expand All @@ -1460,7 +1460,7 @@ sizeof_func(PyObject *self, PyObject *obj)
return NULL;
}

static char alignment_doc[] =
static const char alignment_doc[] =
"alignment(C type) -> integer\n"
"alignment(C instance) -> integer\n"
"Return the alignment requirements of a C instance";
Expand All @@ -1483,7 +1483,7 @@ align_func(PyObject *self, PyObject *obj)
return NULL;
}

static char byref_doc[] =
static const char byref_doc[] =
"byref(C instance[, offset=0]) -> byref-object\n"
"Return a pointer lookalike to a C instance, only usable\n"
"as function argument";
Expand Down Expand Up @@ -1527,7 +1527,7 @@ byref(PyObject *self, PyObject *args)
return (PyObject *)parg;
}

static char addressof_doc[] =
static const char addressof_doc[] =
"addressof(C instance) -> integer\n"
"Return the address of the C instance internal buffer";

Expand Down
2 changes: 1 addition & 1 deletion Modules/_curses_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* Release Number */

static char *PyCursesVersion = "2.1";
static const char PyCursesVersion[] = "2.1";

/* Includes */

Expand Down
20 changes: 10 additions & 10 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ divide_nearest(PyObject *m, PyObject *n)
* and the number of days before that month in the same year. These
* 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 */
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, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
};
Expand Down Expand Up @@ -1009,10 +1009,10 @@ append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo)
static PyObject *
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"
};
static const char *MonthNames[] = {
static const char * const MonthNames[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
Expand Down Expand Up @@ -2307,7 +2307,7 @@ static PyMethodDef delta_methods[] = {
{NULL, NULL},
};

static char delta_doc[] =
static const char delta_doc[] =
PyDoc_STR("Difference between two datetime values.");

static PyNumberMethods delta_as_number = {
Expand Down Expand Up @@ -2886,7 +2886,7 @@ static PyMethodDef date_methods[] = {
{NULL, NULL}
};

static char date_doc[] =
static const char date_doc[] =
PyDoc_STR("date(year, month, day) --> date object");

static PyNumberMethods date_as_number = {
Expand Down Expand Up @@ -3155,7 +3155,7 @@ static PyMethodDef tzinfo_methods[] = {
{NULL, NULL}
};

static char tzinfo_doc[] =
static const char tzinfo_doc[] =
PyDoc_STR("Abstract base class for time zone info objects.");

static PyTypeObject PyDateTime_TZInfoType = {
Expand Down Expand Up @@ -3387,7 +3387,7 @@ static PyMethodDef timezone_methods[] = {
{NULL, NULL}
};

static char timezone_doc[] =
static const char timezone_doc[] =
PyDoc_STR("Fixed offset from UTC implementation of tzinfo.");

static PyTypeObject PyDateTime_TimeZoneType = {
Expand Down Expand Up @@ -3877,7 +3877,7 @@ static PyMethodDef time_methods[] = {
{NULL, NULL}
};

static char time_doc[] =
static const char time_doc[] =
PyDoc_STR("time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object\n\
\n\
All arguments are optional. tzinfo may be None, or an instance of\n\
Expand Down Expand Up @@ -5065,7 +5065,7 @@ static PyMethodDef datetime_methods[] = {
{NULL, NULL}
};

static char datetime_doc[] =
static const char datetime_doc[] =
PyDoc_STR("datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])\n\
\n\
The year, month and day arguments are required. tzinfo may be None, or an\n\
Expand Down
8 changes: 4 additions & 4 deletions Modules/_dbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
*/
#if defined(HAVE_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)
#include <gdbm/ndbm.h>
static char *which_dbm = "GNU gdbm";
static const char which_dbm[] = "GNU gdbm";
#elif defined(HAVE_GDBM_DASH_NDBM_H)
#include <gdbm-ndbm.h>
static char *which_dbm = "GNU gdbm";
static const char which_dbm[] = "GNU gdbm";
#elif defined(HAVE_BERKDB_H)
#include <db.h>
static char *which_dbm = "Berkeley DB";
static const char which_dbm[] = "Berkeley DB";
#else
#error "No ndbm.h available!"
#endif
Expand Down
2 changes: 1 addition & 1 deletion Modules/_gdbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ dbmopen_impl(PyModuleDef *module, const char *name, const char *flags,
return newdbmobject(name, iflags, mode);
}

static char dbmmodule_open_flags[] = "rwcn"
static const char dbmmodule_open_flags[] = "rwcn"
#ifdef GDBM_FAST
"f"
#endif
Expand Down
4 changes: 2 additions & 2 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ typedef struct {
encodefunc_t encodefunc;
} encodefuncentry;

static encodefuncentry encodefuncs[] = {
static const encodefuncentry encodefuncs[] = {
{"ascii", (encodefunc_t) ascii_encode},
{"iso8859-1", (encodefunc_t) latin1_encode},
{"utf-8", (encodefunc_t) utf8_encode},
Expand Down Expand Up @@ -1022,7 +1022,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
goto error;
}
else if (PyUnicode_Check(res)) {
encodefuncentry *e = encodefuncs;
const encodefuncentry *e = encodefuncs;
while (e->name != NULL) {
if (!PyUnicode_CompareWithASCIIString(res, e->name)) {
self->encodefunc = e->encodefunc;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_randommodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static PY_UINT32_T
genrand_int32(RandomObject *self)
{
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 */
PY_UINT32_T *mt;

Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ pysqlite_connection_exit(pysqlite_Connection* self, PyObject* args)
Py_RETURN_FALSE;
}

static char connection_doc[] =
static const char connection_doc[] =
PyDoc_STR("SQLite database connection object.");

static PyGetSetDef connection_getset[] = {
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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)
{
Expand Down Expand Up @@ -1050,7 +1050,7 @@ static struct PyMemberDef cursor_members[] =
{NULL}
};

static char cursor_doc[] =
static const char cursor_doc[] =
PyDoc_STR("SQLite database cursor class.");

PyTypeObject pysqlite_CursorType = {
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ static PyMethodDef module_methods[] = {
};

struct _IntConstantPair {
char* constant_name;
const char *constant_name;
int constant_value;
};

typedef struct _IntConstantPair IntConstantPair;

static IntConstantPair _int_constants[] = {
static const IntConstantPair _int_constants[] = {
{"PARSE_DECLTYPES", PARSE_DECLTYPES},
{"PARSE_COLNAMES", PARSE_COLNAMES},

Expand Down
2 changes: 1 addition & 1 deletion Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* other compatibility work.
*/

static char copyright[] =
static const char copyright[] =
" SRE 2.2.2 Copyright (c) 1997-2002 by Secret Labs AB ";

#define PY_SSIZE_T_CLEAN
Expand Down
Loading

0 comments on commit 2d06e84

Please sign in to comment.