Skip to content
Snippets Groups Projects
Commit 40561f6a authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Fix for Python3 in python embedded functional tests

parent 88733beb
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,27 @@ ...@@ -21,6 +21,27 @@
//! Comparing results of GetVersionNumber() function obtained in "embedded" and "native C++" ways. //! Comparing results of GetVersionNumber() function obtained in "embedded" and "native C++" ways.
#if PY_MAJOR_VERSION >= 3
#define PyString_FromString PyUnicode_FromString
#define PyString_AsString PyBytes_AsString
#endif
namespace {
const char* asString(PyObject* object)
{
#if PY_MAJOR_VERSION >= 3
PyObject* pyStr = PyUnicode_AsEncodedString(object, "utf-8", "Error ~");
return PyBytes_AsString(pyStr);
#else
return PyString_AsString(object);
#endif
}
}
bool FunctionCall::runTest() bool FunctionCall::runTest()
{ {
Py_Initialize(); Py_Initialize();
...@@ -49,7 +70,7 @@ bool FunctionCall::runTest() ...@@ -49,7 +70,7 @@ bool FunctionCall::runTest()
if(!result) if(!result)
throw std::runtime_error("Error while calling function"); throw std::runtime_error("Error while calling function");
char* cstr = PyString_AsString(result); const char* cstr = asString(result);
if(!cstr) if(!cstr)
throw std::runtime_error("Error in return type"); throw std::runtime_error("Error in return type");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment