[Python-Dev] Const-correctness in C-API Object Protocol

David Claridge daave at daave.com
Wed Feb 23 00:14:10 CET 2011


> 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

This is precisely the warning I've been getting, I've been embedding
Python 2.6 in an application built using g++ 4.4.

> The later is addressed by issue 1699259
> <http://bugs.python.org/issue1699259>.  It looks like const was added
> in 3.2, but deemed not important enough to backport to 2.7.  The issue
> is still open, so interested parties can argue for backport there.
>
> The former (PyObject_CallMethod) is similarly subject of an open issue
> in a commit review stage: <http://bugs.python.org/issue9369>.

Thanks, I'll add my 2c worth on those issues.

Even if it is eventually decided not to backport those patches to 2.7,
it would be nice if the documentation could be updated to indicate
that strings passed to those functions won't be modified, so that API
users like myself can feel a little safer when passing literals in,
without having to trawl through the interpreter source to see if the
arguments are modified.

Thanks,

--
David Claridge
http://daave.com


More information about the Python-Dev mailing list