Skip to content

Commit 20b39b2

Browse files
Removed redundant casts to char *.
Corresponding functions now accept `const char *` (issue #1772673).
1 parent 131caba commit 20b39b2

File tree

10 files changed

+17
-18
lines changed

10 files changed

+17
-18
lines changed

Modules/_cursesmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ PyCurses_KeyName(PyObject *self, PyObject *args)
26752675
}
26762676
knp = keyname(ch);
26772677

2678-
return PyBytes_FromString((knp == NULL) ? "" : (char *)knp);
2678+
return PyBytes_FromString((knp == NULL) ? "" : knp);
26792679
}
26802680
#endif
26812681

Modules/_decimal/_decimal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5640,7 +5640,7 @@ PyInit__decimal(void)
56405640
goto error; /* GCOV_NOT_REACHED */
56415641
}
56425642

5643-
ASSIGN_PTR(cm->ex, PyErr_NewException((char *)cm->fqname, base, NULL));
5643+
ASSIGN_PTR(cm->ex, PyErr_NewException(cm->fqname, base, NULL));
56445644
Py_DECREF(base);
56455645

56465646
/* add to module */
@@ -5672,7 +5672,7 @@ PyInit__decimal(void)
56725672
goto error; /* GCOV_NOT_REACHED */
56735673
}
56745674

5675-
ASSIGN_PTR(cm->ex, PyErr_NewException((char *)cm->fqname, base, NULL));
5675+
ASSIGN_PTR(cm->ex, PyErr_NewException(cm->fqname, base, NULL));
56765676
Py_DECREF(base);
56775677

56785678
Py_INCREF(cm->ex);

Modules/cjkcodecs/cjkcodecs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ importmap(const char *modname, const char *symbol,
362362
if (mod == NULL)
363363
return -1;
364364

365-
o = PyObject_GetAttrString(mod, (char*)symbol);
365+
o = PyObject_GetAttrString(mod, symbol);
366366
if (o == NULL)
367367
goto errorexit;
368368
else if (!PyCapsule_IsValid(o, PyMultibyteCodec_CAPSULE_NAME)) {

Modules/cjkcodecs/multibytecodec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,10 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
12691269

12701270
if (sizehint < 0)
12711271
cres = PyObject_CallMethod(self->stream,
1272-
(char *)method, NULL);
1272+
method, NULL);
12731273
else
12741274
cres = PyObject_CallMethod(self->stream,
1275-
(char *)method, "i", sizehint);
1275+
method, "i", sizehint);
12761276
if (cres == NULL)
12771277
goto errorexit;
12781278

Modules/pyexpat.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ PyUnknownEncodingHandler(void *encodingHandlerData,
14781478

14791479

14801480
static PyObject *
1481-
newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
1481+
newxmlparseobject(const char *encoding, const char *namespace_separator, PyObject *intern)
14821482
{
14831483
int i;
14841484
xmlparseobject *self;
@@ -1932,8 +1932,7 @@ pyexpat_ParserCreate_impl(PyModuleDef *module, const char *encoding, const char
19321932
return NULL;
19331933
}
19341934

1935-
result = newxmlparseobject((char *)encoding, (char *)namespace_separator,
1936-
intern);
1935+
result = newxmlparseobject(encoding, namespace_separator, intern);
19371936
if (intern_decref) {
19381937
Py_DECREF(intern);
19391938
}
@@ -2074,7 +2073,7 @@ MODULE_INITFUNC(void)
20742073
PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype);
20752074

20762075
PyModule_AddStringConstant(m, "EXPAT_VERSION",
2077-
(char *) XML_ExpatVersion());
2076+
XML_ExpatVersion());
20782077
{
20792078
XML_Expat_Version info = XML_ExpatVersionInfo();
20802079
PyModule_AddObject(m, "version_info",
@@ -2154,7 +2153,7 @@ MODULE_INITFUNC(void)
21542153

21552154
#define MYCONST(name) \
21562155
if (PyModule_AddStringConstant(errors_module, #name, \
2157-
(char *)XML_ErrorString(name)) < 0) \
2156+
XML_ErrorString(name)) < 0) \
21582157
return NULL; \
21592158
tmpnum = PyLong_FromLong(name); \
21602159
if (tmpnum == NULL) return NULL; \

Objects/bytesobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3403,7 +3403,7 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
34033403
_Py_DEC_REFTOTAL;
34043404
_Py_ForgetReference(v);
34053405
*pv = (PyObject *)
3406-
PyObject_REALLOC((char *)v, PyBytesObject_SIZE + newsize);
3406+
PyObject_REALLOC(v, PyBytesObject_SIZE + newsize);
34073407
if (*pv == NULL) {
34083408
PyObject_Del(v);
34093409
PyErr_NoMemory();

Objects/floatobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ _PyFloat_Pack4(double x, unsigned char *p, int le)
20262026
}
20272027
else {
20282028
float y = (float)x;
2029-
const char *s = (char*)&y;
2029+
const unsigned char *s = (unsigned char*)&y;
20302030
int i, incr = 1;
20312031

20322032
if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x))
@@ -2162,7 +2162,7 @@ _PyFloat_Pack8(double x, unsigned char *p, int le)
21622162
return -1;
21632163
}
21642164
else {
2165-
const char *s = (char*)&x;
2165+
const unsigned char *s = (unsigned char*)&x;
21662166
int i, incr = 1;
21672167

21682168
if ((double_format == ieee_little_endian_format && !le)

Objects/longobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ _PyLong_FromBytes(const char *s, Py_ssize_t len, int base)
23122312
PyObject *result, *strobj;
23132313
char *end = NULL;
23142314

2315-
result = PyLong_FromString((char*)s, &end, base);
2315+
result = PyLong_FromString(s, &end, base);
23162316
if (end == NULL || (result != NULL && end == s + len))
23172317
return result;
23182318
Py_XDECREF(result);

Objects/unicodeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
727727
_Py_DEC_REFTOTAL;
728728
_Py_ForgetReference(unicode);
729729

730-
new_unicode = (PyObject *)PyObject_REALLOC((char *)unicode, new_size);
730+
new_unicode = (PyObject *)PyObject_REALLOC(unicode, new_size);
731731
if (new_unicode == NULL) {
732732
_Py_NewReference(unicode);
733733
PyErr_NoMemory();
@@ -3483,7 +3483,7 @@ mbstowcs_errorpos(const char *str, size_t len)
34833483
memset(&mbs, 0, sizeof mbs);
34843484
while (len)
34853485
{
3486-
converted = mbrtowc(&ch, (char*)str, len, &mbs);
3486+
converted = mbrtowc(&ch, str, len, &mbs);
34873487
if (converted == 0)
34883488
/* Reached end of string */
34893489
break;

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ PyImport_AppendInittab(const char *name, PyObject* (*initfunc)(void))
20642064

20652065
memset(newtab, '\0', sizeof newtab);
20662066

2067-
newtab[0].name = (char *)name;
2067+
newtab[0].name = name;
20682068
newtab[0].initfunc = initfunc;
20692069

20702070
return PyImport_ExtendInittab(newtab);

0 commit comments

Comments
 (0)