Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic-graph-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
dynamic-graph-python
Commits
d4a89710
Commit
d4a89710
authored
5 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
module initialization compatible with python 2 & 3
parent
2c6f3151
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dynamic-graph-py.cc
+65
-9
65 additions, 9 deletions
src/dynamic-graph-py.cc
with
65 additions
and
9 deletions
src/dynamic-graph-py.cc
+
65
−
9
View file @
d4a89710
...
...
@@ -72,7 +72,9 @@ extern PyObject* realTimeLoggerDestroy(PyObject* self, PyObject* args);
extern
PyObject
*
realTimeLoggerInstance
(
PyObject
*
self
,
PyObject
*
args
);
}
// namespace debug
PyObject
*
dgpyError
;
struct
module_state
{
PyObject
*
dgpyError
;
};
/**
\brief plug a signal into another one.
...
...
@@ -140,6 +142,25 @@ PyObject* enableTrace(PyObject* /*self*/, PyObject* args) {
}
return
Py_BuildValue
(
""
);
}
#if PY_MAJOR_VERSION >= 3
#define GETSTATE(m) ((struct dynamicgraph::python::module_state*)PyModule_GetState(m))
#else
#define GETSTATE(m) (&dynamicgraph::python::_state)
static
struct
dynamicgraph
::
python
::
module_state
_state
;
#endif
static
PyObject
*
#if PY_MAJOR_VERSION >= 3
error_out
(
PyObject
*
m
,
PyObject
*
)
{
struct
module_state
*
st
=
GETSTATE
(
m
);
#else
error_out
(
PyObject
*
,
PyObject
*
)
{
struct
module_state
*
st
=
&
dynamicgraph
::
python
::
_state
;
#endif
PyErr_SetString
(
st
->
dgpyError
,
"something bad happened"
);
return
NULL
;
}
}
// namespace python
}
// namespace dynamicgraph
...
...
@@ -219,18 +240,53 @@ static PyMethodDef dynamicGraphMethods[] = {
"Destroy the real time logger."
},
{
"real_time_logger_instance"
,
dynamicgraph
::
python
::
debug
::
realTimeLoggerInstance
,
METH_VARARGS
,
"Starts the real time logger."
},
{
"error_out"
,
(
PyCFunction
)
dynamicgraph
::
python
::
error_out
,
METH_NOARGS
,
NULL
},
{
NULL
,
NULL
,
0
,
NULL
}
/* Sentinel */
};
PyMODINIT_FUNC
initwrap
(
void
)
{
PyObject
*
m
;
#if PY_MAJOR_VERSION >= 3
static
struct
PyModuleDef
moduledef
=
{
PyModuleDef_HEAD_INIT
,
"dynamic_graph"
,
NULL
,
sizeof
(
struct
dynamicgraph
::
python
::
module_state
),
dynamicGraphMethods
,
NULL
,
NULL
,
NULL
,
NULL
};
#define INITERROR return NULL
PyMODINIT_FUNC
PyInit_dynamic_graph
(
void
)
m
=
Py_InitModule
(
"wrap"
,
dynamicGraphMethods
);
if
(
m
==
NULL
)
return
;
#else
#define INITERROR
return
std
::
string
msg
(
"dynamic_graph.error"
);
void
initdynamic_graph
(
void
)
#endif
{
#if PY_MAJOR_VERSION >= 3
PyObject
*
module
=
PyModule_Create
(
&
moduledef
);
#else
PyObject
*
module
=
Py_InitModule
(
"dynamic_graph"
,
dynamicGraphMethods
);
#endif
if
(
module
==
NULL
)
INITERROR
;
struct
dynamicgraph
::
python
::
module_state
*
st
=
GETSTATE
(
module
);
st
->
dgpyError
=
PyErr_NewException
(
const_cast
<
char
*>
(
"dynamic_graph.dgpyError"
),
NULL
,
NULL
);
if
(
st
->
dgpyError
==
NULL
)
{
Py_DECREF
(
module
);
INITERROR
;
}
dynamicgraph
::
python
::
dgpyError
=
PyErr_NewException
(
const_cast
<
char
*>
(
msg
.
c_str
()),
NULL
,
NULL
);
Py_INCREF
(
dynamicgraph
::
python
::
dgpyError
)
;
PyModule_AddObject
(
m
,
"error"
,
dynamicgraph
::
python
::
dgpyError
);
#if PY_MAJOR_VERSION >= 3
return
module
;
#endif
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment