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
834ff2f5
Commit
834ff2f5
authored
5 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
explicit error in case of misuse of dg.plug, fix #36
parent
d4a210d2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/dynamic_graph/dynamic-graph-py.cc
+29
-3
29 additions, 3 deletions
src/dynamic_graph/dynamic-graph-py.cc
unitTesting/test_bindings.py
+11
-2
11 additions, 2 deletions
unitTesting/test_bindings.py
with
40 additions
and
5 deletions
src/dynamic_graph/dynamic-graph-py.cc
+
29
−
3
View file @
834ff2f5
...
...
@@ -17,7 +17,13 @@ namespace python {
/**
\brief plug a signal into another one.
*/
PyObject
*
plug
(
PyObject
*
/*self*/
,
PyObject
*
args
)
{
PyObject
*
plug
(
#if PY_MAJOR_VERSION >= 3
PyObject
*
m
,
PyObject
*
args
#else
PyObject
*
,
PyObject
*
args
#endif
)
{
PyObject
*
objOut
=
NULL
;
PyObject
*
objIn
=
NULL
;
void
*
pObjOut
;
...
...
@@ -40,10 +46,22 @@ PyObject* plug(PyObject* /*self*/, PyObject* args) {
pObjIn
=
PyCapsule_GetPointer
(
objIn
,
"dynamic_graph.Signal"
);
SignalBase
<
int
>*
signalIn
=
(
SignalBase
<
int
>*
)
pObjIn
;
if
(
signalIn
==
NULL
)
return
NULL
;
if
(
signalIn
==
NULL
)
{
struct
module_state
*
st
=
GETSTATE
(
m
);
std
::
ostringstream
oss
;
oss
<<
"dgpy.plug in argument must be a dynamic_graph.Signal, not a "
<<
PyCapsule_GetName
(
objIn
);
PyErr_SetString
(
st
->
dgpyError
,
oss
.
str
().
c_str
());
return
NULL
;
}
pObjOut
=
PyCapsule_GetPointer
(
objOut
,
"dynamic_graph.Signal"
);
SignalBase
<
int
>*
signalOut
=
(
SignalBase
<
int
>*
)
pObjOut
;
if
(
signalOut
==
NULL
)
return
NULL
;
if
(
signalOut
==
NULL
)
{
struct
module_state
*
st
=
GETSTATE
(
m
);
std
::
ostringstream
oss
;
oss
<<
"dgpy.plug out argument must be a dynamic_graph.Signal, not a "
<<
PyCapsule_GetName
(
objOut
);
PyErr_SetString
(
st
->
dgpyError
,
oss
.
str
().
c_str
());
return
NULL
;
}
std
::
ostringstream
os
;
try
{
...
...
@@ -123,6 +141,14 @@ void initwrap(void)
INITERROR
;
}
Py_XINCREF
(
st
->
dgpyError
);
if
(
PyModule_AddObject
(
module
,
"dgpyError"
,
st
->
dgpyError
)
<
0
)
{
Py_XDECREF
(
st
->
dgpyError
);
Py_CLEAR
(
st
->
dgpyError
);
Py_DECREF
(
module
);
return
NULL
;
}
#if PY_MAJOR_VERSION >= 3
return
module
;
#endif
...
...
This diff is collapsed.
Click to expand it.
unitTesting/test_bindings.py
+
11
−
2
View file @
834ff2f5
import
unittest
import
dynamic_graph
as
dg
from
custom_entity
import
CustomEntity
...
...
@@ -15,10 +16,18 @@ class BindingsTests(unittest.TestCase):
second
=
CustomEntity
(
'
second_entity
'
)
# Check that we can connect first.out to second.in
dg
.
plug
(
first
.
signal
(
'
out_double
'
),
second
.
signal
(
'
in_double
'
))
# Check that we can't connect first.out to second
with
self
.
assertRaises
(
Value
Error
)
as
cm
:
with
self
.
assertRaises
(
dg
.
dgpy
Error
)
as
cm
_in
:
dg
.
plug
(
first
.
signal
(
'
out_double
'
),
second
)
self
.
assertEqual
(
str
(
cm
.
exception
),
"
PyCapsule_GetPointer called with incorrect name
"
)
self
.
assertEqual
(
str
(
cm_in
.
exception
),
"
dgpy.plug in argument must be a dynamic_graph.Signal, not a dynamic_graph.Entity
"
)
# Check that we can't connect first to second.in
with
self
.
assertRaises
(
dg
.
dgpyError
)
as
cm_out
:
dg
.
plug
(
first
,
second
.
signal
(
'
in_double
'
))
self
.
assertEqual
(
str
(
cm_out
.
exception
),
"
dgpy.plug out argument must be a dynamic_graph.Signal, not a dynamic_graph.Entity
"
)
if
__name__
==
'
__main__
'
:
...
...
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