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
2c6f3151
Commit
2c6f3151
authored
Oct 02, 2019
by
Guilhem Saurel
Browse files
[Python 3] int → long, string → unicode
parent
46130584
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/convert-dg-to-py.cc
View file @
2c6f3151
...
...
@@ -23,8 +23,8 @@ void fillMatrixRow(Matrix& m, unsigned iRow, PyObject* sequence) {
PyObject
*
pyDouble
=
PySequence_GetItem
(
sequence
,
iCol
);
if
(
PyFloat_Check
(
pyDouble
))
m
(
iRow
,
iCol
)
=
PyFloat_AsDouble
(
pyDouble
);
else
if
(
Py
Int
_Check
(
pyDouble
))
m
(
iRow
,
iCol
)
=
(
int
)
Py
Int_AS_LONG
(
pyDouble
)
+
0.0
;
else
if
(
Py
Long
_Check
(
pyDouble
))
m
(
iRow
,
iCol
)
=
(
int
)
Py
Long_AsLong
(
pyDouble
)
+
0.0
;
else
throw
ExceptionPython
(
ExceptionPython
::
MATRIX_PARSING
,
"element of matrix should be "
...
...
@@ -39,8 +39,8 @@ void fillMatrixRow(Eigen::Matrix4d& m, unsigned iRow, PyObject* sequence) {
PyObject
*
pyDouble
=
PySequence_GetItem
(
sequence
,
iCol
);
if
(
PyFloat_Check
(
pyDouble
))
m
(
iRow
,
iCol
)
=
PyFloat_AsDouble
(
pyDouble
);
else
if
(
Py
Int
_Check
(
pyDouble
))
m
(
iRow
,
iCol
)
=
(
int
)
Py
Int_AS_LONG
(
pyDouble
)
+
0.0
;
else
if
(
Py
Long
_Check
(
pyDouble
))
m
(
iRow
,
iCol
)
=
(
int
)
Py
Long_AsLong
(
pyDouble
)
+
0.0
;
else
throw
ExceptionPython
(
ExceptionPython
::
MATRIX_PARSING
,
"element of matrix should be "
...
...
@@ -73,25 +73,25 @@ command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& val
return
Value
(
bvalue
);
break
;
case
(
Value
::
UNSIGNED
):
if
(
!
Py
Int
_Check
(
pyObject
))
{
if
(
!
Py
Long
_Check
(
pyObject
))
{
throw
ExceptionPython
(
ExceptionPython
::
VALUE_PARSING
,
"unsigned int"
);
}
uvalue
=
(
unsigned
int
)
Py
Int
_AsUnsignedLongMask
(
pyObject
);
uvalue
=
(
unsigned
int
)
Py
Long
_AsUnsignedLongMask
(
pyObject
);
return
Value
(
uvalue
);
break
;
case
(
Value
::
INT
):
if
(
!
Py
Int
_Check
(
pyObject
))
{
if
(
!
Py
Long
_Check
(
pyObject
))
{
throw
ExceptionPython
(
ExceptionPython
::
VALUE_PARSING
,
"int"
);
}
ivalue
=
(
int
)
Py
Int_AS_LONG
(
pyObject
);
ivalue
=
(
int
)
Py
Long_AsLong
(
pyObject
);
return
Value
(
ivalue
);
break
;
case
(
Value
::
FLOAT
):
if
(
PyFloat_Check
(
pyObject
))
{
fvalue
=
(
float
)
PyFloat_AsDouble
(
pyObject
);
return
Value
(
fvalue
);
}
else
if
(
Py
Int
_Check
(
pyObject
))
{
fvalue
=
(
float
)
Py
Int_AS_LONG
(
pyObject
);
}
else
if
(
Py
Long
_Check
(
pyObject
))
{
fvalue
=
(
float
)
Py
Long_AsLong
(
pyObject
);
return
Value
(
fvalue
);
}
else
{
throw
ExceptionPython
(
ExceptionPython
::
VALUE_PARSING
,
"float"
);
...
...
@@ -101,18 +101,18 @@ command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& val
if
(
PyFloat_Check
(
pyObject
))
{
dvalue
=
PyFloat_AsDouble
(
pyObject
);
return
Value
(
dvalue
);
}
else
if
(
Py
Int
_Check
(
pyObject
))
{
dvalue
=
(
double
)
Py
Int_AS_LONG
(
pyObject
);
}
else
if
(
Py
Long
_Check
(
pyObject
))
{
dvalue
=
(
double
)
Py
Long_AsLong
(
pyObject
);
return
Value
(
dvalue
);
}
else
{
throw
ExceptionPython
(
ExceptionPython
::
VALUE_PARSING
,
"double"
);
}
break
;
case
(
Value
::
STRING
):
if
(
!
Py
String
_Check
(
pyObject
))
{
if
(
!
Py
Unicode
_Check
(
pyObject
))
{
throw
ExceptionPython
(
ExceptionPython
::
VALUE_PARSING
,
"string"
);
}
svalue
=
Py
String_AsString
(
pyObject
);
svalue
=
Py
Unicode_AS_DATA
(
pyObject
);
return
Value
(
svalue
);
break
;
case
(
Value
::
VECTOR
):
...
...
@@ -126,8 +126,8 @@ command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& val
PyObject
*
pyDouble
=
PySequence_GetItem
(
pyObject
,
i
);
if
(
PyFloat_Check
(
pyDouble
))
v
(
i
)
=
PyFloat_AsDouble
(
pyDouble
);
else
if
(
Py
Int
_Check
(
pyDouble
))
v
(
i
)
=
(
int
)
Py
Int_AS_LONG
(
pyDouble
)
+
0.0
;
else
if
(
Py
Long
_Check
(
pyDouble
))
v
(
i
)
=
(
int
)
Py
Long_AsLong
(
pyDouble
)
+
0.0
;
else
throw
ExceptionPython
(
ExceptionPython
::
VECTOR_PARSING
,
"element of vector should be a floating "
...
...
src/interpreter.cc
View file @
2c6f3151
...
...
@@ -65,11 +65,11 @@ bool HandleErr(std::string& err, PyObject* traceback_format_exception, PyObject*
assert
(
PyList_Check
(
pyerr
));
Py_ssize_t
size
=
PyList_GET_SIZE
(
pyerr
);
std
::
string
stringRes
;
for
(
Py_ssize_t
i
=
0
;
i
<
size
;
++
i
)
stringRes
+=
std
::
string
(
Py
String_AsString
(
PyList_GET_ITEM
(
pyerr
,
i
)));
for
(
Py_ssize_t
i
=
0
;
i
<
size
;
++
i
)
stringRes
+=
std
::
string
(
Py
Unicode_AS_DATA
(
PyList_GET_ITEM
(
pyerr
,
i
)));
Py_DecRef
(
pyerr
);
pyerr
=
Py
String
_FromString
(
stringRes
.
c_str
());
err
=
Py
String_AsString
(
pyerr
);
pyerr
=
Py
Unicode
_FromString
(
stringRes
.
c_str
());
err
=
Py
Unicode_AS_DATA
(
pyerr
);
dgDEBUG
(
15
)
<<
"err: "
<<
err
<<
std
::
endl
;
Py_DecRef
(
pyerr
);
...
...
@@ -92,7 +92,7 @@ bool HandleErr(std::string& err, PyObject* traceback_format_exception, PyObject*
PyObject
*
stdout_obj
=
PyRun_String
(
"stdout_catcher.fetch()"
,
Py_eval_input
,
globals_
,
globals_
);
std
::
string
out
(
""
);
out
=
Py
String_AsString
(
stdout_obj
);
out
=
Py
Unicode_AS_DATA
(
stdout_obj
);
// Local display for the robot (in debug mode or for the logs)
if
(
out
.
length
()
!=
0
)
{
dgDEBUG
(
15
)
<<
std
::
endl
;
...
...
@@ -146,7 +146,7 @@ Interpreter::~Interpreter() {
PyObject
*
poAttrName
;
while
((
poAttrName
=
PyIter_Next
(
poAttrIter
))
!=
NULL
)
{
std
::
string
oAttrName
(
Py
String_AS_STRING
(
poAttrName
));
std
::
string
oAttrName
(
Py
Unicode_AS_DATA
(
poAttrName
));
// Make sure we don't delete any private objects.
if
(
oAttrName
.
compare
(
0
,
2
,
"__"
)
!=
0
||
oAttrName
.
compare
(
oAttrName
.
size
()
-
2
,
2
,
"__"
)
!=
0
)
{
...
...
@@ -214,7 +214,7 @@ void Interpreter::python(const std::string& command, std::string& res, std::stri
PyObject
*
stdout_obj
=
0
;
stdout_obj
=
PyRun_String
(
"stdout_catcher.fetch()"
,
Py_eval_input
,
globals_
,
globals_
);
out
=
Py
String_AsString
(
stdout_obj
);
out
=
Py
Unicode_AS_DATA
(
stdout_obj
);
// Local display for the robot (in debug mode or for the logs)
if
(
out
.
size
()
!=
0
)
std
::
cout
<<
"Output:"
<<
out
<<
std
::
endl
;
if
(
err
.
size
()
!=
0
)
std
::
cout
<<
"Error:"
<<
err
<<
std
::
endl
;
...
...
@@ -223,7 +223,7 @@ void Interpreter::python(const std::string& command, std::string& res, std::stri
// then results is equal to NULL. This will trigger a SEGV
if
(
result2
!=
NULL
)
{
dgDEBUG
(
15
)
<<
"For command :"
<<
command
<<
std
::
endl
;
res
=
Py
String_AsString
(
result2
);
res
=
Py
Unicode_AS_DATA
(
result2
);
dgDEBUG
(
15
)
<<
"Result is: "
<<
res
<<
std
::
endl
;
dgDEBUG
(
15
)
<<
"Out is: "
<<
out
<<
std
::
endl
;
dgDEBUG
(
15
)
<<
"Err is :"
<<
err
<<
std
::
endl
;
...
...
src/signal-wrapper.cc
View file @
2c6f3151
...
...
@@ -11,7 +11,7 @@ namespace dynamicgraph {
namespace
python
{
namespace
signalWrapper
{
void
convert
(
PyObject
*
o
,
bool
&
v
)
{
v
=
(
o
==
Py_True
);
}
void
convert
(
PyObject
*
o
,
int
&
v
)
{
v
=
(
int
)
Py
Int_AS_LONG
(
o
);
}
void
convert
(
PyObject
*
o
,
int
&
v
)
{
v
=
(
int
)
Py
Long_AsLong
(
o
);
}
void
convert
(
PyObject
*
o
,
float
&
v
)
{
v
=
(
float
)
PyFloat_AS_DOUBLE
(
o
);
}
void
convert
(
PyObject
*
o
,
double
&
v
)
{
v
=
PyFloat_AS_DOUBLE
(
o
);
}
void
convert
(
PyObject
*
o
,
Vector
&
v
)
{
...
...
@@ -45,7 +45,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
=
Py
String_AsString
(
str
);
error
=
Py
Unicode_AS_DATA
(
str
);
error
+=
" is not callable"
;
Py_DECREF
(
str
);
return
false
;
...
...
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