Add the const qualifier to "char *" variables that refer to literal s… · pythoncapi/cpython@e2f92de · GitHub
Skip to content

Commit e2f92de

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

23 files changed

Lines changed: 46 additions & 41 deletions

Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion

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

0 commit comments

Comments
 (0)