[C++-sig] working around the non-const Python C API
Jeremy Hylton
jeremy at alum.mit.edu
Wed Dec 14 16:57:13 CET 2005
I thought I'd let folks in C++ land know that I did make some
improvements on the Python trunk. I updated all of the functions that
commonly take string literals in extension modules -- PyMethodDef, the
string tp slots of a type object, PyArg_ParseTuple and friends,
Py_BuildValue, and PyObject_GetAttrString() and friends.
Jeremy
On 12/2/05, Jeremy Hylton <jeremy at alum.mit.edu> wrote:
> I was curious if anyone had advice on how to work around the fact that
> much of the Python C API asks for char* when it really intends to
> treat it as a const char*. An example of this behavior is the
> PyMethodDef struct, which has char* ml_name and char* ml_doc
> parameters. If you use a string literal, you get a warning about
> casting a const char* to a char*. I can add a cast around each
> literal, but that's really ugly.
>
> Is there a good way to avoid the warnings?
>
> Secondarily, I know that python-dev is a bit hesitant about const
> correctness, but we did get some const char* types added with the new
> bytecode compiler. Perhaps it's worthwhile to try changing a few of
> the most egregious cases to use const char*.
>
> Jeremy
>
More information about the Cplusplus-sig
mailing list