Add the const qualifier to "char *" variables that refer to literal strings. (#4370)
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 3a6ad86..bdc3728 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -1336,7 +1336,7 @@
handle = ctypes_dlopen(name_str, mode);
Py_XDECREF(name2);
if (!handle) {
- char *errmsg = ctypes_dlerror();
+ const char *errmsg = ctypes_dlerror();
if (!errmsg)
errmsg = "dlopen() error";
PyErr_SetString(PyExc_OSError,
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index ae1905b..42f4a85 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -96,7 +96,7 @@
/* Release Number */
-char *PyCursesVersion = "2.2";
+static const char PyCursesVersion[] = "2.2";
/* Includes */
@@ -2562,7 +2562,7 @@
}
if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) {
- char* s = "setupterm: unknown error";
+ const char* s = "setupterm: unknown error";
if (err == 0) {
s = "setupterm: could not find terminal";
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 57eee2d..3e83fb6 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -1550,7 +1550,7 @@
pysqlite_connection_exit(pysqlite_Connection* self, PyObject* args)
{
PyObject* exc_type, *exc_value, *exc_tb;
- char* method_name;
+ const char* method_name;
PyObject* result;
if (!PyArg_ParseTuple(args, "OOO", &exc_type, &exc_value, &exc_tb)) {
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 5210809..7a57719 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2413,7 +2413,7 @@
static PyObject *
test_string_to_double(PyObject *self) {
double result;
- char *msg;
+ const char *msg;
#define CHECK_STRING(STR, expected) \
result = PyOS_string_to_double(STR, NULL, NULL); \
diff --git a/Modules/fpectlmodule.c b/Modules/fpectlmodule.c
index 404f692..42ef0f6 100644
--- a/Modules/fpectlmodule.c
+++ b/Modules/fpectlmodule.c
@@ -125,7 +125,8 @@
extern long ieee_handler(const char*, const char*, sigfpe_handler_type);
#endif
- char *mode="exception", *in="all", *out;
+ const char *mode="exception", *in="all";
+ char *out;
(void) nonstandard_arithmetic();
(void) ieee_flags("clearall",mode,in,&out);
(void) ieee_handler("set","common",(sigfpe_handler_type)handler);
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 6e26c7a..121eb46 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1608,7 +1608,7 @@
{
if (!(_PyRuntime.gc.debug & DEBUG_SAVEALL)
&& _PyRuntime.gc.garbage != NULL && PyList_GET_SIZE(_PyRuntime.gc.garbage) > 0) {
- char *message;
+ const char *message;
if (_PyRuntime.gc.debug & DEBUG_UNCOLLECTABLE)
message = "gc: %zd uncollectable objects at " \
"shutdown";
diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c
index b6fb53c..06e87bf 100644
--- a/Modules/getaddrinfo.c
+++ b/Modules/getaddrinfo.c
@@ -342,7 +342,7 @@
port = htons((u_short)atoi(servname));
} else {
struct servent *sp;
- char *proto;
+ const char *proto;
proto = NULL;
switch (pai->ai_socktype) {
diff --git a/Modules/main.c b/Modules/main.c
index 846ecb6..54abbcc 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -312,7 +312,7 @@
run_file(FILE *fp, const wchar_t *filename, PyCompilerFlags *p_cf)
{
PyObject *unicode, *bytes = NULL;
- char *filename_str;
+ const char *filename_str;
int run;
/* call pending calls like signal handlers (SIGINT) */
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index ea7baf4..6cf4545 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1210,7 +1210,7 @@
DWORD off_lo; /* lower 32 bits of offset */
DWORD size_hi; /* upper 32 bits of size */
DWORD size_lo; /* lower 32 bits of size */
- char *tagname = "";
+ const char *tagname = "";
DWORD dwErr = 0;
int fileno;
HANDLE fh = 0;
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
index 8bb4d0d..58ee71f 100644
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -53,7 +53,7 @@
typedef struct {
PyObject_HEAD
- char *devicename; /* name of the device file */
+ const char *devicename; /* name of the device file */
int fd; /* file descriptor */
int mode; /* file mode (O_RDONLY, etc.) */
Py_ssize_t icount; /* input count */
@@ -82,8 +82,8 @@
{
oss_audio_t *self;
int fd, afmts, imode;
- char *devicename = NULL;
- char *mode = NULL;
+ const char *devicename = NULL;
+ const char *mode = NULL;
/* Two ways to call open():
open(device, mode) (for consistency with builtin open())
@@ -167,7 +167,7 @@
static oss_mixer_t *
newossmixerobject(PyObject *arg)
{
- char *devicename = NULL;
+ const char *devicename = NULL;
int fd;
oss_mixer_t *self;