[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-04-26 Thread STINNER Victor

STINNER Victor added the comment:


New changeset 6e676954de7c4f3f06dd5b56842c9a2c931a1cab by Victor Stinner in 
branch 'master':
timemodule.c: Cast PyUnicode_AsUTF8() to char* (#1294)
https://github.com/python/cpython/commit/6e676954de7c4f3f06dd5b56842c9a2c931a1cab


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-04-26 Thread Stefan Krah

Changes by Stefan Krah :


--
nosy:  -skrah

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-04-26 Thread Martin Panter

Changes by Martin Panter :


--
nosy:  -martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-04-26 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests:  -1072

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-04-26 Thread STINNER Victor

Changes by STINNER Victor :


--
pull_requests: +1401

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-03-31 Thread Donald Stufft

Changes by Donald Stufft :


--
pull_requests: +1072

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-01-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-01-22 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 0d89212941f4 by Serhiy Storchaka in branch 'default':
Issue #28769: The result of PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8()
https://hg.python.org/cpython/rev/0d89212941f4

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-01-22 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-01-22 Thread Stefan Krah

Stefan Krah added the comment:

For _decimal I'm happy with just the cast from the first patch -- you have a 
one line diff and it's easy to see the focus of the issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2017-01-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Stefan, what are your thoughts about this? The patch touches _decimal.c.

--
nosy: +skrah

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2016-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Addressed comments, added the versionchanged directives, the code in _decimal.c 
is now more obvious.

--
Added file: http://bugs.python.org/file45981/PyUnicode_AsUTF8-const-2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2016-12-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Opened a topic on Python-Dev: 
https://mail.python.org/pipermail/python-dev/2016-December/147029.html.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2016-11-22 Thread STINNER Victor

STINNER Victor added the comment:

Hum, sorry, my opinion on const is not obvious in my previous message: I like 
const :-) I want to use const everywhere! I still "believe" (I don't know if 
it's true or not) that const helps a lot compilers to optimize the code.

I don't know if it helps for a single variable. Maybe it's more helpful on a 
whole structure and/or pointers to avoid complex heuristics on aliasing.

My first attempt to design the _PyBytesWriter API was a big mistake: it was 
much slower: issue #17742. I understood that using a structure instead of 
multiple variables does stress the compiler who doesn't know if some 
optimizations are still save. In case of doubt, the compiler doesn't optimize 
to avoid generating invalid code.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2016-11-22 Thread STINNER Victor

STINNER Victor added the comment:

Hum, I would like to discuss this topic on python-dev.

Changing PyUnicode_AsUTF8() alone is fine, but the issue with changing return 
type is that the const has to be propagated to callers, and then to callers of 
callers, etc. For example, if your patch, you cast (const char*) to (char*) to 
call tp_getattr.

The question is why tp_getattr doesn't use (const char*)?

I would prefer to take an overall decision for the C API, to decide if it's ok 
to "propagate" const changes in various places of the C API.

About the stable API: in fact, it's more a stable *ABI*: PEP 384, "Defining a 
Stable ABI". At the ABI level, there is no more "const". So it's perfectly fine 
to add or remove const, we already did that in the past.

Obviously, such change should only be done in Python 3.7.

For me, the main issue is for Python modules compiled with -Werror: if they 
upgrade to Python 3.7, the compilation will fail because they cast (const 
char*) to (char*) implicitly, which is a warning when using -Wall -Wextra, 
warning converted to a compilation error.

That's why I suggest to have an overall discussion on const on python-dev ;-)

--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2016-11-22 Thread Martin Panter

Martin Panter added the comment:

No opinion if this is a good change to make, but I left some review suggestions

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28769] Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"

2016-11-21 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8() return a reference to cached 
readonly UTF-8 representation of a string. Changing the content of the UTF-8 
representation is an error. Proposed patch makes these functions returning 
"const char *" rather of "char *" to force this restriction.

This is backward-incompatible change. Since PyUnicode_AsUTF8AndSize() and 
PyUnicode_AsUTF8() can return an error, it is more likely that the result is 
saved in a local variable rather than passing to other function. If the type of 
this variable is "char *" rather than "const char *", this would cause a 
compiler error. The fix is simple -- just add the const qualifier to the local 
variable declaration (more preferable) or cast the result of 
PyUnicode_AsUTF8AndSize() or PyUnicode_AsUTF8() to "char *".

Both functions are not in stable API.

--
components: Interpreter Core
files: PyUnicode_AsUTF8-const.patch
keywords: patch
messages: 281439
nosy: ncoghlan, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Make PyUnicode_AsUTF8 returning "const char *" rather of "char *"
type: enhancement
versions: Python 3.7
Added file: http://bugs.python.org/file45596/PyUnicode_AsUTF8-const.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com