From 59d149f9b47d24a8948f9459bed26aee9e3c302a Mon Sep 17 00:00:00 2001 From: James Roy Date: Thu, 17 Apr 2025 16:02:36 +0800 Subject: [PATCH 1/7] Add missing PyUnicode_Resize() doc --- Doc/c-api/unicode.rst | 17 +++++++++++++++++ Doc/data/refcounts.dat | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 31063962ae51c5..729302d263c1af 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -666,6 +666,23 @@ APIs: .. versionadded:: 3.3 +.. c:function:: int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length); + + Resize a Unicode object. The length is the number of codepoints. + + Try to resize the string in place (which is usually faster than allocating + a new string and copy characters), or create a new string. + + ``*unicode`` is modified to point to the new (resized) object and 0 is + returned on success. Otherwise, an exception is set, -1 is returned, + and ``*unicode`` is left untouched. + + .. warning:: + + The function doesn't check string content, the result may not be a + string in canonical representation. + + .. c:function:: Py_ssize_t PyUnicode_Fill(PyObject *unicode, Py_ssize_t start, \ Py_ssize_t length, Py_UCS4 fill_char) diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 14629fbff0fb78..369f0ef0905dc8 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -2791,6 +2791,10 @@ PyUnicode_CopyCharacters:PyObject*:from:0: PyUnicode_CopyCharacters:Py_ssize_t:from_start:: PyUnicode_CopyCharacters:Py_ssize_t:how_many:: +PyUnicode_Resize:int::: +PyUnicode_Resize:PyObject**:unicode:0: +PyUnicode_Resize:Py_ssize_t:length:: + PyUnicode_Fill:Py_ssize_t::: PyUnicode_Fill:PyObject*:unicode:0: PyUnicode_Fill:Py_ssize_t:start:: From fee0803144f1ae49bdec7e347d077e9c49cbb66d Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Fri, 18 Apr 2025 09:03:52 +0800 Subject: [PATCH 2/7] Update Doc/c-api/unicode.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/unicode.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 729302d263c1af..390da93a007873 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -674,7 +674,7 @@ APIs: a new string and copy characters), or create a new string. ``*unicode`` is modified to point to the new (resized) object and 0 is - returned on success. Otherwise, an exception is set, -1 is returned, + returned on success. Otherwise, ``-1`` is returned and an exception is set, and ``*unicode`` is left untouched. .. warning:: From 0ddaa8fd41dbf2250f2fe1bae35a9278809bd43f Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Fri, 18 Apr 2025 09:04:17 +0800 Subject: [PATCH 3/7] Update Doc/c-api/unicode.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/unicode.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 390da93a007873..cfceb117c9d653 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -671,7 +671,7 @@ APIs: Resize a Unicode object. The length is the number of codepoints. Try to resize the string in place (which is usually faster than allocating - a new string and copy characters), or create a new string. + a new string and copying characters), or create a new string. ``*unicode`` is modified to point to the new (resized) object and 0 is returned on success. Otherwise, ``-1`` is returned and an exception is set, From 74fa74fc0908d7b4fd0cfd78026b89c1a65f584d Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Fri, 18 Apr 2025 09:04:24 +0800 Subject: [PATCH 4/7] Update Doc/c-api/unicode.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/unicode.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index cfceb117c9d653..9fe25ddab2e4b4 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -673,7 +673,7 @@ APIs: Try to resize the string in place (which is usually faster than allocating a new string and copying characters), or create a new string. - ``*unicode`` is modified to point to the new (resized) object and 0 is + ``*unicode`` is modified to point to the new (resized) object and ``0`` is returned on success. Otherwise, ``-1`` is returned and an exception is set, and ``*unicode`` is left untouched. From e140a381c6eb9a583b2155d1d948226c14d32022 Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Sat, 19 Apr 2025 17:09:41 +0800 Subject: [PATCH 5/7] Update Doc/c-api/unicode.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/unicode.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 9fe25ddab2e4b4..6e691d4d092da0 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -677,8 +677,6 @@ APIs: returned on success. Otherwise, ``-1`` is returned and an exception is set, and ``*unicode`` is left untouched. - .. warning:: - The function doesn't check string content, the result may not be a string in canonical representation. From b237d2f35bb4be6f8087398dcc884dc92dd7c9a5 Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Sat, 19 Apr 2025 17:10:22 +0800 Subject: [PATCH 6/7] Update Doc/c-api/unicode.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/unicode.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 6e691d4d092da0..dce92db17e5bb2 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -668,7 +668,7 @@ APIs: .. c:function:: int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length); - Resize a Unicode object. The length is the number of codepoints. + Resize a Unicode object *\*unicode* to the new *length* in code points. Try to resize the string in place (which is usually faster than allocating a new string and copying characters), or create a new string. From 037861a18b764cfe67f5ff5667aa85b6bcc74833 Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Sat, 19 Apr 2025 17:12:06 +0800 Subject: [PATCH 7/7] Change doc --- Doc/c-api/unicode.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index dce92db17e5bb2..91f414fcf51cf3 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -673,12 +673,12 @@ APIs: Try to resize the string in place (which is usually faster than allocating a new string and copying characters), or create a new string. - ``*unicode`` is modified to point to the new (resized) object and ``0`` is + *\*unicode* is modified to point to the new (resized) object and ``0`` is returned on success. Otherwise, ``-1`` is returned and an exception is set, - and ``*unicode`` is left untouched. + and *\*unicode* is left untouched. - The function doesn't check string content, the result may not be a - string in canonical representation. + The function doesn't check string content, the result may not be a + string in canonical representation. .. c:function:: Py_ssize_t PyUnicode_Fill(PyObject *unicode, Py_ssize_t start, \