diff options
-rw-r--r-- | Doc/c-api/unicode.rst | 10 | ||||
-rw-r--r-- | Doc/whatsnew/3.7.rst | 4 | ||||
-rw-r--r-- | Include/unicodeobject.h | 4 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_dbmmodule.c | 2 | ||||
-rw-r--r-- | Modules/_decimal/_decimal.c | 2 | ||||
-rw-r--r-- | Modules/_gdbmmodule.c | 2 | ||||
-rw-r--r-- | Objects/object.c | 8 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 4 |
9 files changed, 26 insertions, 13 deletions
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index a5d6c86..bcae44e 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -1038,7 +1038,7 @@ These are the UTF-8 codec APIs: 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 @@ These are the UTF-8 codec APIs: .. 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) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index fe03def..5353a14 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -124,6 +124,10 @@ Build and C API Changes 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 index 87cd96d..6a0740a 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -1135,7 +1135,7 @@ PyAPI_FUNC(int) PyUnicode_ClearFreeList(void); */ #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 @@ PyAPI_FUNC(char *) 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 @@ -614,6 +614,9 @@ Windows 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 index 804978a..52bdd0b 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -239,7 +239,7 @@ dbm_contains(PyObject *self, PyObject *arg) 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 index fcc1f15..933b3f5 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3199,7 +3199,7 @@ dec_format(PyObject *dec, PyObject *args) } 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 index daae71d..b727ba6 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -319,7 +319,7 @@ dbm_contains(PyObject *self, PyObject *arg) 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 index 7b80bcb..93cdc10 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -890,10 +890,10 @@ PyObject_GetAttr(PyObject *v, PyObject *name) 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 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) 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 index 5fbe56c..b711f0c 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3972,7 +3972,7 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr) } -char* +const char * PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize) { PyObject *bytes; @@ -4007,7 +4007,7 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize) return PyUnicode_UTF8(unicode); } -char* +const char * PyUnicode_AsUTF8(PyObject *unicode) { return PyUnicode_AsUTF8AndSize(unicode, NULL); |