Skip to content

bpo-39605: Fix some casts to not cast away const#18453

Merged
benjaminp merged 11 commits into
python:masterfrom
petdance:Issue39605
Feb 12, 2020
Merged

bpo-39605: Fix some casts to not cast away const#18453
benjaminp merged 11 commits into
python:masterfrom
petdance:Issue39605

Conversation

@petdance

@petdance petdance commented Feb 11, 2020

Copy link
Copy Markdown
Contributor

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.

https://bugs.python.org/issue39605

@codecov

codecov Bot commented Feb 11, 2020

Copy link
Copy Markdown

Codecov Report

Merging #18453 into master will decrease coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18453      +/-   ##
==========================================
- Coverage   82.20%   82.11%   -0.09%     
==========================================
  Files        1957     1954       -3     
  Lines      589324   583606    -5718     
  Branches    44428    44428              
==========================================
- Hits       484430   479255    -5175     
+ Misses      95233    94705     -528     
+ Partials     9661     9646      -15     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) ⬇️
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) ⬇️
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) ⬇️
Lib/test/test_smtpnet.py 78.57% <0.00%> (-12.86%) ⬇️
Lib/ftplib.py 63.85% <0.00%> (-6.06%) ⬇️
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) ⬇️
Lib/dbm/__init__.py 66.66% <0.00%> (-4.45%) ⬇️
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) ⬇️
Lib/test/test_socket.py 71.94% <0.00%> (-3.87%) ⬇️
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) ⬇️
... and 317 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 96ce227...2af5667. Read the comment docs.

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @petdance for the PR, and @benjaminp for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-18471 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Feb 12, 2020
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
(cherry picked from commit e6be9b5)

Co-authored-by: Andy Lester <andy@petdance.com>
@petdance petdance deleted the Issue39605 branch February 12, 2020 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants