diff --git a/fm-common/centos/fm-common.spec b/fm-common/centos/fm-common.spec index 8f1dc81c..d549fa5d 100644 --- a/fm-common/centos/fm-common.spec +++ b/fm-common/centos/fm-common.spec @@ -1,7 +1,7 @@ %define local_dir /usr/local %define local_bindir %{local_dir}/bin %define cgcs_doc_deploy_dir /opt/deploy/cgcs_doc -%define pythonroot /usr/lib64/python2.7/site-packages +%define pythonroot %python3_sitearch Summary: CGTS Platform Fault Management Common Package Name: fm-common @@ -15,10 +15,10 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: util-linux BuildRequires: postgresql-devel BuildRequires: libuuid-devel -BuildRequires: python-devel -BuildRequires: python-setuptools -BuildRequires: python2-pip -BuildRequires: python2-wheel +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +BuildRequires: python3-wheel %package -n fm-common-dev Summary: CGTS Platform Fault Management Common Package - Development files @@ -51,8 +51,8 @@ VER=%{version} MAJOR=`echo $VER | awk -F . '{print $1}'` MINOR=`echo $VER | awk -F . '{print $2}'` make MAJOR=$MAJOR MINOR=$MINOR %{?_smp_mflags} -%{__python} setup.py build -%py2_build_wheel +%{__python3} setup.py build +%py3_build_wheel %install rm -rf %{buildroot} @@ -66,7 +66,7 @@ make DESTDIR=%{buildroot} \ CGCS_DOC_DEPLOY=%{cgcs_doc_deploy_dir} \ MAJOR=$MAJOR MINOR=$MINOR install -%{__python} setup.py install --root=%{buildroot} \ +%{__python3} setup.py install --root=%{buildroot} \ --install-lib=%{pythonroot} \ --prefix=/usr \ --install-data=/usr/share @@ -83,7 +83,9 @@ rm -rf %{buildroot} %{local_bindir}/* %{_libdir}/*.so.* -%{pythonroot}/fm_core.so +# with python3 PEP 3149, ABI version is tagged in so name. +# so the file name will be like: fm_core.cpython-36m-x86_64-linux-gnu.so +%{pythonroot}/fm_core.cpython-3*.so %{pythonroot}/fm_core-*.egg-info %files -n fm-common-dev diff --git a/fm-common/sources/Makefile b/fm-common/sources/Makefile index 7b1ea031..39c3b28c 100755 --- a/fm-common/sources/Makefile +++ b/fm-common/sources/Makefile @@ -4,7 +4,7 @@ SRCS = fmAPI.cpp fmFile.cpp fmLog.cpp fmMsgServer.cpp fmMutex.cpp fmSocket.cpp f CLI_SRCS = fm_cli.cpp OBJS = $(SRCS:.cpp=.o) CLI_OBJS = fm_cli.o -LDLIBS = -lstdc++ -lrt -luuid -lpq -lpthread -lpython2.7 +LDLIBS = -lstdc++ -lrt -luuid -lpq -lpthread -lpython3.6m INCLUDES = -I./ -I$(shell pg_config --includedir) CCFLAGS = -g -O2 -Wall -Werror -fPIC EXTRACCFLAGS= -Wformat -Wformat-security diff --git a/fm-common/sources/fmDbUtils.cpp b/fm-common/sources/fmDbUtils.cpp index 98790b74..bbde207f 100644 --- a/fm-common/sources/fmDbUtils.cpp +++ b/fm-common/sources/fmDbUtils.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include "fmMutex.h" @@ -611,21 +611,32 @@ bool fm_db_util_sync_event_suppression(void){ FILE* file; int argc; - char * argv[2]; FM_INFO_LOG("Starting event suppression synchronization...\n"); argc = 2; - argv[0] = (char*)FM_DB_SYNC_EVENT_SUPPRESSION; - argv[1] = (char*)db_conn; - Py_SetProgramName(argv[0]); + wchar_t *py_argv[2]; + py_argv[0] = Py_DecodeLocale(FM_DB_SYNC_EVENT_SUPPRESSION, NULL); + if (py_argv[0] == NULL) { + FM_ERROR_LOG("Fatal error: cannot decode argv[0]\n"); + return false; + } + py_argv[1] = Py_DecodeLocale(db_conn, NULL); + if (py_argv[1] == NULL) { + PyMem_RawFree(py_argv[0]); + FM_ERROR_LOG("Fatal error: cannot decode argv[1]\n"); + return false; + } + Py_SetProgramName(py_argv[0]); Py_Initialize(); - PySys_SetArgv(argc, argv); + PySys_SetArgv(argc, py_argv); file = fopen(FM_DB_SYNC_EVENT_SUPPRESSION,"r"); PyRun_SimpleFile(file, FM_DB_SYNC_EVENT_SUPPRESSION); fclose(file); Py_Finalize(); + PyMem_RawFree(py_argv[0]); + PyMem_RawFree(py_argv[1]); FM_INFO_LOG("Completed event suppression synchronization.\n"); diff --git a/fm-common/sources/fm_db_sync_event_suppression.py b/fm-common/sources/fm_db_sync_event_suppression.py index 16777c63..badc6aa9 100755 --- a/fm-common/sources/fm_db_sync_event_suppression.py +++ b/fm-common/sources/fm_db_sync_event_suppression.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (c) 2016-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 diff --git a/fm-common/sources/fm_python_mod_main.cpp b/fm-common/sources/fm_python_mod_main.cpp index c47669aa..2c1461b7 100644 --- a/fm-common/sources/fm_python_mod_main.cpp +++ b/fm-common/sources/fm_python_mod_main.cpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: Apache-2.0 // - -#include +#define PY_SSIZE_T_CLEAN +#include #include #include "fmAPI.h" #include "fmAlarmUtils.h" @@ -84,7 +84,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){ @@ -120,7 +120,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) { @@ -165,7 +165,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"); } } @@ -214,7 +214,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"); } } @@ -313,10 +313,20 @@ static PyMethodDef _methods [] = { { NULL, NULL, 0, NULL } }; +static struct PyModuleDef cModPyDem = +{ + PyModuleDef_HEAD_INIT, + "fm_core", /* name of module */ + "", /* module documentation, may be NULL */ + -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ + _methods +}; + PyMODINIT_FUNC initfm_core() { - PyObject *m = Py_InitModule("fm_core", _methods); + PyObject *m = PyModule_Create(&cModPyDem); if (m == NULL){ PySys_WriteStderr("Failed to initialize fm_core"); - return; + return NULL; } + return m; }