static
std::string copyList(PyObject *pyList, std::list<std::string>& cppList)
{
- std::string error;
+ std::string error="";
if(!PyList_Check(pyList))
{
error = "Not a python list.\n";
}
else
{
- int n = PyList_Size(pyList);
- for(int i=0; i<n; i++)
+ Py_ssize_t n = PyList_Size(pyList);
+ for(Py_ssize_t i=0; i<n; i++)
{
PyObject *elem = PyList_GetItem(pyList,i);
- if(!PyString_Check(elem))
+ if(!PyUnicode_Check(elem))
{
std::stringstream message;
message << "List element number " << i << " is not a string.\n";
}
else
{
- const char * portName = PyString_AsString(elem);
- cppList.push_back(portName);
+ cppList.push_back(std::string(PyUnicode_AsUTF8(elem)));
}
}
}
PyObject *pystr, *module_name, *pyth_module, *pyth_func;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
pystr = PyObject_Str(pvalue);
- result = PyString_AsString(pystr);
+ result = std::string(PyUnicode_AsUTF8(pystr));
result += "\n";
Py_DECREF(pystr);
/* See if we can get a full traceback */
if(ptraceback)
{
- module_name = PyString_FromString("traceback");
+ module_name = PyUnicode_FromString("traceback");
pyth_module = PyImport_Import(module_name);
Py_DECREF(module_name);
if (pyth_module)
for(int i=0; i<n; i++)
{
pystr = PyList_GetItem(pyList,i);
- result += PyString_AsString(pystr);
+ result += std::string(PyUnicode_AsUTF8(pystr));
}
Py_DECREF(pyList);
}
// Py_Initialize();
YACS::ENGINE::AutoGIL agil;
- pValue = PyString_FromString(_python_parser_module.c_str());
+ pValue = PyUnicode_FromString(_python_parser_module.c_str());
pModule = PyImport_Import(pValue);
Py_DECREF(pValue);
if (pFunc && PyCallable_Check(pFunc))
{
pArgs = PyTuple_New(1);
- pValue = PyString_FromString(python_code.c_str());
+ pValue = PyUnicode_FromString(python_code.c_str());
PyTuple_SetItem(pArgs, 0, pValue);
pValue = PyObject_CallObject(pFunc, pArgs);
{
errorMessage += "Parsing function should return a tuple of two string lists.\n";
}
- int n = PyTuple_Size(pValue);
+ Py_ssize_t n = PyTuple_Size(pValue);
if(n != 2)
{
errorMessage += "Parsing function should return two string lists.\n";
if(pAttribute = checkAndGetAttribute(fpy, "name", errorMessage))
{
- if(!PyString_Check(pAttribute))
+ if(!PyUnicode_Check(pAttribute))
{
errorMessage += "Attribute 'name' should be a string.\n";
Py_DECREF(pAttribute);
{
_functions.push_back(FunctionProperties());
FunctionProperties& fcpp = _functions.back();
- fcpp._name=PyString_AsString(pAttribute);
+ fcpp._name=std::string(PyUnicode_AsUTF8(pAttribute));
Py_DECREF(pAttribute);
if(pAttribute = checkAndGetAttribute(fpy, "inputs", errorMessage))