is now of type "const char *" rather of "char *".
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
.. 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.
.. 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)
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
==========
*/
#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
*/
#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
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.
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;
}
if (PyUnicode_Check(fmtarg)) {
- fmt = PyUnicode_AsUTF8AndSize(fmtarg, &size);
+ fmt = (char *)PyUnicode_AsUTF8AndSize(fmtarg, &size);
if (fmt == NULL) {
return NULL;
}
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;
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'",
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;
}
}
-char*
+const char *
PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
{
PyObject *bytes;
return PyUnicode_UTF8(unicode);
}
-char*
+const char *
PyUnicode_AsUTF8(PyObject *unicode)
{
return PyUnicode_AsUTF8AndSize(unicode, NULL);