[pygobject] Replace PyUnicode_GET_SIZE() usage with PyUnicode_GET_LENGTH()
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Replace PyUnicode_GET_SIZE() usage with PyUnicode_GET_LENGTH()
- Date: Tue, 6 Oct 2020 11:41:39 +0000 (UTC)
commit c945c99fbadb4496ff0fc01d42efd786abf5fba8
Author: Christoph Reiter <reiter christoph gmail com>
Date: Tue Oct 6 11:59:17 2020 +0200
Replace PyUnicode_GET_SIZE() usage with PyUnicode_GET_LENGTH()
PyUnicode_GET_SIZE() is deprecated and actually wrong in case wchar_t
is not 4 bytes and high code points, use PyUnicode_GET_LENGTH() instead.
Fixes a deprecation warning with Python 3.9
gi/pygi-basictype.c | 2 +-
tests/test_everything.py | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c
index 2864d918..82f8a85a 100644
--- a/gi/pygi-basictype.c
+++ b/gi/pygi-basictype.c
@@ -192,7 +192,7 @@ pygi_gunichar_from_py (PyObject *py_arg, gunichar *result)
if (PyUnicode_Check (py_arg)) {
PyObject *py_bytes;
- size = PyUnicode_GET_SIZE (py_arg);
+ size = PyUnicode_GET_LENGTH (py_arg);
py_bytes = PyUnicode_AsUTF8String (py_arg);
if (!py_bytes)
return FALSE;
diff --git a/tests/test_everything.py b/tests/test_everything.py
index ba1b0629..968cf785 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -359,6 +359,7 @@ class TestEverything(unittest.TestCase):
def test_unichar(self):
self.assertEqual("c", Everything.test_unichar("c"))
+ self.assertEqual(chr(sys.maxunicode), Everything.test_unichar(chr(sys.maxunicode)))
self.assertEqual(u"♥", Everything.test_unichar(u"♥"))
self.assertRaises(TypeError, Everything.test_unichar, "")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]