Fix python3.9 building

PyString_FromString has been removed from python3.9,
use PyUnicode_FromString instead since its backwards
compatible with python2.7.

Story: 2009101
Task: 43219

Signed-off-by: Charles Short <charles.short@windriver.com>
Change-Id: I9535e0f36d56dd5ae15c1ffea27fdf0877de0484
This commit is contained in:
Charles Short 2021-09-07 08:40:25 -04:00
parent 5296a75fbc
commit a0774c1c94
1 changed files with 5 additions and 8 deletions

View File

@ -6,11 +6,8 @@
#if PY_MAJOR_VERSION >= 3
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#define PyString_FromString PyUnicode_FromString
#else
#include <Python.h>
#endif
#include <Python.h>
#include <stdio.h>
#include "fmAPI.h"
#include "fmAlarmUtils.h"
@ -89,7 +86,7 @@ static PyObject * _fm_set(PyObject * self, PyObject *args) {
rc = fm_set_fault(&alm_data, &tmp_uuid);
if (rc == FM_ERR_OK) {
return PyString_FromString(&(tmp_uuid[0]));
return PyUnicode_FromString(&(tmp_uuid[0]));
}
if (rc == FM_ERR_NOCONNECT){
@ -125,7 +122,7 @@ static PyObject * _fm_get(PyObject * self, PyObject *args) {
rc = fm_get_fault(&af,&ad);
if (rc == FM_ERR_OK) {
fm_alarm_to_string(&ad,alm_str);
return PyString_FromString(alm_str.c_str());
return PyUnicode_FromString(alm_str.c_str());
}
if (rc == FM_ERR_ENTITY_NOT_FOUND) {
@ -170,7 +167,7 @@ static PyObject * _fm_get_by_aid(PyObject * self, PyObject *args, PyObject* kwar
std::string s;
fm_alarm_to_string(&lst[ix],s);
if (s.size() > 0) {
if (PyList_Append(__lst, PyString_FromString(s.c_str())) != 0) {
if (PyList_Append(__lst, PyUnicode_FromString(s.c_str())) != 0) {
ERROR_LOG("Failed to append alarm to the list");
}
}
@ -219,7 +216,7 @@ static PyObject * _fm_get_by_eid(PyObject * self, PyObject *args, PyObject* kwar
std::string s;
fm_alarm_to_string(&lst[ix], s);
if (s.size() > 0) {
if (PyList_Append(__lst,PyString_FromString(s.c_str())) != 0) {
if (PyList_Append(__lst,PyUnicode_FromString(s.c_str())) != 0) {
ERROR_LOG("Failed to append alarm to the list");
}
}