Skip to content
Snippets Groups Projects
Commit d358b4a1 authored by olivier stasse's avatar olivier stasse
Browse files

Robustify the python interpreter when some python objects cannot be stringified.

parent b43fa1da
No related branches found
No related tags found
No related merge requests found
...@@ -110,7 +110,11 @@ std::string Interpreter::python( const std::string& command ) ...@@ -110,7 +110,11 @@ std::string Interpreter::python( const std::string& command )
} else { } else {
result = PyObject_Repr(result); result = PyObject_Repr(result);
} }
std::string value = PyString_AsString(result); std::string value = "";
// PyString_AsString will generate a segv if result is NULL.
// This might be the case if PyObject_Repr fails.
if (result!=NULL)
value = PyString_AsString(result);
return value; return value;
} }
...@@ -157,9 +161,13 @@ void Interpreter::python( const std::string& command, std::string& res, ...@@ -157,9 +161,13 @@ void Interpreter::python( const std::string& command, std::string& res,
Py_eval_input, globals_, Py_eval_input, globals_,
globals_); globals_);
out = PyString_AsString(stdout_obj); out = PyString_AsString(stdout_obj);
// Local display for the robot (in debug mode or for the logs)
std::cout << out; std::cout << out;
result = PyObject_Repr(result); result = PyObject_Repr(result);
res = PyString_AsString(result); // If python cannot build a string representation of result
// then results is equal to NULL. This will trigger a SEGV
if (result!=NULL)
res = PyString_AsString(result);
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment