Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AsUTF8AndSize #1491

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/bindings/openravepy_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
2 changes: 2 additions & 0 deletions test/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
Loading