src
dynamic_graph
python-compat.cc
Go to the documentation of this file.
1
#include "
dynamic-graph/python/python-compat.hh
"
2
3
// Get any PyObject and get its str() representation as an std::string
4
std::string
obj_to_str
(PyObject* o) {
5
std::string ret;
6
PyObject* os;
7
#if PY_MAJOR_VERSION >= 3
8
os = PyObject_Str(o);
9
assert(os != NULL);
10
assert(PyUnicode_Check(os));
11
ret = PyUnicode_AsUTF8(os);
12
#else
13
os = PyObject_Unicode(o);
14
assert(os != NULL);
15
assert(PyUnicode_Check(os));
16
PyObject* oss = PyUnicode_AsUTF8String(os);
17
assert(oss != NULL);
18
ret = PyString_AsString(oss);
19
Py_DECREF(oss);
20
#endif
21
Py_DECREF(os);
22
return
ret;
23
}
python-compat.hh
obj_to_str
std::string obj_to_str(PyObject *o)
Definition:
python-compat.cc:4
dynamic-graph-python
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Oct 27 2023 02:16:36