This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: deprecated conversion from string constant to char *
Type: compile error Stage: resolved
Components: Extension Modules Versions: Python 3.2
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Trundle, barry-scott, berker.peksag, loewis, r.david.murray, sebastinas
Priority: normal Keywords: patch

Created on 2009-09-20 11:29 by barry-scott, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
const_api_r75468.patch barry-scott, 2009-10-17 18:01 Patch to add const to python API for strings review
const_api_r75619.patch barry-scott, 2009-10-22 19:30 Patch to add const to python API for strings (2) review
Messages (13)
msg92890 - (view) Author: Barry Alan Scott (barry-scott) * Date: 2009-09-20 11:29
Many Python API functions are causing GCC to rightly complain
that const char * strings are being passed to python functions
that take char * but do not need to modify the args.

g++ reports example.cxx:633: warning: deprecated conversion from string
constant to ‘char*’

The example I encountered today, while testing PyCXX against
G++ 4.2.1 on Mac OS X, was PyObject_CallMethod
but it is not limited to this function.

Would a patch help progress this issue?
msg92917 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-09-20 20:50
A patch would definitely help. Such a patch shouldn't whole-sale replace
char with const char, but selectively only change locations where it is
actually necessary and doesn't hurt.
msg92931 - (view) Author: Andreas Stührk (Trundle) * Date: 2009-09-21 11:08
See also issue #1699259.
msg92938 - (view) Author: Barry Alan Scott (barry-scott) * Date: 2009-09-21 13:23
I'd guess that this change can first be made against 2.7 and 3.2
so that API's do not change.

Where do I find the source code to generate the patch against
for 2.7 and 3.2?
msg92940 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-09-21 13:55
Take a look at http://www.python.org/dev, specifically the 'How to Get
Started' article (which points you to the developer's FAQ, which
explains how to do an anonymous checkout of the source).
msg92942 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-09-21 14:02
I'm setting the targets to 2.7/3.2 per the discussion in issue #1699259.
 Perhaps the question of whether or not it is "really" an API change
could be revisited, but if so that would probably have to go through
python-dev.
msg94184 - (view) Author: Barry Alan Scott (barry-scott) * Date: 2009-10-17 18:01
Here is my 1st patch to allow const char * and const Py_UNICODE *
It is agsinst http://svn.python.org/projects/python/trunk.

What I have attempted to do is stop the public API of python needing
char * or Py_UNICODE * where the API clearly does not need to modify
the argument. I have only modified internal API where its necessary
to provide a public const API.

Please give feedback and let me know if you wish me raise anything
with python dev.

I'm happy to produce a 3.2 version of the patch after the 2.7 version
is acceptable.

Barry
msg94189 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-10-17 20:52
Without looking into the details: the places where you cast-away
constness look wrong. Either the parameter shouldn't have been declared
const, or the target of the assignment needs to be converted to const,
too. If the cast is really legitimite, a comment needs to justify it
(but then, I think I would still prefer not to change the parameter to
const).
msg94214 - (view) Author: Barry Alan Scott (barry-scott) * Date: 2009-10-18 15:18
I was trying to avoid changing the const ness of output parameters.
Given the advice not to go mad on putting const everywhere.

1) I can comment the casts to maintain this goal.
2) Or change the output paramter const ness.

Given your feedback I'm guessing you want me to go further with 
the use of const and do (2).

Barry
msg94223 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-10-18 20:03
> 1) I can comment the casts to maintain this goal.
> 2) Or change the output paramter const ness.
> 
> Given your feedback I'm guessing you want me to go further with 
> the use of const and do (2).

Ah, ok - as I said, I didn't look into detail further. IIUC, changing
output parameters to const could break existing code (right?); this
should be avoided absolutely.

Rather than having the casts, I think I would prefer to take no action
at these places; I recommend to discuss that on python-dev (some may
argue in favor of changing output pointers to const if that is
semantically correct).
msg94368 - (view) Author: Barry Alan Scott (barry-scott) * Date: 2009-10-22 19:30
Updated patch with comment explaining cast.
msg110580 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-17 16:34
Drop 2.7 as it's gone.  See also #1699259.
msg323126 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-08-05 00:57
All changes (except PyUnicode_EncodeDecimal() which was deprecated in Python 3.3) have already been implemented in the following commits:

* https://github.com/python/cpython/commit/c679227e31245b0e8dec74a1f7cc77710541d985
* https://github.com/python/cpython/commit/f308132cc29eea9b7fe899deb575d29d607a48f4
* https://github.com/python/cpython/commit/f0b463ad845c7433a0c561ef2c71d350f4b508c5

Closing this as 'out of date'.
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51201
2018-08-05 00:57:44berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg323126

resolution: out of date
stage: resolved
2014-02-03 19:20:38BreamoreBoysetnosy: - BreamoreBoy
2010-07-17 16:34:51BreamoreBoysetnosy: + BreamoreBoy

messages: + msg110580
versions: - Python 2.7
2009-10-22 19:30:18barry-scottsetfiles: + const_api_r75619.patch

messages: + msg94368
2009-10-18 20:03:11loewissetmessages: + msg94223
2009-10-18 15:18:44barry-scottsetnosy: loewis, barry-scott, sebastinas, r.david.murray, Trundle
messages: + msg94214
components: + Extension Modules, - Interpreter Core
2009-10-17 20:52:56loewissetmessages: + msg94189
2009-10-17 18:01:16barry-scottsetfiles: + const_api_r75468.patch
keywords: + patch
messages: + msg94184
2009-09-21 14:02:36r.david.murraysetpriority: normal

messages: + msg92942
versions: + Python 2.7, Python 3.2, - Python 2.6, Python 3.1
2009-09-21 13:55:24r.david.murraysetnosy: + r.david.murray
messages: + msg92940
2009-09-21 13:23:14barry-scottsetmessages: + msg92938
2009-09-21 11:40:30sebastinassetnosy: + sebastinas
2009-09-21 11:08:31Trundlesetnosy: + Trundle
messages: + msg92931
2009-09-20 20:50:32loewissetnosy: + loewis
messages: + msg92917
2009-09-20 11:29:45barry-scottcreate