From 8e44b9e38ea46d9120cc5134c7950c9ef74d679e Mon Sep 17 00:00:00 2001 From: ChiouRung Haung Date: Wed, 19 May 2021 04:16:02 +0800 Subject: [PATCH] [Minipack] Modify fbfpgaiomodule.c to support both python2 and python3 (#7604) Modify fbfpgaiomodule.c to support both python2 and python3 Signed-off-by: chiourung_huang --- .../minipack/lib/fbfpgaiomodule.c | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/minipack/lib/fbfpgaiomodule.c b/platform/broadcom/sonic-platform-modules-accton/minipack/lib/fbfpgaiomodule.c index 036eb95c944a..f5f8c8235fc5 100755 --- a/platform/broadcom/sonic-platform-modules-accton/minipack/lib/fbfpgaiomodule.c +++ b/platform/broadcom/sonic-platform-modules-accton/minipack/lib/fbfpgaiomodule.c @@ -109,10 +109,7 @@ static PyMethodDef FbfpgaMethods[] = { { NULL, NULL, 0, NULL }, }; -PyMODINIT_FUNC -initfbfpgaio(void) -{ - char docstr[] = "\ +static char docstr[] = "\ 1. hw_init():\n\ return value: True/False\n\ 2. hw_release():\n\ @@ -122,5 +119,26 @@ initfbfpgaio(void) In reading operation: data which is read from FPGA\n\ In writing operation: None\n"; +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC +initfbfpgaio(void) +{ (void) Py_InitModule3("fbfpgaio", FbfpgaMethods, docstr); } +#else +static struct PyModuleDef FbfpgaModule = +{ + PyModuleDef_HEAD_INIT, + "fbfpgaio", /* name of module */ + docstr, + -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ + FbfpgaMethods +}; + +PyMODINIT_FUNC +PyInit_fbfpgaio(void) +{ + return PyModule_Create(&FbfpgaModule); +} +#endif +