Issue #28769: The result of PyUnicode_AsUTF8AndSize() and PyUnicode_AsUTF8()

is now of type "const char *" rather of "char *".
This commit is contained in:
Serhiy Storchaka 2017-01-22 23:07:07 +02:00
parent d528791096
commit 2a404b63d4
9 changed files with 26 additions and 13 deletions

View File

@ -1038,7 +1038,7 @@ These are the UTF-8 codec APIs:
raised by the codec. 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 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 store the size of the encoded representation (in bytes) in *size*. The
@ -1055,13 +1055,19 @@ These are the UTF-8 codec APIs:
.. versionadded:: 3.3 .. versionadded:: 3.3
.. versionchanged:: 3.7
The return type is now ``const char *`` rather of ``char *``.
.. c:function:: char* PyUnicode_AsUTF8(PyObject *unicode)
.. c:function:: const char* PyUnicode_AsUTF8(PyObject *unicode)
As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size. As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.
.. versionadded:: 3.3 .. 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) .. c:function:: PyObject* PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors)

View File

@ -124,6 +124,10 @@ Build and C API Changes
and :c:type:`wrapperbase` are now of type ``const char *`` rather of and :c:type:`wrapperbase` are now of type ``const char *`` rather of
``char *``. (Contributed by Serhiy Storchaka in :issue:`28761`.) ``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 Deprecated
========== ==========

View File

@ -1135,7 +1135,7 @@ PyAPI_FUNC(int) PyUnicode_ClearFreeList(void);
*/ */
#ifndef Py_LIMITED_API #ifndef Py_LIMITED_API
PyAPI_FUNC(char *) PyUnicode_AsUTF8AndSize( PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize(
PyObject *unicode, PyObject *unicode,
Py_ssize_t *size); Py_ssize_t *size);
#define _PyUnicode_AsStringAndSize PyUnicode_AsUTF8AndSize #define _PyUnicode_AsStringAndSize PyUnicode_AsUTF8AndSize
@ -1162,7 +1162,7 @@ PyAPI_FUNC(char *) PyUnicode_AsUTF8AndSize(
*/ */
#ifndef Py_LIMITED_API #ifndef Py_LIMITED_API
PyAPI_FUNC(char *) PyUnicode_AsUTF8(PyObject *unicode); PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode);
#define _PyUnicode_AsString PyUnicode_AsUTF8 #define _PyUnicode_AsString PyUnicode_AsUTF8
#endif #endif

View File

@ -614,6 +614,9 @@ Windows
C API 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 - 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 available only when Py_LIMITED_API is set to the PY_VERSION_HEX value of
the minimum Python version supporting this API. the minimum Python version supporting this API.

View File

@ -239,7 +239,7 @@ dbm_contains(PyObject *self, PyObject *arg)
return -1; return -1;
} }
if (PyUnicode_Check(arg)) { if (PyUnicode_Check(arg)) {
key.dptr = PyUnicode_AsUTF8AndSize(arg, &size); key.dptr = (char *)PyUnicode_AsUTF8AndSize(arg, &size);
key.dsize = size; key.dsize = size;
if (key.dptr == NULL) if (key.dptr == NULL)
return -1; return -1;

View File

@ -3199,7 +3199,7 @@ dec_format(PyObject *dec, PyObject *args)
} }
if (PyUnicode_Check(fmtarg)) { if (PyUnicode_Check(fmtarg)) {
fmt = PyUnicode_AsUTF8AndSize(fmtarg, &size); fmt = (char *)PyUnicode_AsUTF8AndSize(fmtarg, &size);
if (fmt == NULL) { if (fmt == NULL) {
return NULL; return NULL;
} }

View File

@ -319,7 +319,7 @@ dbm_contains(PyObject *self, PyObject *arg)
return -1; return -1;
} }
if (PyUnicode_Check(arg)) { if (PyUnicode_Check(arg)) {
key.dptr = PyUnicode_AsUTF8AndSize(arg, &size); key.dptr = (char *)PyUnicode_AsUTF8AndSize(arg, &size);
key.dsize = size; key.dsize = size;
if (key.dptr == NULL) if (key.dptr == NULL)
return -1; return -1;

View File

@ -890,10 +890,10 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
if (tp->tp_getattro != NULL) if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name); return (*tp->tp_getattro)(v, name);
if (tp->tp_getattr != NULL) { if (tp->tp_getattr != NULL) {
char *name_str = PyUnicode_AsUTF8(name); const char *name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL) if (name_str == NULL)
return NULL; return NULL;
return (*tp->tp_getattr)(v, name_str); return (*tp->tp_getattr)(v, (char *)name_str);
} }
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%U'", "'%.50s' object has no attribute '%U'",
@ -934,10 +934,10 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
return err; return err;
} }
if (tp->tp_setattr != NULL) { if (tp->tp_setattr != NULL) {
char *name_str = PyUnicode_AsUTF8(name); const char *name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL) if (name_str == NULL)
return -1; return -1;
err = (*tp->tp_setattr)(v, name_str, value); err = (*tp->tp_setattr)(v, (char *)name_str, value);
Py_DECREF(name); Py_DECREF(name);
return err; return err;
} }

View File

@ -3972,7 +3972,7 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr)
} }
char* const char *
PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize) PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
{ {
PyObject *bytes; PyObject *bytes;
@ -4007,7 +4007,7 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
return PyUnicode_UTF8(unicode); return PyUnicode_UTF8(unicode);
} }
char* const char *
PyUnicode_AsUTF8(PyObject *unicode) PyUnicode_AsUTF8(PyObject *unicode)
{ {
return PyUnicode_AsUTF8AndSize(unicode, NULL); return PyUnicode_AsUTF8AndSize(unicode, NULL);