Skip to content

Commit e2f92de

Browse files
Add the const qualifier to "char *" variables that refer to literal strings. (#4370)
1 parent e184cfd commit e2f92de

23 files changed

+46
-41
lines changed

Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args)
13361336
handle = ctypes_dlopen(name_str, mode);
13371337
Py_XDECREF(name2);
13381338
if (!handle) {
1339-
char *errmsg = ctypes_dlerror();
1339+
const char *errmsg = ctypes_dlerror();
13401340
if (!errmsg)
13411341
errmsg = "dlopen() error";
13421342
PyErr_SetString(PyExc_OSError,

Modules/_cursesmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
/* Release Number */
9898

99-
char *PyCursesVersion = "2.2";
99+
static const char PyCursesVersion[] = "2.2";
100100

101101
/* Includes */
102102

@@ -2562,7 +2562,7 @@ PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
25622562
}
25632563

25642564
if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) {
2565-
char* s = "setupterm: unknown error";
2565+
const char* s = "setupterm: unknown error";
25662566

25672567
if (err == 0) {
25682568
s = "setupterm: could not find terminal";

Modules/_sqlite/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ static PyObject *
15501550
pysqlite_connection_exit(pysqlite_Connection* self, PyObject* args)
15511551
{
15521552
PyObject* exc_type, *exc_value, *exc_tb;
1553-
char* method_name;
1553+
const char* method_name;
15541554
PyObject* result;
15551555

15561556
if (!PyArg_ParseTuple(args, "OOO", &exc_type, &exc_value, &exc_tb)) {

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ test_with_docstring(PyObject *self)
24132413
static PyObject *
24142414
test_string_to_double(PyObject *self) {
24152415
double result;
2416-
char *msg;
2416+
const char *msg;
24172417

24182418
#define CHECK_STRING(STR, expected) \
24192419
result = PyOS_string_to_double(STR, NULL, NULL); \

Modules/fpectlmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ static void fpe_reset(Sigfunc *handler)
125125
extern long ieee_handler(const char*, const char*, sigfpe_handler_type);
126126
#endif
127127

128-
char *mode="exception", *in="all", *out;
128+
const char *mode="exception", *in="all";
129+
char *out;
129130
(void) nonstandard_arithmetic();
130131
(void) ieee_flags("clearall",mode,in,&out);
131132
(void) ieee_handler("set","common",(sigfpe_handler_type)handler);

Modules/gcmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ _PyGC_DumpShutdownStats(void)
16081608
{
16091609
if (!(_PyRuntime.gc.debug & DEBUG_SAVEALL)
16101610
&& _PyRuntime.gc.garbage != NULL && PyList_GET_SIZE(_PyRuntime.gc.garbage) > 0) {
1611-
char *message;
1611+
const char *message;
16121612
if (_PyRuntime.gc.debug & DEBUG_UNCOLLECTABLE)
16131613
message = "gc: %zd uncollectable objects at " \
16141614
"shutdown";

Modules/getaddrinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ getaddrinfo(const char*hostname, const char*servname,
342342
port = htons((u_short)atoi(servname));
343343
} else {
344344
struct servent *sp;
345-
char *proto;
345+
const char *proto;
346346

347347
proto = NULL;
348348
switch (pai->ai_socktype) {

Modules/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static int
312312
run_file(FILE *fp, const wchar_t *filename, PyCompilerFlags *p_cf)
313313
{
314314
PyObject *unicode, *bytes = NULL;
315-
char *filename_str;
315+
const char *filename_str;
316316
int run;
317317

318318
/* call pending calls like signal handlers (SIGINT) */

Modules/mmapmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
12101210
DWORD off_lo; /* lower 32 bits of offset */
12111211
DWORD size_hi; /* upper 32 bits of size */
12121212
DWORD size_lo; /* lower 32 bits of size */
1213-
char *tagname = "";
1213+
const char *tagname = "";
12141214
DWORD dwErr = 0;
12151215
int fileno;
12161216
HANDLE fh = 0;

Modules/ossaudiodev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef unsigned long uint32_t;
5353

5454
typedef struct {
5555
PyObject_HEAD
56-
char *devicename; /* name of the device file */
56+
const char *devicename; /* name of the device file */
5757
int fd; /* file descriptor */
5858
int mode; /* file mode (O_RDONLY, etc.) */
5959
Py_ssize_t icount; /* input count */
@@ -82,8 +82,8 @@ newossobject(PyObject *arg)
8282
{
8383
oss_audio_t *self;
8484
int fd, afmts, imode;
85-
char *devicename = NULL;
86-
char *mode = NULL;
85+
const char *devicename = NULL;
86+
const char *mode = NULL;
8787

8888
/* Two ways to call open():
8989
open(device, mode) (for consistency with builtin open())
@@ -167,7 +167,7 @@ oss_dealloc(oss_audio_t *self)
167167
static oss_mixer_t *
168168
newossmixerobject(PyObject *arg)
169169
{
170-
char *devicename = NULL;
170+
const char *devicename = NULL;
171171
int fd;
172172
oss_mixer_t *self;
173173

0 commit comments

Comments
 (0)