-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some constness / char literal issues being found by MSVC standard conforming mode #8344
Conversation
@acozzette, I am fine with adjusting the code according to the style guide, but is there any chance that Google, being a visionary sponsor of PSF, could make something to fix this issue right in the Python itself? These const_cast's are nasty. Removing them in the future would require adding |
@georgthegreat This would definitely be nice to fix within Python itself, but unfortunately I don't think I can help much there because I'm not really connected to anyone would be in a good position to work on that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Fixing this in python will require changes in many opensource projects anyway. It's better not to block on this.
I have changed to const_cast, as requested.
PyObject* py_database = NULL; | ||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &py_database)) { | ||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", (char**)kwlist, &py_database)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is another tricky thing.
CPython C API was using char*
for const literals in py2, with many problems being fixed (that is, replaced with const char*
) in Python3. This one, however, remains unfixed (this PR attempted to fix it, but did not get to the merge commit and looks abandoned).
Similar crutchy remove_const-casts can be found in various open source projects:
The list includes the following pip packages (but definitely not limited to):
It might be better to fix python problem before merging this PR.
@acozzette, none of the above links claiming that Kokoro build failed work for me. Could you, please, help me to understand failure reasons? |
Sorry about that, those failures were caused by an unrelated issue that should be fixed now. Let me try running the tests again. |
This is the continuation of protocolbuffers#8344
This is the continuation of #8344
This one is somewhat tricky.
According to C Language Standard
"string"
has typechar[7]
(that is, 6 letters + null terminator).According to C++ Standard, however, it has its natural type of
const char[7]
(see cppreference).An attempt to write
char* ptr = "string";
, however, does not cause any errors when compiled by clang or gcc.MSVC has
/permissive-
flag which is off by default, unless/std:c++latest
is used.This PR fixes issues caused by this type mismatch.