]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpaspy: Allow building with python3
authorJohannes Berg <johannes.berg@intel.com>
Sun, 11 Oct 2020 08:20:51 +0000 (10:20 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 11 Oct 2020 16:41:08 +0000 (19:41 +0300)
Add the necessary modified module registration code to allow building
wpaspy with python3. Also clean up the wpaspy_close() function to not
poke into the python version specific details.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
wpaspy/Makefile
wpaspy/wpaspy.c

index bc920e0cc5036b24145aef4286ce07a0f2ec4217..6f720a9fe1218cfd566930ec6d5a4a99b4412bfe 100644 (file)
@@ -2,6 +2,7 @@ all: build
 
 SRC=wpaspy.c
 
+.PHONY: build
 build: $(SRC) setup.py
        python setup.py build
 
index 278089b48adaf24559759f981fdce84ac9ec39c4..4d4c2a49569f75b38fa7eddf176bf1c6c3c4d581 100644 (file)
@@ -44,8 +44,7 @@ static void wpaspy_close(struct wpaspy_obj *self)
                self->ctrl = NULL;
        }
 
-       if (self->ob_type)
-               self->ob_type->tp_free((PyObject *) self);
+       PyObject_Del(self);
 }
 
 
@@ -193,6 +192,7 @@ static PyTypeObject wpaspy_ctrl = {
 };
 
 
+#if PY_MAJOR_VERSION < 3
 static PyMethodDef module_methods[] = {
        { NULL, NULL, 0, NULL }
 };
@@ -212,3 +212,34 @@ PyMODINIT_FUNC initwpaspy(void)
        PyModule_AddObject(mod, "Ctrl", (PyObject *) &wpaspy_ctrl);
        PyModule_AddObject(mod, "error", wpaspy_error);
 }
+#else
+static struct PyModuleDef wpaspy_def = {
+       PyModuleDef_HEAD_INIT,
+       "wpaspy",
+};
+
+
+PyMODINIT_FUNC initwpaspy(void)
+{
+       PyObject *mod;
+
+       mod = PyModule_Create(&wpaspy_def);
+       if (!mod)
+               return NULL;
+
+       wpaspy_error = PyErr_NewException("wpaspy.error", NULL, NULL);
+
+       Py_INCREF(&wpaspy_ctrl);
+       Py_INCREF(wpaspy_error);
+
+       if (PyModule_AddObject(mod, "Ctrl", (PyObject *) &wpaspy_ctrl) < 0 ||
+           PyModule_AddObject(mod, "error", wpaspy_error) < 0) {
+               Py_DECREF(&wpaspy_ctrl);
+               Py_DECREF(wpaspy_error);
+               Py_DECREF(mod);
+               mod = NULL;
+       }
+
+       return mod;
+}
+#endif