From: Michael Tremer Date: Thu, 6 May 2021 15:29:31 +0000 (+0000) Subject: _fireinfo: Migrate to Python 3 X-Git-Tag: v2.2.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba11fa338ae50d44c3a7d3cc99256671e06c9a0c;p=oddments%2Ffireinfo.git _fireinfo: Migrate to Python 3 Signed-off-by: Michael Tremer --- diff --git a/src/_fireinfo/fireinfo.c b/src/_fireinfo/fireinfo.c index 6601c21..58ee7e2 100644 --- a/src/_fireinfo/fireinfo.c +++ b/src/_fireinfo/fireinfo.c @@ -185,7 +185,7 @@ do_detect_hypervisor() { if (!hypervisor_vendor) Py_RETURN_NONE; - return PyString_FromString(hypervisor_vendor); + return PyUnicode_FromString(hypervisor_vendor); } Py_RETURN_NONE; @@ -215,22 +215,30 @@ do_get_harddisk_serial(PyObject *o, PyObject *args) { strncpy(serial, (const char *)hd.serial_no, sizeof(serial) - 1); if (serial[0]) - return PyString_FromString(serial); + return PyUnicode_FromString(serial); } Py_RETURN_NONE; } -static PyMethodDef fireinfoModuleMethods[] = { +static PyMethodDef fireinfo_methods[] = { { "detect_hypervisor", (PyCFunction) do_detect_hypervisor, METH_NOARGS, NULL }, { "get_harddisk_serial", (PyCFunction) do_get_harddisk_serial, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } }; -void init_fireinfo(void) { - PyObject *m; +static struct PyModuleDef fireinfo_module = { + .m_base = PyModuleDef_HEAD_INIT, + .m_name = "_fireinfo", + .m_size = -1, + .m_doc = "Python module for fireinfo", + .m_methods = fireinfo_methods, +}; + +PyMODINIT_FUNC PyInit__fireinfo(void) { + PyObject* m = PyModule_Create(&fireinfo_module); + if (!m) + return NULL; - m = Py_InitModule("_fireinfo", fireinfoModuleMethods); - if (m == NULL) - return; + return m; }