classification
Title: Replacing char* with const char*
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 2.7
process
Status: open Resolution:
Dependencies: replacing char* with const char* in sysmodule.c/.h
View: 1699259
Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, dgreiman, ext-, gustavo
Priority: normal Keywords: patch

Created on 2007-08-12 16:43 by ext-, last changed 2009-05-15 01:51 by ajaksu2.

Files
File name Uploaded Description Edit
const_char.patch ext-, 2007-08-12 16:43 Patch to replace char* with const char* in a few functions review
Messages (4)
msg53019 - (view) Author: eXt (ext-) Date: 2007-08-12 16:43
Many functions use char* where const char* should be used. I've changed this in a few function prototypes which I use while embedding python due to numerous warnings about deprecated casting from string constants to char*.
msg58709 - (view) Author: Gustavo J. A. M. Carneiro (gustavo) Date: 2007-12-17 22:28
I was about to submit the very same patch :-)
I missed PyErr_NewException, but you missed the PyMapping_* methods ;)

Please look into this matter.  GCC 4.2 has arrived and it has a new
warning.  The code:

     char* kwlist[] = { "target", "encoding", NULL };

now gives a warning like:

"warning: deprecated conversion from string constant to ‘char*’"

at least when compiling in C++ mode...

This means that people have to declare it as "const char* kwlist", which
will then trigger another warning when calling
PyArg_ParseTupleAndKeywords with such a variable, because the prototype is:

PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
                                                  const char *, char **,
...);

The "char **" should be "const char **".  ext-, any chance you could fix
that too?
msg58712 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-12-17 23:52
There was once a rather long discussion about "const" in
PyArg_ParseTupleAndKeywords:
http://mail.python.org/pipermail/python-dev/2006-February/060689.html

If you don't read it to the end, here is the conclusion:
"""
It sounds like the right answer for Python is to change the signature
of PyArg_ParseTupleAndKeywords() back.  We'll fix it when C fixes its
const rules <wink>.
"""

"const char*" was accepted without opposition, though.
msg62954 - (view) Author: Alexander Belopolsky (belopolsky) (Python committer) Date: 2008-02-25 00:25
Douglas Greiman submitted many similar changes with his issue2135 patch.  
His patch also amends documentation, which is missing here.

I am adding dgreiman to the nosy list here to avoid duplication of 
effort.

I am -0 on the idea.
History
Date User Action Args
2009-05-15 01:51:24ajaksu2setdependencies: + replacing char* with const char* in sysmodule.c/.h
versions: + Python 2.7, - Python 2.6
2008-02-25 00:25:46belopolskysetnosy: + belopolsky, dgreiman
messages: + msg62954
2008-01-06 12:21:09christian.heimessettype: enhancement
versions: + Python 2.6
2007-12-17 23:52:01amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg58712
2007-12-17 22:28:56gustavosetnosy: + gustavo
messages: + msg58709
2007-08-12 16:43:07ext-create