Skip to content
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

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/google/protobuf/pyext/descriptor_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase(
// The public DescriptorPool constructor.
static PyObject* New(PyTypeObject* type,
PyObject* args, PyObject* kwargs) {
static char* kwlist[] = {"descriptor_db", 0};
static const char* kwlist[] = {"descriptor_db", 0};
PyObject* py_database = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &py_database)) {
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", (char**)kwlist, &py_database)) {
Copy link
Contributor Author

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.

georgthegreat marked this conversation as resolved.
Show resolved Hide resolved
return NULL;
}
DescriptorDatabase* database = NULL;
Expand Down
8 changes: 4 additions & 4 deletions python/google/protobuf/pyext/map_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,

static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
PyObject* kwargs) {
static char* kwlist[] = {"key", "default", nullptr};
static const char* kwlist[] = {"key", "default", nullptr};
PyObject* key;
PyObject* default_value = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &key,
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", (char**)kwlist, &key,
&default_value)) {
return NULL;
}
Expand Down Expand Up @@ -757,10 +757,10 @@ PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) {
}

PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
static char* kwlist[] = {"key", "default", nullptr};
static const char* kwlist[] = {"key", "default", nullptr};
PyObject* key;
PyObject* default_value = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &key,
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", (char**)kwlist, &key,
&default_value)) {
return NULL;
}
Expand Down
10 changes: 5 additions & 5 deletions python/google/protobuf/pyext/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
}

static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
static char *kwlist[] = {"name", "bases", "dict", 0};
static const char *kwlist[] = {"name", "bases", "dict", 0};
PyObject *bases, *dict;
const char* name;

// Check arguments: (name, bases, dict)
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!O!:type", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!O!:type", (char**)kwlist,
&name,
&PyTuple_Type, &bases,
&PyDict_Type, &dict)) {
Expand Down Expand Up @@ -546,7 +546,7 @@ PyObject* PickleError_class;

// Format an error message for unexpected types.
// Always return with an exception set.
void FormatTypeError(PyObject* arg, char* expected_types) {
void FormatTypeError(PyObject* arg, const char* expected_types) {
// This function is often called with an exception set.
// Clear it to call PyObject_Repr() in good conditions.
PyErr_Clear();
Expand Down Expand Up @@ -1679,9 +1679,9 @@ static PyObject* InternalSerializeToString(
CMessage* self, PyObject* args, PyObject* kwargs,
bool require_initialized) {
// Parse the "deterministic" kwarg; defaults to False.
static char* kwlist[] = { "deterministic", 0 };
static const char* kwlist[] = { "deterministic", 0 };
PyObject* deterministic_obj = Py_None;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", (char**)kwlist,
&deterministic_obj)) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion python/google/protobuf/pyext/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg);

#define FULL_MODULE_NAME "google.protobuf.pyext._message"

void FormatTypeError(PyObject* arg, char* expected_types);
void FormatTypeError(PyObject* arg, const char* expected_types);
template<class T>
bool CheckAndGetInteger(PyObject* arg, T* value);
bool CheckAndGetDouble(PyObject* arg, double* value);
Expand Down
4 changes: 2 additions & 2 deletions python/google/protobuf/pyext/message_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool)
}

PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
static char* kwlist[] = {"pool", 0};
static const char* kwlist[] = {"pool", 0};
PyObject* pool = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &pool)) {
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", (char**)kwlist, &pool)) {
return NULL;
}
ScopedPyObjectPtr owned_pool;
Expand Down