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: More const char
Type: enhancement Stage: resolved
Components: Extension Modules, Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, serhiy.storchaka, skrah
Priority: normal Keywords: patch

Created on 2015-12-22 12:56 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
const_char_ptr.patch serhiy.storchaka, 2015-12-22 12:56 review
Messages (9)
msg256837 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-22 12:56
Proposed patch adds the const qualifier to char* parameter declarations and static char arrays if appropriate. This makes the code more strict and can help to catch bugs or generate more efficient code. In additional it can decrease memory consumption by avoiding copying constant data.
msg257002 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-25 17:54
New changeset 3cb3e224b692 by Serhiy Storchaka in branch 'default':
Issue #25923: Added the const qualifier to static constant arrays.
https://hg.python.org/cpython/rev/3cb3e224b692
msg257004 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-25 18:02
New changeset 80d1faa9735d by Serhiy Storchaka in branch 'default':
Issue #25923: Added more const qualifiers to signatures of static and private functions.
https://hg.python.org/cpython/rev/80d1faa9735d
msg257007 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-12-25 19:28
What is the point of changing the return value of a function in
Objects/memoryobject.c to "const char *" and then casting it back
to "char *" in the one place that the function is used?

Churn like this has a direct cost for me: I have to update my
private 100% coverage patch for no gain at all.
msg257009 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-25 20:10
get_native_fmtstr() returns a pointer to C string literal. It is constant by its nature, and I thought it would be more clear to cast it explicitly if needed. It would be better (in particular for compatibility with C++) to make Py_buffer.format to be const char*, since it is borrowed reference to constant string, and often is initialized with string literal, but this is backward incompatible change of public API. I'm planning to open separate issue for backward-incompatible (controlled with a macro) constantness changing.
msg257010 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-12-25 20:36
I was faced with the same dilemma when I wrote the code and I
*deliberately* decided that returning (const char *) + an
additional cast wasn't worth it for a static function
that's used only once.
msg257014 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-25 21:36
Sorry. Do you prefer to revert this change or left it as is?
msg257022 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-12-26 10:45
There's no need to revert it.  Both versions are okay, but I wanted
to point out that these kinds of changes a) add a cognitive load for
other developers (I have to look what has changed in memoryobject.c)
and b) may override other developers' conscious decisions.
msg257169 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-29 06:48
Excuse my troubling.
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70111
2015-12-29 06:48:28serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg257169

stage: patch review -> resolved
2015-12-26 10:45:14skrahsetmessages: + msg257022
2015-12-25 21:36:54serhiy.storchakasetmessages: + msg257014
2015-12-25 20:36:20skrahsetmessages: + msg257010
2015-12-25 20:10:04serhiy.storchakasetmessages: + msg257009
2015-12-25 19:28:06skrahsetnosy: + skrah
messages: + msg257007
2015-12-25 18:02:36python-devsetmessages: + msg257004
2015-12-25 17:54:56python-devsetnosy: + python-dev
messages: + msg257002
2015-12-22 12:56:32serhiy.storchakacreate