]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
_fireinfo: Migrate to Python 3
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 May 2021 15:29:31 +0000 (15:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 May 2021 15:29:31 +0000 (15:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_fireinfo/fireinfo.c

index 6601c21a733f35a0892d50bd8f95afc128c5973e..58ee7e22abede8dedd64747873dca107ec8cd066 100644 (file)
@@ -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;
 }