Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph-python
Commits
342fa551
Commit
342fa551
authored
Oct 29, 2019
by
Guilhem Saurel
Browse files
add python-compat for obj-to-str
parent
2de7489e
Changes
20
Hide whitespace changes
Inline
Side-by-side
include/dynamic-graph/python/CMakeLists.txt
View file @
342fa551
...
...
@@ -7,6 +7,7 @@ SET(${PROJECT_NAME}_HEADERS
exception.hh
exception-python.hh
interpreter.hh
python-compat.hh
signal-wrapper.hh
)
...
...
include/dynamic-graph/python/convert-dg-to-py.hh
View file @
342fa551
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
#include
<Python.h>
#include
<dynamic-graph/linear-algebra.h>
#include
<dynamic-graph/value.h>
#include
<dynamic-graph/python/exception-python.hh>
...
...
include/dynamic-graph/python/dynamic-graph-py.hh
View file @
342fa551
#ifndef DYNAMIC_GRAPH_PY
#define DYNAMIC_GRAPH_PY
#include
<Python.h>
#include
<iostream>
#include
<sstream>
#include
<string>
#include
<dynamic-graph/debug.h>
#include
<dynamic-graph/exception-factory.h>
#include
<dynamic-graph/signal-base.h>
#include
"signal-wrapper.hh"
#include
"
dynamic-graph/python/
signal-wrapper.hh"
namespace
dynamicgraph
{
namespace
python
{
...
...
include/dynamic-graph/python/exception-python.hh
View file @
342fa551
...
...
@@ -4,10 +4,10 @@
#ifndef DYNAMIC_GRAPH_PYTHON_EXCEPTION_PYTHON_H
#define DYNAMIC_GRAPH_PYTHON_EXCEPTION_PYTHON_H
#include
<string>
#include
<dynamic-graph/fwd.hh>
#include
<dynamic-graph/exception-abstract.h>
#include
"dynamic-graph/python/python-compat.hh"
// Depending on whether one is building or using the
// library define DLLAPI to import or export.
...
...
include/dynamic-graph/python/interpreter.hh
View file @
342fa551
...
...
@@ -6,12 +6,10 @@
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
#define PY_SSIZE_T_CLEAN
#include
<Python.h>
#include
<string>
#include
"dynamic-graph/python/api.hh"
#include
"dynamic-graph/python/deprecated.hh"
#include
"dynamic-graph/python/python-compat.hh"
#include
"dynamic-graph/python/api.hh"
namespace
dynamicgraph
{
...
...
@@ -48,7 +46,7 @@ class DYNAMIC_GRAPH_PYTHON_DLLAPI Interpreter {
PyObject
*
globals
();
private:
/// The Python
e
thread state
/// The Python thread state
PyThreadState
*
_pyState
;
/// Pointer to the dictionary of global variables
PyObject
*
globals_
;
...
...
include/dynamic-graph/python/python-compat.hh
0 → 100644
View file @
342fa551
#ifndef DGPY_PYTHON_COMPAT_H
#define DGPY_PYTHON_COMPAT_H
#include
<string>
#define PY_SSIZE_T_CLEAN
#include
<Python.h>
// Get any PyObject and get its str() representation as an std::string
std
::
string
obj_to_str
(
PyObject
*
o
);
#endif
include/dynamic-graph/python/signal-wrapper.hh
View file @
342fa551
...
...
@@ -4,11 +4,10 @@
#ifndef DGPY_SIGNAL_WRAPPER
#define DGPY_SIGNAL_WRAPPER
#include
<Python.h>
#include
<dynamic-graph/linear-algebra.h>
#include
<dynamic-graph/signal.h>
#include
<dynamic-graph/entity.h>
#include
"dynamic-graph/python/python-compat.hh"
namespace
dynamicgraph
{
namespace
python
{
...
...
src/CMakeLists.txt
View file @
342fa551
...
...
@@ -7,7 +7,7 @@
#
SET
(
LIBRARY_NAME
${
PROJECT_NAME
}
)
ADD_LIBRARY
(
${
LIBRARY_NAME
}
SHARED interpreter.cc
)
ADD_LIBRARY
(
${
LIBRARY_NAME
}
SHARED interpreter.cc
dynamic_graph/python-compat.cc
)
TARGET_LINK_LIBRARIES
(
${
LIBRARY_NAME
}
${
PYTHON_LIBRARY
}
)
...
...
src/dynamic_graph/CMakeLists.txt
View file @
342fa551
...
...
@@ -11,6 +11,7 @@ ADD_LIBRARY(${PYTHON_MODULE}
exception-python.cc
factory-py.cc
pool-py.cc
python-compat.cc
signal-base-py.cc
signal-caster-py.cc
signal-wrapper.cc
...
...
src/dynamic_graph/convert-dg-to-py.cc
View file @
342fa551
...
...
@@ -8,6 +8,7 @@
#include
<dynamic-graph/signal-caster.h>
#include
"dynamic-graph/python/convert-dg-to-py.hh"
#include
"dynamic-graph/python/python-compat.hh"
namespace
dynamicgraph
{
...
...
@@ -113,7 +114,7 @@ command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& val
if
(
!
PyUnicode_Check
(
pyObject
))
{
throw
ExceptionPython
(
ExceptionPython
::
VALUE_PARSING
,
"string"
);
}
svalue
=
PyUnicode_AS_DATA
(
pyObject
);
svalue
=
obj_to_str
(
pyObject
);
return
Value
(
svalue
);
break
;
case
(
Value
::
VECTOR
):
...
...
src/dynamic_graph/debug-py.cc
View file @
342fa551
...
...
@@ -8,7 +8,6 @@
#include
<dynamic-graph/real-time-logger.h>
#include
<map>
#include
<Python.h>
#include
<dynamic-graph/pool.h>
#include
<dynamic-graph/entity.h>
#include
<vector>
...
...
src/dynamic_graph/dynamic-graph-py.cc
View file @
342fa551
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
#include
<Python.h>
#include
<iostream>
#include
<sstream>
#include
<string>
#include
<dynamic-graph/debug.h>
#include
<dynamic-graph/exception-factory.h>
...
...
src/dynamic_graph/entity-py.cc
View file @
342fa551
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
#include
<Python.h>
#include
<iostream>
#include
<dynamic-graph/entity.h>
...
...
src/dynamic_graph/factory-py.cc
View file @
342fa551
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
#include
<Python.h>
#include
<iostream>
#include
<dynamic-graph/factory.h>
...
...
src/dynamic_graph/pool-py.cc
View file @
342fa551
// Copyright 2011, 2012, Florent Lamiraux, LAAS-CNRS.
#include
<Python.h>
#include
<dynamic-graph/pool.h>
#include
<dynamic-graph/entity.h>
#include
<vector>
...
...
src/dynamic_graph/python-compat.cc
0 → 100644
View file @
342fa551
#include
"dynamic-graph/python/python-compat.hh"
// Get any PyObject and get its str() representation as an std::string
std
::
string
obj_to_str
(
PyObject
*
o
)
{
std
::
string
ret
;
PyObject
*
os
;
#if PY_MAJOR_VERSION >= 3
os
=
PyObject_Str
(
o
);
assert
(
os
!=
NULL
);
assert
(
PyUnicode_Check
(
os
));
ret
=
PyUnicode_AsUTF8
(
os
);
#else
os
=
PyObject_Unicode
(
o
);
assert
(
os
!=
NULL
);
assert
(
PyUnicode_Check
(
os
));
PyObject
*
oss
=
PyUnicode_AsUTF8String
(
os
);
assert
(
oss
!=
NULL
);
ret
=
PyString_AsString
(
oss
);
Py_DECREF
(
oss
);
#endif
Py_DECREF
(
os
);
return
ret
;
}
src/dynamic_graph/signal-base-py.cc
View file @
342fa551
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
#include
<Python.h>
#include
<iostream>
#include
<sstream>
...
...
src/dynamic_graph/signal-caster-py.cc
View file @
342fa551
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
#include
<Python.h>
#include
<iostream>
#include
<sstream>
...
...
src/dynamic_graph/signal-wrapper.cc
View file @
342fa551
// Copyright (c) 2018, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
#include
<Python.h>
#include
<dynamic-graph/factory.h>
#include
<dynamic-graph/command-bind.h>
...
...
@@ -45,7 +44,7 @@ template <class T, class Time>
bool
SignalWrapper
<
T
,
Time
>::
checkCallable
(
PyObject
*
c
,
std
::
string
&
error
)
{
if
(
PyCallable_Check
(
c
)
==
0
)
{
PyObject
*
str
=
PyObject_Str
(
c
);
error
=
PyUnicode_AS_DATA
(
str
);
error
=
obj_to_str
(
str
);
error
+=
" is not callable"
;
Py_DECREF
(
str
);
return
false
;
...
...
src/interpreter.cc
View file @
342fa551
...
...
@@ -28,28 +28,6 @@ static const std::string pythonPrefix[8] = {"from __future__ import print_functi
"sys.stdout = stdout_catcher"
,
"sys.stderr = stderr_catcher"
};
// Get any PyObject and get its str() representation as an std::string
std
::
string
obj_to_str
(
PyObject
*
o
)
{
std
::
string
ret
;
PyObject
*
os
;
#if PY_MAJOR_VERSION >= 3
os
=
PyObject_Str
(
o
);
assert
(
os
!=
NULL
);
assert
(
PyUnicode_Check
(
os
));
ret
=
PyUnicode_AsUTF8
(
os
);
#else
os
=
PyObject_Unicode
(
o
);
assert
(
os
!=
NULL
);
assert
(
PyUnicode_Check
(
os
));
PyObject
*
oss
=
PyUnicode_AsUTF8String
(
os
);
assert
(
oss
!=
NULL
);
ret
=
PyString_AsString
(
oss
);
Py_DECREF
(
oss
);
#endif
Py_DECREF
(
os
);
return
ret
;
}
bool
HandleErr
(
std
::
string
&
err
,
PyObject
*
globals_
,
int
PythonInputType
)
{
dgDEBUGIN
(
15
);
err
=
""
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment