Skip to content
Snippets Groups Projects
Commit a9cf7232 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr
Browse files

Fix bug in getCommandDocstring.

    When help was invoked with a wrong command name, the interpreter failed with
    segmentation fault.
parent 4657223e
No related branches found
No related tags found
No related merge requests found
...@@ -294,15 +294,20 @@ namespace dynamicgraph { ...@@ -294,15 +294,20 @@ namespace dynamicgraph {
} }
void* pointer = PyCObject_AsVoidPtr(object); void* pointer = PyCObject_AsVoidPtr(object);
Entity* entity = (Entity*)pointer; Entity* entity = (Entity*)pointer;
typedef std::map<const std::string, command::Command*> CommandMap; typedef std::map<const std::string, command::Command*> commandMap_t;
CommandMap map = entity->getNewStyleCommandMap(); typedef std::map<const std::string, command::Command*>::iterator
iterator_t;
commandMap_t map = entity->getNewStyleCommandMap();
command::Command* command = NULL; command::Command* command = NULL;
try { iterator_t it = map.find(commandName);
command = map[commandName]; if (it == map.end()) {
} catch (const std::exception& exc) { std::ostringstream oss;
PyErr_SetString(dgpyError, exc.what()); oss << "'" << entity->getName() << "' entity has no command '"
<< commandName << "'.";
PyErr_SetString(PyExc_AttributeError, oss.str().c_str());
return NULL; return NULL;
} }
command = it->second;
std::string docstring = command->getDocstring(); std::string docstring = command->getDocstring();
return Py_BuildValue("s", docstring.c_str()); return Py_BuildValue("s", docstring.c_str());
} }
......
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