From 557ec891decf80f6ee2239c2bb9254226f3c8bdb Mon Sep 17 00:00:00 2001 From: Taiju Yamada Date: Wed, 26 Feb 2025 17:06:06 +0900 Subject: [PATCH 1/2] Use AsUTF8AndSize --- python/bindings/openravepy_int.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/bindings/openravepy_int.cpp b/python/bindings/openravepy_int.cpp index 6a200efc70..444fae8929 100644 --- a/python/bindings/openravepy_int.cpp +++ b/python/bindings/openravepy_int.cpp @@ -256,7 +256,9 @@ void toRapidJSONValue(const object &obj, rapidjson::Value &value, rapidjson::Doc #if PY_MAJOR_VERSION >= 3 else if (PyUnicode_Check(obj.ptr())) { - value.SetString(PyUnicode_AsUTF8(obj.ptr()), PyUnicode_GET_LENGTH(obj.ptr()), allocator); + ssize_t size; + const char *utf8 = PyUnicode_AsUTF8AndSize(obj.ptr(), &size); + value.SetString(utf8, size, allocator); } #else else if (PyString_Check(obj.ptr())) From ac1e0690adc732df1563e89b05ba4768c01a5e4d Mon Sep 17 00:00:00 2001 From: Taiju Yamada Date: Wed, 26 Feb 2025 17:32:42 +0900 Subject: [PATCH 2/2] Add test --- test/test_kinematics.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_kinematics.py b/test/test_kinematics.py index d90dedf4de..4d82f16a48 100644 --- a/test/test_kinematics.py +++ b/test/test_kinematics.py @@ -1092,6 +1092,7 @@ def test_custombody(self): link1._mapFloatParameters = {'param0':[1,2.3]} link1._mapIntParameters = {'param0':[4,5,6]} link1._t[0,3] = 0.5 + link1.DeserializeJSON({'stringParameters': [{'id': 'jp3', 'value': u'日本語'}]}) joint0 = KinBody.JointInfo() joint0._name = 'j0' @@ -1113,6 +1114,7 @@ def test_custombody(self): assert(transdist(body.GetLinks()[1].GetTransform(), array([[ 0.69670671, -0.71735609, 0. , 0.34835335], [ 0.71735609, 0.69670671, 0. , 0.35867805], [ 0. , 0. , 1. , 0. ], [ 0. , 0. , 0. , 1. ]])) <= 1e-7) assert(body.GetLinks()[0].GetStringParameters('jp') == u'\u65e5\u672c\u8a9e') assert(body.GetJoints()[0].GetStringParameters('test2') == 'has spaces') + assert(body.GetLinks()[1].GetStringParameters('jp3') == u'\u65e5\u672c\u8a9e') # https://github.com/rdiankov/openrave/pull/1491 def test_paddinggeometry(self): env=self.env