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;
 
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 83c3549..dc1515a 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1806,7 +1806,8 @@
 /*[clinic end generated code: output=760412661a34ad5a input=ef7bb59b09c21d62]*/
 {
     Py_ssize_t left, right, mysize, byteslen;
-    char *myptr, *bytesptr;
+    char *myptr;
+    const char *bytesptr;
     Py_buffer vbytes;
 
     if (bytes == Py_None) {
@@ -1816,7 +1817,7 @@
     else {
         if (PyObject_GetBuffer(bytes, &vbytes, PyBUF_SIMPLE) != 0)
             return NULL;
-        bytesptr = (char *) vbytes.buf;
+        bytesptr = (const char *) vbytes.buf;
         byteslen = vbytes.len;
     }
     myptr = PyByteArray_AS_STRING(self);
@@ -1847,7 +1848,8 @@
 /*[clinic end generated code: output=d005c9d0ab909e66 input=80843f975dd7c480]*/
 {
     Py_ssize_t left, right, mysize, byteslen;
-    char *myptr, *bytesptr;
+    char *myptr;
+    const char *bytesptr;
     Py_buffer vbytes;
 
     if (bytes == Py_None) {
@@ -1857,7 +1859,7 @@
     else {
         if (PyObject_GetBuffer(bytes, &vbytes, PyBUF_SIMPLE) != 0)
             return NULL;
-        bytesptr = (char *) vbytes.buf;
+        bytesptr = (const char *) vbytes.buf;
         byteslen = vbytes.len;
     }
     myptr = PyByteArray_AS_STRING(self);
@@ -1885,7 +1887,8 @@
 /*[clinic end generated code: output=030e2fbd2f7276bd input=e728b994954cfd91]*/
 {
     Py_ssize_t right, mysize, byteslen;
-    char *myptr, *bytesptr;
+    char *myptr;
+    const char *bytesptr;
     Py_buffer vbytes;
 
     if (bytes == Py_None) {
@@ -1895,7 +1898,7 @@
     else {
         if (PyObject_GetBuffer(bytes, &vbytes, PyBUF_SIMPLE) != 0)
             return NULL;
-        bytesptr = (char *) vbytes.buf;
+        bytesptr = (const char *) vbytes.buf;
         byteslen = vbytes.len;
     }
     myptr = PyByteArray_AS_STRING(self);
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 063c24a..e88c95c 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -543,7 +543,7 @@
 {
     PyObject *func = PyInstanceMethod_Function(self);
     PyObject *funcname = NULL , *result = NULL;
-    char *defname = "?";
+    const char *defname = "?";
 
     if (func == NULL) {
         PyErr_BadInternalCall();
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 3bf37ee..4bcf2ce 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -363,9 +363,9 @@
     /* These do not need to be freed. re is either an alias
        for pre or a pointer to a constant.  lead and tail
        are pointers to constants. */
-    char *re = NULL;
-    char *lead = "";
-    char *tail = "";
+    const char *re = NULL;
+    const char *lead = "";
+    const char *tail = "";
 
     if (v->cval.real == 0. && copysign(1.0, v->cval.real)==1.0) {
         /* Real part is +0: just output the imaginary part and do not
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 7793a54..00a8823 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -152,7 +152,7 @@
     PyObject *result;
 
     if (gen->gi_running) {
-        char *msg = "generator already executing";
+        const char *msg = "generator already executing";
         if (PyCoro_CheckExact(gen)) {
             msg = "coroutine already executing";
         }
@@ -186,8 +186,8 @@
 
     if (f->f_lasti == -1) {
         if (arg && arg != Py_None) {
-            char *msg = "can't send non-None value to a "
-                        "just-started generator";
+            const char *msg = "can't send non-None value to a "
+                              "just-started generator";
             if (PyCoro_CheckExact(gen)) {
                 msg = NON_INIT_CORO_MSG;
             }
@@ -410,7 +410,7 @@
         PyErr_SetNone(PyExc_GeneratorExit);
     retval = gen_send_ex(gen, Py_None, 1, 1);
     if (retval) {
-        char *msg = "generator ignored GeneratorExit";
+        const char *msg = "generator ignored GeneratorExit";
         if (PyCoro_CheckExact(gen)) {
             msg = "coroutine ignored GeneratorExit";
         } else if (PyAsyncGen_CheckExact(gen)) {
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 7f5306f..4441c82 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -1646,7 +1646,7 @@
 {
     const uint8_t *q = (const uint8_t *)p;
     char msgbuf[64];
-    char *msg;
+    const char *msg;
     size_t nbytes;
     const uint8_t *tail;
     int i;
@@ -1661,7 +1661,7 @@
     id = (char)q[-SST];
     if (id != api) {
         msg = msgbuf;
-        snprintf(msg, sizeof(msgbuf), "bad ID: Allocated using API '%c', verified using API '%c'", id, api);
+        snprintf(msgbuf, sizeof(msgbuf), "bad ID: Allocated using API '%c', verified using API '%c'", id, api);
         msgbuf[sizeof(msgbuf)-1] = 0;
         goto error;
     }
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index afacb36..5d22ce7 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -1625,7 +1625,7 @@
     if (len == -1)
         return -1;
     if (len > 1) {
-        char *msg = "expected at most 1 arguments, got %d";
+        const char *msg = "expected at most 1 arguments, got %d";
         PyErr_Format(PyExc_TypeError, msg, len);
         return -1;
     }
@@ -2337,7 +2337,7 @@
     assert(args == NULL || PyTuple_Check(args));
     len = (args != NULL) ? PyTuple_GET_SIZE(args) : 0;
     if (len > 1) {
-        char *msg = "update() takes at most 1 positional argument (%d given)";
+        const char *msg = "update() takes at most 1 positional argument (%d given)";
         PyErr_Format(PyExc_TypeError, msg, len);
         return NULL;
     }
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 194c5bc..fdc3197 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8396,8 +8396,8 @@
     Py_ssize_t collstartpos = *inpos;
     Py_ssize_t collendpos = *inpos+1;
     Py_ssize_t collpos;
-    char *encoding = "charmap";
-    char *reason = "character maps to <undefined>";
+    const char *encoding = "charmap";
+    const char *reason = "character maps to <undefined>";
     charmapencode_result x;
     Py_UCS4 ch;
     int val;
@@ -8928,7 +8928,7 @@
     /* output buffer */
     _PyUnicodeWriter writer;
     /* error handler */
-    char *reason = "character maps to <undefined>";
+    const char *reason = "character maps to <undefined>";
     PyObject *errorHandler = NULL;
     PyObject *exc = NULL;
     int ignore;
diff --git a/PC/bdist_wininst/install.c b/PC/bdist_wininst/install.c
index 4f9ef6c..04323eb 100644
--- a/PC/bdist_wininst/install.c
+++ b/PC/bdist_wininst/install.c
@@ -1614,7 +1614,7 @@
 
             if (count == 0) {
                 char Buffer[4096];
-                char *msg;
+                const char *msg;
                 if (target_version && target_version[0]) {
                     wsprintf(Buffer,
                              "Python version %s required, which was not found"
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 6215a63..8eac0af 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1942,7 +1942,7 @@
     /* If we're interactive, use (GNU) readline */
     if (tty) {
         PyObject *po = NULL;
-        char *promptstr;
+        const char *promptstr;
         char *s = NULL;
         PyObject *stdin_encoding = NULL, *stdin_errors = NULL;
         PyObject *stdout_encoding = NULL, *stdout_errors = NULL;
diff --git a/Python/compile.c b/Python/compile.c
index 58a708c..a3ea60d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4846,7 +4846,7 @@
 static int
 compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
 {
-    char * kindname = NULL;
+    const char * kindname = NULL;
     switch (s->kind) {
     case Index_kind:
         kindname = "index";
diff --git a/Python/pyhash.c b/Python/pyhash.c
index 8a6bd60..aa49eeb 100644
--- a/Python/pyhash.c
+++ b/Python/pyhash.c
@@ -196,7 +196,7 @@
 #ifdef Py_HASH_STATS
     int i;
     Py_ssize_t total = 0;
-    char *fmt = "%2i %8" PY_FORMAT_SIZE_T "d %8" PY_FORMAT_SIZE_T "d\n";
+    const char *fmt = "%2i %8" PY_FORMAT_SIZE_T "d %8" PY_FORMAT_SIZE_T "d\n";
 
     fprintf(stderr, "len   calls    total\n");
     for (i = 1; i <= Py_HASH_STATS_MAX; i++) {
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index f19d239..9bf9363 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -597,7 +597,8 @@
 ensure_decimal_point(char* buffer, size_t buf_size, int precision)
 {
     int digit_count, insert_count = 0, convert_to_exp = 0;
-    char *chars_to_insert, *digits_start;
+    const char *chars_to_insert;
+    char *digits_start;
 
     /* search for the first non-digit character */
     char *p = buffer;
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 17ec182..3d63186 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1300,7 +1300,7 @@
 {
     PyObject *v, *w, *errtype, *errtext;
     PyObject *msg_obj = NULL;
-    char *msg = NULL;
+    const char *msg = NULL;
     int offset = err->offset;
 
     errtype = PyExc_SyntaxError;