File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -244,11 +244,19 @@ PyObject *fromMetadata(MetadataNode m)
244244 PyList_Append (submeta, fromMetadata (child));
245245 }
246246 PyObject *data = PyDict_New ();
247- PyDict_SetItemString (data, " name" , PyUnicode_FromString (name.data ()));
248- PyDict_SetItemString (data, " value" , PyUnicode_FromString (value.data ()));
249- PyDict_SetItemString (data, " type" , PyUnicode_FromString (type.data ()));
250- PyDict_SetItemString (data, " description" ,
251- PyUnicode_FromString (description.data ()));
247+
248+ auto getString = [](const std::string& s)
249+ {
250+ PyObject *o = PyUnicode_FromString (s.data ());
251+ if (!o)
252+ o = PyUnicode_FromString (" <INVALID UNICODE>" );
253+ return o;
254+ };
255+
256+ PyDict_SetItemString (data, " name" , getString (name));
257+ PyDict_SetItemString (data, " value" , getString (value));
258+ PyDict_SetItemString (data, " type" , getString (value));
259+ PyDict_SetItemString (data, " description" , getString (description));
252260
253261 if (children.size ())
254262 PyDict_SetItemString (data, " children" , submeta);
You can’t perform that action at this time.
0 commit comments