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.

Title: const arg for PyInt_FromString
Type: enhancement Stage:
Components: Extension Modules Versions: Python 3.2
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, doerwalter, gvanrossum, ncoghlan, philipdumont
Priority: low Keywords: patch

Created on 2008-01-18 18:46 by philipdumont, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
Python-2.5.patch philipdumont, 2008-01-22 20:12
autotest.out.after philipdumont, 2008-01-22 20:13 Output of test run after patch
make_test_after philipdumont, 2008-02-12 16:10 Output of 'make test' after patch
Messages (8)
msg60108 - (view) Author: phil (philipdumont) Date: 2008-01-18 18:46
In PyInt_FromString(), please change the type of the first
arg from char * to const char *.  That is, of course, if
the function indeed does not write to the string.  (I took
a quick look at the code; it doesn't appear to.)

If the function does modify the string, it should be

I'm getting a compiler error in some C++ code when I
use a std::string::c_str() as the arg.  Of course, I could
cast away the const, but paranoid as I am, I'd like
reassurance that I can do so with impunity.  :-)
msg60117 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-18 21:03
So how about submitting a patch *and* building everything from scratch
and running all the unit tests to make sure this doesn't break anything?
msg61531 - (view) Author: phil (philipdumont) Date: 2008-01-22 20:12
Oh, all right.  Just don't tell my boss -- he thinks I'm doing
"real" work.  :-)

I haven't thoroughly studied the test harness, but it looked like

  <prefix>/bin/python <prefix>/lib/python2.5/test/

was what I should do?  The output generated before/after the patch
was identical.
msg62312 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2008-02-12 12:29
The test suite is run via test/ If you aren't on windows,
'make test' works as well.

For myself, I tend to just run "./python -m test.regrtest" in the
directory where I built Python.
msg62321 - (view) Author: phil (philipdumont) Date: 2008-02-12 16:10
Ok.  Ran 'make test' before and after patch.  Output identical. 
Attaching output after patch.
msg87734 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2009-05-14 10:57
The patch no longer applies cleanly to the trunk.
msg116916 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-09-20 07:50
Any opinions as to whether the patch should be reworked for 3.2 or not?
msg116924 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-09-20 11:16
I'm rejecting this due to the effect it has on the output parameters.

The patch ends up have to stick (char *) casts in several places because a pointer into the string provided via the char * input parameter is returned by each affected API to the calling function via a char **output parameter.

We can't change the signature of the output parameters since that would break existing code. That then means we also can't change the signature of the input parameters, since we can't guarantee that the recipient of the output parameter won't later use it to change things.

The calling code knows whether or not it is going to modify the pointer it receives back, and hence whether or not it is safe to cast away the const-ness of the passed in pointer.
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46174
2010-09-20 11:16:41ncoghlansetstatus: open -> closed
resolution: rejected
messages: + msg116924
2010-09-20 07:50:04BreamoreBoysetnosy: + BreamoreBoy

messages: + msg116916
versions: - Python 2.7
2009-05-14 10:57:57doerwaltersetnosy: + doerwalter
messages: + msg87734
2009-05-13 21:55:16ajaksu2setkeywords: + patch
versions: + Python 2.7, Python 3.2, - Python 2.5
2008-02-12 16:10:23philipdumontsetfiles: + make_test_after
messages: + msg62321
2008-02-12 12:29:04ncoghlansetnosy: + ncoghlan
messages: + msg62312
2008-01-22 20:13:27philipdumontsetfiles: + autotest.out.after
2008-01-22 20:12:38philipdumontsetfiles: + Python-2.5.patch
messages: + msg61531
2008-01-18 21:03:15gvanrossumsetpriority: low
nosy: + gvanrossum
messages: + msg60117
2008-01-18 18:46:08philipdumontcreate