Merge "Re-enable python2 support" into f/centos8

This commit is contained in:
Zuul 2021-07-21 12:35:59 +00:00 committed by Gerrit Code Review
commit 1a199b4da6
3 changed files with 50 additions and 15 deletions

View File

@ -4,13 +4,24 @@ SRCS = fmAPI.cpp fmFile.cpp fmLog.cpp fmMsgServer.cpp fmMutex.cpp fmSocket.cpp f
CLI_SRCS = fm_cli.cpp CLI_SRCS = fm_cli.cpp
OBJS = $(SRCS:.cpp=.o) OBJS = $(SRCS:.cpp=.o)
CLI_OBJS = fm_cli.o CLI_OBJS = fm_cli.o
LDLIBS = -lstdc++ -lrt -luuid -lpq -lpthread -lpython3.6m -ljson-c LDLIBS = -lstdc++ -lrt -luuid -lpq -lpthread -ljson-c
INCLUDES = -I./ -I$(shell pg_config --includedir) INCLUDES = -I./ -I$(shell pg_config --includedir)
CCFLAGS = -g -O2 -Wall -Werror -fPIC CCFLAGS = -g -O2 -Wall -fPIC
EXTRACCFLAGS= -Wformat -Wformat-security EXTRACCFLAGS= -Wformat -Wformat-security
MAJOR ?= 1 MAJOR ?= 1
MINOR ?= 0 MINOR ?= 0
OS_ID = $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
OS_VERSION_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-8)
LDLIBS += -lpython3.6m
INCLUDES += -I/usr/include/python3.6m
CCFLAGS += -Werror
else
INCLUDES += -I/usr/include/python2.7
LDLIBS += -lpython2.7
endif
DESTDIR ?= / DESTDIR ?= /
BINDIR ?= /usr/local/bin BINDIR ?= /usr/local/bin

View File

@ -15,7 +15,7 @@
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <python3.6m/Python.h> #include <Python.h>
#include "fmMutex.h" #include "fmMutex.h"
@ -616,6 +616,7 @@ bool fm_db_util_sync_event_suppression(void){
argc = 2; argc = 2;
#if PY_MAJOR_VERSION >= 3
wchar_t *py_argv[2]; wchar_t *py_argv[2];
py_argv[0] = Py_DecodeLocale(FM_DB_SYNC_EVENT_SUPPRESSION, NULL); py_argv[0] = Py_DecodeLocale(FM_DB_SYNC_EVENT_SUPPRESSION, NULL);
if (py_argv[0] == NULL) { if (py_argv[0] == NULL) {
@ -629,14 +630,23 @@ bool fm_db_util_sync_event_suppression(void){
return false; return false;
} }
Py_SetProgramName(py_argv[0]); Py_SetProgramName(py_argv[0]);
#else
char * argv[2];
argv[0] = (char*)FM_DB_SYNC_EVENT_SUPPRESSION;
argv[1] = (char*)db_conn;
Py_SetProgramName(argv[0]);
#endif
Py_Initialize(); Py_Initialize();
PySys_SetArgv(argc, py_argv); PySys_SetArgv(argc, py_argv);
file = fopen(FM_DB_SYNC_EVENT_SUPPRESSION,"r"); file = fopen(FM_DB_SYNC_EVENT_SUPPRESSION,"r");
PyRun_SimpleFile(file, FM_DB_SYNC_EVENT_SUPPRESSION); PyRun_SimpleFile(file, FM_DB_SYNC_EVENT_SUPPRESSION);
fclose(file); fclose(file);
Py_Finalize(); Py_Finalize();
#if PY_MAJOR_VERSION >= 3
PyMem_RawFree(py_argv[0]); PyMem_RawFree(py_argv[0]);
PyMem_RawFree(py_argv[1]); PyMem_RawFree(py_argv[1]);
#endif
FM_INFO_LOG("Completed event suppression synchronization.\n"); FM_INFO_LOG("Completed event suppression synchronization.\n");

View File

@ -4,8 +4,13 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
#if PY_MAJOR_VERSION >= 3
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
#include <python3.6m/Python.h> #include <Python.h>
#define PyString_FromString PyUnicode_FromString
#else
#include <Python.h>
#endif
#include <stdio.h> #include <stdio.h>
#include "fmAPI.h" #include "fmAPI.h"
#include "fmAlarmUtils.h" #include "fmAlarmUtils.h"
@ -84,7 +89,7 @@ static PyObject * _fm_set(PyObject * self, PyObject *args) {
rc = fm_set_fault(&alm_data, &tmp_uuid); rc = fm_set_fault(&alm_data, &tmp_uuid);
if (rc == FM_ERR_OK) { if (rc == FM_ERR_OK) {
return PyUnicode_FromString(&(tmp_uuid[0])); return PyString_FromString(&(tmp_uuid[0]));
} }
if (rc == FM_ERR_NOCONNECT){ if (rc == FM_ERR_NOCONNECT){
@ -120,7 +125,7 @@ static PyObject * _fm_get(PyObject * self, PyObject *args) {
rc = fm_get_fault(&af,&ad); rc = fm_get_fault(&af,&ad);
if (rc == FM_ERR_OK) { if (rc == FM_ERR_OK) {
fm_alarm_to_string(&ad,alm_str); fm_alarm_to_string(&ad,alm_str);
return PyUnicode_FromString(alm_str.c_str()); return PyString_FromString(alm_str.c_str());
} }
if (rc == FM_ERR_ENTITY_NOT_FOUND) { if (rc == FM_ERR_ENTITY_NOT_FOUND) {
@ -165,7 +170,7 @@ static PyObject * _fm_get_by_aid(PyObject * self, PyObject *args, PyObject* kwar
std::string s; std::string s;
fm_alarm_to_string(&lst[ix],s); fm_alarm_to_string(&lst[ix],s);
if (s.size() > 0) { if (s.size() > 0) {
if (PyList_Append(__lst, PyUnicode_FromString(s.c_str())) != 0) { if (PyList_Append(__lst, PyString_FromString(s.c_str())) != 0) {
ERROR_LOG("Failed to append alarm to the list"); ERROR_LOG("Failed to append alarm to the list");
} }
} }
@ -214,7 +219,7 @@ static PyObject * _fm_get_by_eid(PyObject * self, PyObject *args, PyObject* kwar
std::string s; std::string s;
fm_alarm_to_string(&lst[ix], s); fm_alarm_to_string(&lst[ix], s);
if (s.size() > 0) { if (s.size() > 0) {
if (PyList_Append(__lst,PyUnicode_FromString(s.c_str())) != 0) { if (PyList_Append(__lst,PyString_FromString(s.c_str())) != 0) {
ERROR_LOG("Failed to append alarm to the list"); ERROR_LOG("Failed to append alarm to the list");
} }
} }
@ -313,6 +318,7 @@ static PyMethodDef _methods [] = {
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef cModPyDem = static struct PyModuleDef cModPyDem =
{ {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
@ -321,16 +327,24 @@ static struct PyModuleDef cModPyDem =
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
_methods _methods
}; };
#endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit_fm_core() { PyMODINIT_FUNC PyInit_fm_core() {
PyObject *m = PyModule_Create(&cModPyDem);
if (m == NULL){
PySys_WriteStderr("Failed to initialize fm_core");
return NULL;
}
return m;
}
#else #else
PyMODINIT_FUNC initfm_core() { PyMODINIT_FUNC initfm_core() {
#endif PyObject *m = Py_InitModule("fm_core", _methods);
PyObject *m = PyModule_Create(&cModPyDem); if (m == NULL){
if (m == NULL){ PySys_WriteStderr("Failed to initialize fm_core");
PySys_WriteStderr("Failed to initialize fm_core"); return;
return NULL; }
}
return m;
} }
#endif