Commit c4c2f5a2 authored by Guilhem Saurel's avatar Guilhem Saurel

add macro DGPYERROR

parent 34b43cad
...@@ -22,7 +22,6 @@ typedef boost::shared_ptr<std::ofstream> ofstreamShrPtr; ...@@ -22,7 +22,6 @@ typedef boost::shared_ptr<std::ofstream> ofstreamShrPtr;
namespace dynamicgraph { namespace dynamicgraph {
namespace python { namespace python {
extern PyObject* dgpyError;
namespace debug { namespace debug {
std::map<std::string, ofstreamShrPtr> mapOfFiles_; std::map<std::string, ofstreamShrPtr> mapOfFiles_;
......
...@@ -105,7 +105,7 @@ PyObject* error_out( ...@@ -105,7 +105,7 @@ PyObject* error_out(
#endif #endif
{ {
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
PyObject *module = PyModule_Create(&dynamicgraph::python::moduledef); PyObject *module = PyModule_Create(&dynamicgraph::python::dynamicGraphModuleDef);
#else #else
PyObject *module = Py_InitModule("dynamic_graph", dynamicgraph::python::dynamicGraphMethods); PyObject *module = Py_InitModule("dynamic_graph", dynamicgraph::python::dynamicGraphMethods);
#endif #endif
...@@ -114,7 +114,7 @@ PyObject* error_out( ...@@ -114,7 +114,7 @@ PyObject* error_out(
INITERROR; INITERROR;
struct dynamicgraph::python::module_state *st = GETSTATE(module); struct dynamicgraph::python::module_state *st = GETSTATE(module);
st->dgpyError = PyErr_NewException(const_cast<char*>("dynamic_graph.dgpyError"), NULL, NULL); DGPYERROR = PyErr_NewException(const_cast<char*>("dynamic_graph.dgpyError"), NULL, NULL);
if (st->dgpyError == NULL) { if (st->dgpyError == NULL) {
Py_DECREF(module); Py_DECREF(module);
INITERROR; INITERROR;
......
...@@ -171,7 +171,7 @@ static PyMethodDef dynamicGraphMethods[] = { ...@@ -171,7 +171,7 @@ static PyMethodDef dynamicGraphMethods[] = {
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
__attribute__((unused)) __attribute__((unused))
static struct PyModuleDef moduledef = { static struct PyModuleDef dynamicGraphModuleDef = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"dynamic_graph", "dynamic_graph",
NULL, NULL,
...@@ -183,11 +183,13 @@ static struct PyModuleDef moduledef = { ...@@ -183,11 +183,13 @@ static struct PyModuleDef moduledef = {
NULL NULL
}; };
#define GETSTATE(m) ((struct dynamicgraph::python::module_state*)PyModule_GetState(m)) #define GETSTATE(m) ((struct dynamicgraph::python::module_state*)PyModule_GetState(m))
#define DGPYERROR GETSTATE(PyState_FindModule(&dynamicgraph::python::dynamicGraphModuleDef))->dgpyError
#define INITERROR return NULL #define INITERROR return NULL
#else #else
__attribute__((unused)) __attribute__((unused))
static struct module_state _state; static struct module_state _state;
#define GETSTATE(m) (&dynamicgraph::python::_state) #define GETSTATE(m) (&dynamicgraph::python::_state)
#define DGPYERROR dynamicgraph::python::_state.dgpyError
#define INITERROR return #define INITERROR return
#endif #endif
......
...@@ -31,7 +31,6 @@ using dynamicgraph::command::Value; ...@@ -31,7 +31,6 @@ using dynamicgraph::command::Value;
namespace dynamicgraph { namespace dynamicgraph {
namespace python { namespace python {
extern PyObject* dgpyError;
using namespace convert; using namespace convert;
namespace entity { namespace entity {
...@@ -53,7 +52,7 @@ PyObject* create(PyObject* /*self*/, PyObject* args) { ...@@ -53,7 +52,7 @@ PyObject* create(PyObject* /*self*/, PyObject* args) {
",\n" ",\n"
"but this object is of type " + "but this object is of type " +
std::string(obj->getClassName()) + " and not " + std::string(className)); std::string(obj->getClassName()) + " and not " + std::string(className));
PyErr_SetString(dgpyError, msg.c_str()); PyErr_SetString(DGPYERROR, msg.c_str());
return NULL; return NULL;
} }
} else /* If not, create a new object. */ } else /* If not, create a new object. */
...@@ -238,7 +237,7 @@ PyObject* executeCommand(PyObject* /*self*/, PyObject* args) { ...@@ -238,7 +237,7 @@ PyObject* executeCommand(PyObject* /*self*/, PyObject* args) {
if ((unsigned)size != typeVector.size()) { if ((unsigned)size != typeVector.size()) {
std::stringstream ss; std::stringstream ss;
ss << "command takes " << typeVector.size() << " parameters, " << size << " given."; ss << "command takes " << typeVector.size() << " parameters, " << size << " given.";
PyErr_SetString(dgpyError, ss.str().c_str()); PyErr_SetString(DGPYERROR, ss.str().c_str());
return NULL; return NULL;
} }
std::vector<Value> valueVector; std::vector<Value> valueVector;
...@@ -251,10 +250,10 @@ PyObject* executeCommand(PyObject* /*self*/, PyObject* args) { ...@@ -251,10 +250,10 @@ PyObject* executeCommand(PyObject* /*self*/, PyObject* args) {
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
std::stringstream ss; std::stringstream ss;
ss << "while parsing argument " << iParam + 1 << ": expecting " << exc.what() << "."; ss << "while parsing argument " << iParam + 1 << ": expecting " << exc.what() << ".";
PyErr_SetString(dgpyError, ss.str().c_str()); PyErr_SetString(DGPYERROR, ss.str().c_str());
return NULL; return NULL;
} catch (...) { } catch (...) {
PyErr_SetString(dgpyError, "Unknown exception"); PyErr_SetString(DGPYERROR, "Unknown exception");
return NULL; return NULL;
} }
} }
...@@ -303,7 +302,7 @@ PyObject* getCommandDocstring(PyObject* /*self*/, PyObject* args) { ...@@ -303,7 +302,7 @@ PyObject* getCommandDocstring(PyObject* /*self*/, PyObject* args) {
// Retrieve the entity instance // Retrieve the entity instance
if (!PyCapsule_CheckExact(object)) { if (!PyCapsule_CheckExact(object)) {
PyErr_SetString(dgpyError, "first argument is not an object"); PyErr_SetString(DGPYERROR, "first argument is not an object");
return NULL; return NULL;
} }
void* pointer = PyCapsule_GetPointer(object, "dynamic_graph.Entity"); void* pointer = PyCapsule_GetPointer(object, "dynamic_graph.Entity");
...@@ -332,7 +331,7 @@ PyObject* getDocString(PyObject* /*self*/, PyObject* args) { ...@@ -332,7 +331,7 @@ PyObject* getDocString(PyObject* /*self*/, PyObject* args) {
// Retrieve the entity instance // Retrieve the entity instance
if (!PyCapsule_CheckExact(object)) { if (!PyCapsule_CheckExact(object)) {
PyErr_SetString(dgpyError, "first argument is not an object"); PyErr_SetString(DGPYERROR, "first argument is not an object");
return NULL; return NULL;
} }
void* pointer = PyCapsule_GetPointer(object, "dynamic_graph.Entity"); void* pointer = PyCapsule_GetPointer(object, "dynamic_graph.Entity");
...@@ -340,10 +339,10 @@ PyObject* getDocString(PyObject* /*self*/, PyObject* args) { ...@@ -340,10 +339,10 @@ PyObject* getDocString(PyObject* /*self*/, PyObject* args) {
try { try {
return Py_BuildValue("s", entity->getDocString().c_str()); return Py_BuildValue("s", entity->getDocString().c_str());
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what()); PyErr_SetString(DGPYERROR, exc.what());
return NULL; return NULL;
} catch (...) { } catch (...) {
PyErr_SetString(dgpyError, "Unknown exception"); PyErr_SetString(DGPYERROR, "Unknown exception");
return NULL; return NULL;
} }
return NULL; return NULL;
...@@ -353,7 +352,7 @@ PyObject* display(PyObject* /*self*/, PyObject* args) { ...@@ -353,7 +352,7 @@ PyObject* display(PyObject* /*self*/, PyObject* args) {
/* Retrieve the entity instance. */ /* Retrieve the entity instance. */
PyObject* object = NULL; PyObject* object = NULL;
if (!PyArg_ParseTuple(args, "O", &object) || (!PyCapsule_CheckExact(object))) { if (!PyArg_ParseTuple(args, "O", &object) || (!PyCapsule_CheckExact(object))) {
PyErr_SetString(dgpyError, "first argument is not an object"); PyErr_SetString(DGPYERROR, "first argument is not an object");
return NULL; return NULL;
} }
void* pointer = PyCapsule_GetPointer(object, "dynamic_graph.Entity"); void* pointer = PyCapsule_GetPointer(object, "dynamic_graph.Entity");
...@@ -410,13 +409,13 @@ PyObject* setLoggerVerbosityLevel(PyObject* /*self*/, PyObject* args) { ...@@ -410,13 +409,13 @@ PyObject* setLoggerVerbosityLevel(PyObject* /*self*/, PyObject* args) {
break; break;
} }
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what()); PyErr_SetString(DGPYERROR, exc.what());
return NULL; return NULL;
} catch (const char* s) { } catch (const char* s) {
PyErr_SetString(dgpyError, s); PyErr_SetString(DGPYERROR, s);
return NULL; return NULL;
} catch (...) { } catch (...) {
PyErr_SetString(dgpyError, "Unknown exception"); PyErr_SetString(DGPYERROR, "Unknown exception");
return NULL; return NULL;
} }
...@@ -495,13 +494,13 @@ PyObject* setStreamPrintPeriod(PyObject* /*self*/, PyObject* args) { ...@@ -495,13 +494,13 @@ PyObject* setStreamPrintPeriod(PyObject* /*self*/, PyObject* args) {
entity->setStreamPrintPeriod(streamPrintPeriod); entity->setStreamPrintPeriod(streamPrintPeriod);
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what()); PyErr_SetString(DGPYERROR, exc.what());
return NULL; return NULL;
} catch (const char* s) { } catch (const char* s) {
PyErr_SetString(dgpyError, s); PyErr_SetString(DGPYERROR, s);
return NULL; return NULL;
} catch (...) { } catch (...) {
PyErr_SetString(dgpyError, "Unknown exception"); PyErr_SetString(DGPYERROR, "Unknown exception");
return NULL; return NULL;
} }
...@@ -554,13 +553,13 @@ PyObject* setTimeSample(PyObject* /*self*/, PyObject* args) { ...@@ -554,13 +553,13 @@ PyObject* setTimeSample(PyObject* /*self*/, PyObject* args) {
entity->setTimeSample(timeSample); entity->setTimeSample(timeSample);
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what()); PyErr_SetString(DGPYERROR, exc.what());
return NULL; return NULL;
} catch (const char* s) { } catch (const char* s) {
PyErr_SetString(dgpyError, s); PyErr_SetString(DGPYERROR, s);
return NULL; return NULL;
} catch (...) { } catch (...) {
PyErr_SetString(dgpyError, "Unknown exception"); PyErr_SetString(DGPYERROR, "Unknown exception");
return NULL; return NULL;
} }
......
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
/// called. /// called.
#define CATCH_ALL_EXCEPTIONS() \ #define CATCH_ALL_EXCEPTIONS() \
catch (const std::exception& exc) { \ catch (const std::exception& exc) { \
PyErr_SetString(dgpyError, exc.what()); \ PyErr_SetString(DGPYERROR, exc.what()); \
return NULL; \ return NULL; \
} \ } \
catch (const char* s) { \ catch (const char* s) { \
PyErr_SetString(dgpyError, s); \ PyErr_SetString(DGPYERROR, s); \
return NULL; \ return NULL; \
} \ } \
catch (...) { \ catch (...) { \
PyErr_SetString(dgpyError, "Unknown exception"); \ PyErr_SetString(DGPYERROR, "Unknown exception"); \
return NULL; \ return NULL; \
} \ } \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace dynamicgraph { namespace dynamicgraph {
namespace python { namespace python {
extern PyObject* dgpyError;
namespace pool { namespace pool {
PyObject* writeGraph(PyObject* /*self*/, PyObject* args) { PyObject* writeGraph(PyObject* /*self*/, PyObject* args) {
......
...@@ -22,7 +22,6 @@ using dynamicgraph::SignalBase; ...@@ -22,7 +22,6 @@ using dynamicgraph::SignalBase;
namespace dynamicgraph { namespace dynamicgraph {
namespace python { namespace python {
extern PyObject* dgpyError;
using namespace convert; using namespace convert;
namespace signalBase { namespace signalBase {
...@@ -65,7 +64,7 @@ PythonSignalContainer* getPythonSignalContainer() { ...@@ -65,7 +64,7 @@ PythonSignalContainer* getPythonSignalContainer() {
",\n" ",\n"
"but this object is of type " + "but this object is of type " +
std::string(obj->getClassName()) + " and not " + std::string(className)); std::string(obj->getClassName()) + " and not " + std::string(className));
PyErr_SetString(dgpyError, msg.c_str()); PyErr_SetString(DGPYERROR, msg.c_str());
return NULL; return NULL;
} }
} else { } else {
...@@ -111,7 +110,7 @@ PyObject* createSignalWrapper(PyObject* /*self*/, PyObject* args) { ...@@ -111,7 +110,7 @@ PyObject* createSignalWrapper(PyObject* /*self*/, PyObject* args) {
} }
if (obj == NULL) { if (obj == NULL) {
PyErr_SetString(dgpyError, error.c_str()); PyErr_SetString(DGPYERROR, error.c_str());
return NULL; return NULL;
} }
// Register signal into the python signal container // Register signal into the python signal container
...@@ -148,7 +147,7 @@ PyObject* setTime(PyObject* /*self*/, PyObject* args) { ...@@ -148,7 +147,7 @@ PyObject* setTime(PyObject* /*self*/, PyObject* args) {
int time; int time;
if (!PyArg_ParseTuple(args, "Oi", &object, &time)) return NULL; if (!PyArg_ParseTuple(args, "Oi", &object, &time)) return NULL;
if (!PyCapsule_CheckExact(object)) { if (!PyCapsule_CheckExact(object)) {
PyErr_SetString(dgpyError, "object should be a C object"); PyErr_SetString(DGPYERROR, "object should be a C object");
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment