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