[Python-checkins] cpython: Issue #28769: The result of PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8()
serhiy.storchaka
python-checkins at python.org
Sun Jan 22 16:07:25 EST 2017
https://hg.python.org/cpython/rev/0d89212941f4
changeset: 106263:0d89212941f4
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Jan 22 23:07:07 2017 +0200
summary:
Issue #28769: The result of PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8()
is now of type "const char *" rather of "char *".
files:
Doc/c-api/unicode.rst | 12 +++++++++---
Doc/whatsnew/3.7.rst | 4 ++++
Include/unicodeobject.h | 4 ++--
Misc/NEWS | 3 +++
Modules/_dbmmodule.c | 2 +-
Modules/_decimal/_decimal.c | 2 +-
Modules/_gdbmmodule.c | 2 +-
Objects/object.c | 8 ++++----
Objects/unicodeobject.c | 4 ++--
9 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst
--- a/Doc/c-api/unicode.rst
+++ b/Doc/c-api/unicode.rst
@@ -1038,7 +1038,7 @@
raised by the codec.
-.. c:function:: char* PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size)
+.. c:function:: const char* PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size)
Return a pointer to the UTF-8 encoding of the Unicode object, and
store the size of the encoded representation (in bytes) in *size*. The
@@ -1055,13 +1055,19 @@
.. versionadded:: 3.3
-
-.. c:function:: char* PyUnicode_AsUTF8(PyObject *unicode)
+ .. versionchanged:: 3.7
+ The return type is now ``const char *`` rather of ``char *``.
+
+
+.. c:function:: const char* PyUnicode_AsUTF8(PyObject *unicode)
As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.
.. versionadded:: 3.3
+ .. versionchanged:: 3.7
+ The return type is now ``const char *`` rather of ``char *``.
+
.. c:function:: PyObject* PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst
--- a/Doc/whatsnew/3.7.rst
+++ b/Doc/whatsnew/3.7.rst
@@ -124,6 +124,10 @@
and :c:type:`wrapperbase` are now of type ``const char *`` rather of
``char *``. (Contributed by Serhiy Storchaka in :issue:`28761`.)
+* The result of :c:func:`PyUnicode_AsUTF8AndSize` and :c:func:`PyUnicode_AsUTF8`
+ is now of type ``const char *`` rather of ``char *``.
+ (Contributed by Serhiy Storchaka in :issue:`28769`.)
+
Deprecated
==========
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -1135,7 +1135,7 @@
*/
#ifndef Py_LIMITED_API
-PyAPI_FUNC(char *) PyUnicode_AsUTF8AndSize(
+PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize(
PyObject *unicode,
Py_ssize_t *size);
#define _PyUnicode_AsStringAndSize PyUnicode_AsUTF8AndSize
@@ -1162,7 +1162,7 @@
*/
#ifndef Py_LIMITED_API
-PyAPI_FUNC(char *) PyUnicode_AsUTF8(PyObject *unicode);
+PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode);
#define _PyUnicode_AsString PyUnicode_AsUTF8
#endif
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -614,6 +614,9 @@
C API
-----
+- Issue #28769: The result of PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8()
+ is now of type "const char *" rather of "char *".
+
- Issue #29058: All stable API extensions added after Python 3.2 are now
available only when Py_LIMITED_API is set to the PY_VERSION_HEX value of
the minimum Python version supporting this API.
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -239,7 +239,7 @@
return -1;
}
if (PyUnicode_Check(arg)) {
- key.dptr = PyUnicode_AsUTF8AndSize(arg, &size);
+ key.dptr = (char *)PyUnicode_AsUTF8AndSize(arg, &size);
key.dsize = size;
if (key.dptr == NULL)
return -1;
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -3199,7 +3199,7 @@
}
if (PyUnicode_Check(fmtarg)) {
- fmt = PyUnicode_AsUTF8AndSize(fmtarg, &size);
+ fmt = (char *)PyUnicode_AsUTF8AndSize(fmtarg, &size);
if (fmt == NULL) {
return NULL;
}
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -319,7 +319,7 @@
return -1;
}
if (PyUnicode_Check(arg)) {
- key.dptr = PyUnicode_AsUTF8AndSize(arg, &size);
+ key.dptr = (char *)PyUnicode_AsUTF8AndSize(arg, &size);
key.dsize = size;
if (key.dptr == NULL)
return -1;
diff --git a/Objects/object.c b/Objects/object.c
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -890,10 +890,10 @@
if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name);
if (tp->tp_getattr != NULL) {
- char *name_str = PyUnicode_AsUTF8(name);
+ const char *name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL)
return NULL;
- return (*tp->tp_getattr)(v, name_str);
+ return (*tp->tp_getattr)(v, (char *)name_str);
}
PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%U'",
@@ -934,10 +934,10 @@
return err;
}
if (tp->tp_setattr != NULL) {
- char *name_str = PyUnicode_AsUTF8(name);
+ const char *name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL)
return -1;
- err = (*tp->tp_setattr)(v, name_str, value);
+ err = (*tp->tp_setattr)(v, (char *)name_str, value);
Py_DECREF(name);
return err;
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3972,7 +3972,7 @@
}
-char*
+const char *
PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
{
PyObject *bytes;
@@ -4007,7 +4007,7 @@
return PyUnicode_UTF8(unicode);
}
-char*
+const char *
PyUnicode_AsUTF8(PyObject *unicode)
{
return PyUnicode_AsUTF8AndSize(unicode, NULL);
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list