Commit 36a361e9 authored by Guilhem Saurel's avatar Guilhem Saurel

[Python 3]

parent 206ce636
......@@ -89,35 +89,33 @@ PyObject* error_out(
#else
PyObject*, PyObject*
#endif
) {
struct module_state *st = GETSTATE(m);
PyErr_SetString(st->dgpyError, "something bad happened");
return NULL;
}
) {
struct module_state* st = GETSTATE(m);
PyErr_SetString(st->dgpyError, "something bad happened");
return NULL;
}
} // namespace python
} // namespace dynamicgraph
#ifdef __cplusplus
extern "C" {
#endif
#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit_wrap(void)
PyMODINIT_FUNC PyInit_wrap(void)
#else
void initwrap(void)
void initwrap(void)
#endif
{
#if PY_MAJOR_VERSION >= 3
PyObject *module = PyModule_Create(&dynamicgraph::python::dynamicGraphModuleDef);
PyObject* module = PyModule_Create(&dynamicgraph::python::dynamicGraphModuleDef);
#else
PyObject *module = Py_InitModule("wrap", dynamicgraph::python::dynamicGraphMethods);
PyObject* module = Py_InitModule("wrap", dynamicgraph::python::dynamicGraphMethods);
#endif
if (module == NULL)
INITERROR;
struct dynamicgraph::python::module_state *st = GETSTATE(module);
if (module == NULL) INITERROR;
struct dynamicgraph::python::module_state* st = GETSTATE(module);
DGPYERROR = PyErr_NewException(const_cast<char*>("dynamic_graph.dgpyError"), NULL, NULL);
if (st->dgpyError == NULL) {
......
......@@ -86,13 +86,12 @@ PyObject* error_out(
#else
PyObject*, PyObject*
#endif
);
);
/**
\brief List of python functions
*/
__attribute__((unused))
static PyMethodDef dynamicGraphMethods[] = {
__attribute__((unused)) static PyMethodDef dynamicGraphMethods[] = {
{"w_plug", dynamicgraph::python::plug, METH_VARARGS, "plug an output signal into an input signal"},
{"enableTrace", dynamicgraph::python::enableTrace, METH_VARARGS, "Enable or disable tracing debug info in a file"},
// Signals
......@@ -170,30 +169,26 @@ static PyMethodDef dynamicGraphMethods[] = {
};
#if PY_MAJOR_VERSION >= 3
__attribute__((unused))
static struct PyModuleDef dynamicGraphModuleDef = {
PyModuleDef_HEAD_INIT,
"wrap",
NULL,
sizeof(struct dynamicgraph::python::module_state),
dynamicGraphMethods,
NULL,
NULL,
NULL,
NULL
};
__attribute__((unused)) static struct PyModuleDef dynamicGraphModuleDef = {
PyModuleDef_HEAD_INIT,
"wrap",
NULL,
sizeof(struct dynamicgraph::python::module_state),
dynamicGraphMethods,
NULL,
NULL,
NULL,
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;
__attribute__((unused)) static struct module_state _state;
#define GETSTATE(m) (&dynamicgraph::python::_state)
#define DGPYERROR dynamicgraph::python::_state.dgpyError
#define INITERROR return
#endif
} // namespace python
} // namespace dynamicgraph
......
......@@ -270,9 +270,14 @@ void Interpreter::runPythonFile(std::string filename, std::string& err) {
}
void Interpreter::runMain(void) {
const char* argv[] = {"dg-embedded-pysh"};
PyEval_RestoreThread(_pyState);
#if PY_MAJOR_VERSION >= 3
const wchar_t* argv[] = {L"dg-embedded-pysh"};
Py_Main(1, const_cast<wchar_t**>(argv));
#else
const char* argv[] = {"dg-embedded-pysh"};
Py_Main(1, const_cast<char**>(argv));
#endif
_pyState = PyEval_SaveThread();
}
......
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