closes bpo-39605: Fix some casts to not cast away const. (GH-18453)

gcc -Wcast-qual turns up a number of instances of casting away constness of pointers. Some of these can be safely modified, by either:

Adding the const to the type cast, as in:

-    return _PyUnicode_FromUCS1((unsigned char*)s, size);
+    return _PyUnicode_FromUCS1((const unsigned char*)s, size);

or, Removing the cast entirely, because it's not necessary (but probably was at one time), as in:

-    PyDTrace_FUNCTION_ENTRY((char *)filename, (char *)funcname, lineno);
+    PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);

These changes will not change code, but they will make it much easier to check for errors in consts
This commit is contained in:
Andy Lester 2020-02-11 20:28:35 -06:00 committed by GitHub
parent 029e8401b7
commit e6be9b59a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 39 deletions

View file

@ -1682,8 +1682,8 @@ unpack_single(const char *ptr, const char *fmt)
switch (fmt[0]) {
/* signed integers and fast path for 'B' */
case 'B': uc = *((unsigned char *)ptr); goto convert_uc;
case 'b': ld = *((signed char *)ptr); goto convert_ld;
case 'B': uc = *((const unsigned char *)ptr); goto convert_uc;
case 'b': ld = *((const signed char *)ptr); goto convert_ld;
case 'h': UNPACK_SINGLE(ld, ptr, short); goto convert_ld;
case 'i': UNPACK_SINGLE(ld, ptr, int); goto convert_ld;
case 'l': UNPACK_SINGLE(ld, ptr, long); goto convert_ld;
@ -2684,8 +2684,8 @@ unpack_cmp(const char *p, const char *q, char fmt,
switch (fmt) {
/* signed integers and fast path for 'B' */
case 'B': return *((unsigned char *)p) == *((unsigned char *)q);
case 'b': return *((signed char *)p) == *((signed char *)q);
case 'B': return *((const unsigned char *)p) == *((const unsigned char *)q);
case 'b': return *((const signed char *)p) == *((const signed char *)q);
case 'h': CMP_SINGLE(p, q, short); return equal;
case 'i': CMP_SINGLE(p, q, int); return equal;
case 'l': CMP_SINGLE(p, q, long); return equal;