Commit 9a27fc49 authored by Guilhem Saurel's avatar Guilhem Saurel

[Python 2] put dgpyError as global back

to fix #39 also in Python2
parent ccbcc4a0
......@@ -183,7 +183,7 @@ __attribute__((unused)) static struct PyModuleDef dynamicGraphModuleDef = {
#else
__attribute__((unused)) static struct module_state _state;
#define GETSTATE(m) (&dynamicgraph::python::_state)
#define DGPYERROR(m) dynamicgraph::python::_state.dgpyError
#define DGPYERROR(m) dynamicgraph::python::dgpyError
#define INITERROR return
#endif
......
......@@ -21,6 +21,10 @@ typedef boost::shared_ptr<std::ofstream> ofstreamShrPtr;
namespace dynamicgraph {
namespace python {
#if PY_MAJOR_VERSION == 2
extern PyObject* dgpyError;
# endif
namespace debug {
std::map<std::string, ofstreamShrPtr> mapOfFiles_;
......
......@@ -14,6 +14,10 @@
namespace dynamicgraph {
namespace python {
#if PY_MAJOR_VERSION == 2
PyObject* dgpyError;
# endif
/**
\brief plug a signal into another one.
*/
......@@ -114,8 +118,7 @@ PyObject* error_out(
PyObject*, PyObject*
#endif
) {
struct module_state* st = GETSTATE(m);
PyErr_SetString(st->dgpyError, "something bad happened");
PyErr_SetString(DGPYERROR(m), "something bad happened");
return NULL;
}
......@@ -133,30 +136,29 @@ void initwrap(void)
#endif
{
#if PY_MAJOR_VERSION >= 3
PyObject* module = PyModule_Create(&dynamicgraph::python::dynamicGraphModuleDef);
PyObject* m = PyModule_Create(&dynamicgraph::python::dynamicGraphModuleDef);
#else
PyObject* module = Py_InitModule("wrap", dynamicgraph::python::dynamicGraphMethods);
PyObject* m = Py_InitModule("wrap", dynamicgraph::python::dynamicGraphMethods);
#endif
if (module == NULL) INITERROR;
struct dynamicgraph::python::module_state* st = GETSTATE(module);
if (m == NULL) INITERROR;
st->dgpyError = PyErr_NewException(const_cast<char*>("dynamic_graph.dgpyError"), NULL, NULL);
if (st->dgpyError == NULL) {
Py_DECREF(module);
DGPYERROR(m) = PyErr_NewException(const_cast<char*>("dynamic_graph.dgpyError"), NULL, NULL);
if (DGPYERROR(m) == NULL) {
Py_DECREF(m);
INITERROR;
}
Py_XINCREF(st->dgpyError);
if (PyModule_AddObject(module, "dgpyError", st->dgpyError) < 0) {
Py_XDECREF(st->dgpyError);
Py_CLEAR(st->dgpyError);
Py_DECREF(module);
Py_XINCREF(DGPYERROR(m));
if (PyModule_AddObject(m, "dgpyError", DGPYERROR(m)) < 0) {
Py_XDECREF(DGPYERROR(m));
Py_CLEAR(DGPYERROR(m));
Py_DECREF(m);
INITERROR;
}
#if PY_MAJOR_VERSION >= 3
return module;
return m;
#endif
}
......
......@@ -32,6 +32,10 @@ namespace python {
using namespace convert;
#if PY_MAJOR_VERSION == 2
extern PyObject* dgpyError;
# endif
namespace entity {
/**
......
......@@ -10,6 +10,10 @@
namespace dynamicgraph {
namespace python {
#if PY_MAJOR_VERSION == 2
extern PyObject* dgpyError;
# endif
namespace pool {
PyObject* writeGraph(
......
......@@ -21,6 +21,10 @@ using dynamicgraph::SignalBase;
namespace dynamicgraph {
namespace python {
#if PY_MAJOR_VERSION == 2
extern PyObject* dgpyError;
# endif
using namespace convert;
namespace signalBase {
......
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