[Python-Dev] Const-correctness in C-API Object Protocol
"Martin v. Löwis"
martin at v.loewis.de
Tue Feb 22 23:06:36 CET 2011
>> Though I do not get that warning -- which compiler and version issues
>> it? Is it a C or a C++ compiler?
>
> Well, which warning are you talking about?
I think Guido assumed that the OP was getting actual complaints from
some actual compiler - else he wouldn't have asked the question.
However, he didn't actually say he got compile issues.
If you compile
#include <Python.h>
int main()
{
const char* s = "stdin";
PyObject_CallMethod(0, s, s);
}
with a g++, you get
a.cc: In function ‘int main()’:
a.cc:6: error: invalid conversion from ‘const char*’ to ‘char*’
a.cc:6: error: initializing argument 2 of ‘PyObject*
PyObject_CallMethod(PyObject*, char*, char*, ...)’
a.cc:6: error: invalid conversion from ‘const char*’ to ‘char*’
a.cc:6: error: initializing argument 3 of ‘PyObject*
PyObject_CallMethod(PyObject*, char*, char*, ...)’
If you compile
#include <Python.h>
int main()
{
PyObject_CallMethod(0, "stdin", "stdin");
}
you get
a.cc: In function ‘int main()’:
a.cc:5: warning: deprecated conversion from string constant to ‘char*’
a.cc:5: warning: deprecated conversion from string constant to ‘char*’
Since most people likely use string literals, and since g++ only started
warning about the deprecated conversion only recently, most people
probably haven't run into the issue.
Regards,
Martin
More information about the Python-Dev
mailing list