diff mbox series

wpaspy: allow building with python3

Message ID 1602404451-Ib161859e81b1c347316579ebad1b2cebe5d092d9@changeid
State Accepted
Headers show
Series wpaspy: allow building with python3 | expand

Commit Message

Johannes Berg Oct. 11, 2020, 8:20 a.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

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 |  1 +
 wpaspy/wpaspy.c | 37 +++++++++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

Comments

Jouni Malinen Oct. 11, 2020, 6:28 p.m. UTC | #1
On Sun, Oct 11, 2020 at 10:20:51AM +0200, Johannes Berg wrote:
> 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.

Thanks, applied.
diff mbox series

Patch

diff --git a/wpaspy/Makefile b/wpaspy/Makefile
index bc920e0cc503..6f720a9fe121 100644
--- a/wpaspy/Makefile
+++ b/wpaspy/Makefile
@@ -2,6 +2,7 @@  all: build
 
 SRC=wpaspy.c
 
+.PHONY: build
 build: $(SRC) setup.py
 	python setup.py build
 
diff --git a/wpaspy/wpaspy.c b/wpaspy/wpaspy.c
index 278089b48ada..718bdca3c792 100644
--- a/wpaspy/wpaspy.c
+++ b/wpaspy/wpaspy.c
@@ -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,36 @@  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)
+		goto error;
+	if (PyModule_AddObject(mod, "error", wpaspy_error) < 0)
+		goto error;
+
+	return mod;
+error:
+	Py_DECREF(&wpaspy_ctrl);
+	Py_DECREF(wpaspy_error);
+	Py_DECREF(mod);
+	return NULL;
+}
+#endif