| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,12 +2,12 @@ | |||
| 2 | 2 | pythoncapi_compat.h API | |
| 3 | 3 | +++++++++++++++++++++++ | |
| 4 | 4 | ||
| 5 | - The ``pythoncapi_compat.h`` header file provides implementations of recent | ||
| 6 | - functions for old Python versions. | ||
| 5 | + The ``pythoncapi_compat.h`` header file provides implementations of around 150 | ||
| 6 | + recent functions for old Python versions. | ||
| 7 | 7 | ||
| 8 | 8 | Supported Python versions: | |
| 9 | 9 | ||
| 10 | - * Python 3.6 - 3.15 | ||
| 10 | + * Python 3.6 - 3.16 | ||
| 11 | 11 | * PyPy 3.6 - 3.12 | |
| 12 | 12 | ||
| 13 | 13 | C++03 and C++11 are supported on Python 3.6 and newer. | |
@@ -193,6 +193,12 @@ Python 3.14 | |||
| 193 | 193 | ||
| 194 | 194 | Not available on the limited C API. | |
| 195 | 195 | ||
| 196 | + .. c:function:: int PyUnicodeWriter_WriteUCS4(PyUnicodeWriter *writer, const Py_UCS4 *ucs4, Py_ssize_t size) | ||
| 197 | + | ||
| 198 | + See `PyUnicodeWriter_WriteUCS4() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteUCS4>`__. | ||
| 199 | + | ||
| 200 | + Not available on the limited C API. | ||
| 201 | + | ||
| 196 | 202 | .. c:function:: int PyUnicodeWriter_WriteUTF8(PyUnicodeWriter *writer, const char *str, Py_ssize_t size) | |
| 197 | 203 | ||
| 198 | 204 | See `PyUnicodeWriter_WriteUTF8() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteUTF8>`__. | |
@@ -338,7 +344,6 @@ Not supported: | |||
| 338 | 344 | * ``PyInitConfig_SetStrList()`` | |
| 339 | 345 | * ``PyType_GetBaseByToken()`` | |
| 340 | 346 | * ``PyUnicodeWriter_DecodeUTF8Stateful()`` | |
| 341 | - * ``PyUnicodeWriter_WriteUCS4()`` | ||
| 342 | 347 | * ``Py_InitializeFromInitConfig()`` | |
| 343 | 348 | ||
| 344 | 349 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | Changelog | |
| 2 | 2 | ========= | |
| 3 | 3 | ||
| 4 | + * 2026-10-10: Add ``PyUnicodeWriter_WriteUCS4()`` function. | ||
| 4 | 5 | * 2026-10-08: Add support for the limited C API 3.2. | |
| 5 | 6 | * 2026-10-08: Add functions: | |
| 6 | 7 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1645,6 +1645,21 @@ PyUnicodeWriter_WriteSubstring(PyUnicodeWriter *writer, PyObject *str, | |||
| 1645 | 1645 | start, end); | |
| 1646 | 1646 | } | |
| 1647 | 1647 | ||
| 1648 | + static inline int | ||
| 1649 | + PyUnicodeWriter_WriteUCS4(PyUnicodeWriter *writer, | ||
| 1650 | + const Py_UCS4 *ucs4, Py_ssize_t size) | ||
| 1651 | + { | ||
| 1652 | + PyObject *str = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, | ||
| 1653 | + ucs4, size); | ||
| 1654 | + if (str == NULL) { | ||
| 1655 | + return -1; | ||
| 1656 | + } | ||
| 1657 | + | ||
| 1658 | + int res = _PyUnicodeWriter_WriteStr((_PyUnicodeWriter*)writer, str); | ||
| 1659 | + Py_DECREF(str); | ||
| 1660 | + return res; | ||
| 1661 | + } | ||
| 1662 | + | ||
| 1648 | 1663 | static inline int | |
| 1649 | 1664 | PyUnicodeWriter_Format(PyUnicodeWriter *writer, const char *format, ...) | |
| 1650 | 1665 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1899,6 +1899,7 @@ test_unicodewriter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) | |||
| 1899 | 1899 | return NULL; | |
| 1900 | 1900 | } | |
| 1901 | 1901 | int ret; | |
| 1902 | + const Py_UCS4 ucs4[] = {'u', 'c', 's', '4'}; | ||
| 1902 | 1903 | ||
| 1903 | 1904 | // test PyUnicodeWriter_WriteStr() | |
| 1904 | 1905 | PyObject *str = PyUnicode_FromString("var"); | |
@@ -1940,6 +1941,14 @@ test_unicodewriter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) | |||
| 1940 | 1941 | goto error; | |
| 1941 | 1942 | } | |
| 1942 | 1943 | ||
| 1944 | + // test PyUnicodeWriter_WriteUCS4() | ||
| 1945 | + if (PyUnicodeWriter_WriteUCS4(writer, ucs4, Py_ARRAY_LENGTH(ucs4)) < 0) { | ||
| 1946 | + goto error; | ||
| 1947 | + } | ||
| 1948 | + if (PyUnicodeWriter_WriteChar(writer, ' ') < 0) { | ||
| 1949 | + goto error; | ||
| 1950 | + } | ||
| 1951 | + | ||
| 1943 | 1952 | // test PyUnicodeWriter_WriteRepr() | |
| 1944 | 1953 | str = PyUnicode_FromString("repr"); | |
| 1945 | 1954 | if (str == NULL) { | |
@@ -1958,7 +1967,7 @@ test_unicodewriter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) | |||
| 1958 | 1967 | if (result == NULL) { | |
| 1959 | 1968 | return NULL; | |
| 1960 | 1969 | } | |
| 1961 | - const char *expected = "var=long non-ASCII valu\xC3\xA9 'repr'<NULL>"; | ||
| 1970 | + const char *expected = "var=long non-ASCII valu\xC3\xA9 ucs4 'repr'<NULL>"; | ||
| 1962 | 1971 | assert(PyUnicode_EqualToUTF8(result, expected)); | |
| 1963 | 1972 | Py_DECREF(result); | |
| 1964 | 1973 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments