summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2020-10-06 11:59:17 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2020-10-06 12:01:19 +0200
commitc945c99fbadb4496ff0fc01d42efd786abf5fba8 (patch)
tree76f7fdd6d3928fb36f1cdb78f78ad2b56df281f6
parent2913e72d85269d6b307dc054946a88cbba6707de (diff)
downloadpygobject-c945c99fbadb4496ff0fc01d42efd786abf5fba8.tar.gz
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
-rw-r--r--gi/pygi-basictype.c2
-rw-r--r--tests/test_everything.py1
2 files changed, 2 insertions, 1 deletions
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, "")