fix run error: Py_InitModule not exist in python3.x 28/292428/5 devel master sandbox/wangbiao/py3
authorbiao716.wang <biao716.wang@samsung.com>
Mon, 8 May 2023 05:24:29 +0000 (14:24 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Mon, 8 May 2023 07:44:13 +0000 (16:44 +0900)
Change PyInt_FromLong to PyLong_FromLong
Change PyString_FromString to PyUnicode_FromString
Change-Id: Ie0b171fe5b909294271789aac18cbf1db6950a1b
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
sqlitecache.c

index 3857be7..330af63 100644 (file)
@@ -347,8 +347,8 @@ progress_cb (UpdateInfo *update_info)
     Py_INCREF(repoid);
    
     args = PyTuple_New (3);
-    PyTuple_SET_ITEM (args, 0, PyInt_FromLong (update_info->packages_seen));
-    PyTuple_SET_ITEM (args, 1, PyInt_FromLong (update_info->count_from_md));
+    PyTuple_SET_ITEM (args, 0, PyLong_FromLong (update_info->packages_seen));
+    PyTuple_SET_ITEM (args, 1, PyLong_FromLong (update_info->count_from_md));
     PyTuple_SET_ITEM (args, 2, repoid);
 
     result = PyEval_CallObject (progress, args);
@@ -517,8 +517,8 @@ log_cb (const gchar *log_domain,
         break;
     }
 
-    PyTuple_SET_ITEM (args, 0, PyInt_FromLong (level));
-    PyTuple_SET_ITEM (args, 1, PyString_FromString (message));
+    PyTuple_SET_ITEM (args, 0, PyLong_FromLong (level));
+    PyTuple_SET_ITEM (args, 1, PyUnicode_FromString (message));
 
     result = PyEval_CallObject (callback, args);
     Py_DECREF (args);
@@ -552,7 +552,7 @@ py_update (PyObject *self, PyObject *args, UpdateInfo *update_info)
     g_log_remove_handler (NULL, log_id);
 
     if (db_filename) {
-        ret = PyString_FromString (db_filename);
+        ret = PyUnicode_FromString (db_filename);
         g_free (db_filename);
     } else {
         PyErr_SetString (PyExc_TypeError, err->message);
@@ -621,13 +621,29 @@ static PyMethodDef SqliteMethods[] = {
     {NULL, NULL, 0, NULL}
 };
 
-PyMODINIT_FUNC
-init_sqlitecache (void)
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    "_sqlitecache",            /* m_name */
+    NULL,              /* m_doc */
+    0,                 /* m_size */
+    SqliteMethods,     /* m_methods */
+    NULL,              /* m_reload */
+    NULL,
+    NULL,
+    NULL               /* m_free */
+};
+
+PyObject * PyInit__sqlitecache(void);
+PyObject * PyInit__sqlitecache(void)
 {
     PyObject * m, * d;
 
-    m = Py_InitModule ("_sqlitecache", SqliteMethods);
-
+    m = PyModule_Create (&moduledef);
+    if (m == NULL) {
+        return NULL;
+    }
     d = PyModule_GetDict(m);
-    PyDict_SetItemString(d, "DBVERSION", PyInt_FromLong(YUM_SQLITE_CACHE_DBVERSION));
+    PyDict_SetItemString(d, "DBVERSION", PyLong_FromLong(YUM_SQLITE_CACHE_DBVERSION));
+
+    return m;
 }