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: usage of type "char*" instead of "const char*"
Type: Stage:
Components: Build Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ekholm, terry.reedy, tim.peters
Priority: normal Keywords:

Created on 2005-06-27 06:54 by ekholm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg25651 - (view) Author: Mattias Ekholm (ekholm) Date: 2005-06-27 06:54
I suspect that this is problem is not only related
"char*", but to 
most types used in the Python C API. For "char*" is
quite hard
to sircumvent.

Is there any plan to use const for all function parameters 
when the function is not altering its arguments?

regards
Mattias
msg25652 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2005-06-30 19:01
Logged In: YES 
user_id=593130

Coding style questions should be directed to comp.lang.python 
or the corresponding mail list.
In any case, Python is written in C89, not C++
msg25653 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-06-30 19:49
Logged In: YES 
user_id=31435

It's a valid question, but no, there's no plan to go on a Const 
Crusade.  Developers sometimes add const where it gets in 
the way, if they happen to working in that area anyway.  For 
example, that's how PyDict_GetItemString() grew its const 
char* key argument.  OTOH, PyMapping_GetItemString() 
does not have a const char* key argument, presumably 
because few people use it, and nobody uses it who cared 
enough yet to change it.

As a practical matter, you'd have better luck submitting a 
patch adding const where it's actually gotten in your way 
than hoping someone else will devote the rest of their life to 
slamming in const everywhere it could possibly go.
msg25654 - (view) Author: Mattias Ekholm (ekholm) Date: 2005-06-30 20:00
Logged In: YES 
user_id=889890


this is *not* a coding style question and not related to C++, 
in C string constans may reside in read only memory. 

...and it's a nuisance that the python library code is uses
const 
for char* where appropritate. 
msg25655 - (view) Author: Mattias Ekholm (ekholm) Date: 2005-06-30 20:24
Logged In: YES 
user_id=889890


I'll try to find self-confidence enough to go on a crusade
myself :-)

But, as a simple user of python libraries. I'm reluctant to
start changing
the code here-and-there.
msg25656 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-06-30 21:54
Logged In: YES 
user_id=31435

Actually, a crusade wouldn't be welcome.  We have lots of 
experience with crusades, and it's invariably the case that 
when someone checks in a large number of "mindless" 
changes, they introduce subtle bugs.  That's why developers 
are encouraged to make changes like this incrementally, 
when they happen to be working on a specific area 
_anyway_, so that they're wide awake and _thinking_ about 
that area.

Instead, how about naming the top 3 Python C API functions 
that actually get in your way?  Nobody will object to changing 
the signatures of a few functions someone has said are giving 
them actual real-life problems; the chance of screwing up a 
small task like that is tiny; and you'd get _some_ benefit 
soon.  That's better than never getting any <wink>.
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 42131
2005-06-27 06:54:42ekholmcreate