Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph-python
Commits
d358b4a1
Commit
d358b4a1
authored
Jul 20, 2012
by
olivier stasse
Browse files
Robustify the python interpreter when some python objects cannot be stringified.
parent
b43fa1da
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/interpreter.cc
View file @
d358b4a1
...
...
@@ -110,7 +110,11 @@ std::string Interpreter::python( const std::string& command )
}
else
{
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
;
}
...
...
@@ -157,9 +161,13 @@ void Interpreter::python( const std::string& command, std::string& res,
Py_eval_input
,
globals_
,
globals_
);
out
=
PyString_AsString
(
stdout_obj
);
// Local display for the robot (in debug mode or for the logs)
std
::
cout
<<
out
;
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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment