Add the const qualifier to "char *" variables that refer to literal strings. (#4370)
This commit is contained in:
parent
e184cfd7bf
commit
e2f92de6a9
|
@ -1336,7 +1336,7 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args)
|
|||
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,
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
/* Release Number */
|
||||
|
||||
char *PyCursesVersion = "2.2";
|
||||
static const char PyCursesVersion[] = "2.2";
|
||||
|
||||
/* Includes */
|
||||
|
||||
|
@ -2562,7 +2562,7 @@ PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
|
|||
}
|
||||
|
||||
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";
|
||||
|
|
|
@ -1550,7 +1550,7 @@ static PyObject *
|
|||
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)) {
|
||||
|
|
|
@ -2413,7 +2413,7 @@ test_with_docstring(PyObject *self)
|
|||
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); \
|
||||
|
|
|
@ -125,7 +125,8 @@ static void fpe_reset(Sigfunc *handler)
|
|||
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);
|
||||
|
|
|
@ -1608,7 +1608,7 @@ _PyGC_DumpShutdownStats(void)
|
|||
{
|
||||
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";
|
||||
|
|
|
@ -342,7 +342,7 @@ getaddrinfo(const char*hostname, const char*servname,
|
|||
port = htons((u_short)atoi(servname));
|
||||
} else {
|
||||
struct servent *sp;
|
||||
char *proto;
|
||||
const char *proto;
|
||||
|
||||
proto = NULL;
|
||||
switch (pai->ai_socktype) {
|
||||
|
|
|
@ -312,7 +312,7 @@ static int
|
|||
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) */
|
||||
|
|
|
@ -1210,7 +1210,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
|
|||
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;
|
||||
|
|
|
@ -53,7 +53,7 @@ typedef unsigned long uint32_t;
|
|||
|
||||
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 @@ newossobject(PyObject *arg)
|
|||
{
|
||||
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 @@ oss_dealloc(oss_audio_t *self)
|
|||
static oss_mixer_t *
|
||||
newossmixerobject(PyObject *arg)
|
||||
{
|
||||
char *devicename = NULL;
|
||||
const char *devicename = NULL;
|
||||
int fd;
|
||||
oss_mixer_t *self;
|
||||
|
||||
|
|
|
@ -1806,7 +1806,8 @@ bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes)
|
|||
/*[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 @@ bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes)
|
|||
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 @@ bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes)
|
|||
/*[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 @@ bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes)
|
|||
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 @@ bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes)
|
|||
/*[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 @@ bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes)
|
|||
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);
|
||||
|
|
|
@ -543,7 +543,7 @@ instancemethod_repr(PyObject *self)
|
|||
{
|
||||
PyObject *func = PyInstanceMethod_Function(self);
|
||||
PyObject *funcname = NULL , *result = NULL;
|
||||
char *defname = "?";
|
||||
const char *defname = "?";
|
||||
|
||||
if (func == NULL) {
|
||||
PyErr_BadInternalCall();
|
||||
|
|
|
@ -363,9 +363,9 @@ complex_repr(PyComplexObject *v)
|
|||
/* 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
|
||||
|
|
|
@ -152,7 +152,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
|
|||
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,7 +186,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
|
|||
|
||||
if (f->f_lasti == -1) {
|
||||
if (arg && arg != Py_None) {
|
||||
char *msg = "can't send non-None value to a "
|
||||
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 @@ gen_close(PyGenObject *gen, PyObject *args)
|
|||
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)) {
|
||||
|
|
|
@ -1646,7 +1646,7 @@ _PyMem_DebugCheckAddress(char api, const void *p)
|
|||
{
|
||||
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 @@ _PyMem_DebugCheckAddress(char api, const void *p)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -1625,7 +1625,7 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
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 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -8396,8 +8396,8 @@ charmap_encoding_error(
|
|||
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 @@ _PyUnicode_TranslateCharmap(PyObject *input,
|
|||
/* 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;
|
||||
|
|
|
@ -1614,7 +1614,7 @@ SelectPythonDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
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"
|
||||
|
|
|
@ -1942,7 +1942,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
|
|||
/* 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;
|
||||
|
|
|
@ -4846,7 +4846,7 @@ compiler_visit_nested_slice(struct compiler *c, slice_ty s,
|
|||
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";
|
||||
|
|
|
@ -196,7 +196,7 @@ _PyHash_Fini(void)
|
|||
#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++) {
|
||||
|
|
|
@ -597,7 +597,8 @@ Py_LOCAL_INLINE(char *)
|
|||
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;
|
||||
|
|
|
@ -1300,7 +1300,7 @@ err_input(perrdetail *err)
|
|||
{
|
||||
PyObject *v, *w, *errtype, *errtext;
|
||||
PyObject *msg_obj = NULL;
|
||||
char *msg = NULL;
|
||||
const char *msg = NULL;
|
||||
int offset = err->offset;
|
||||
|
||||
errtype = PyExc_SyntaxError;
|
||||
|
|
Loading…
Reference in New Issue