From de505079f3a623411d0b73d6a3132b9756bcdf76 Mon Sep 17 00:00:00 2001 From: Markus Wanner Date: Tue, 26 Aug 2025 22:23:49 +0200 Subject: [PATCH] Update to compile against python3 --- Makefile | 2 +- src/passfd.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 30b1143..a2284d7 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ BUILDDIR = build DISTDIR = dist # Gah -SUBBUILDDIR = $(shell python -c 'import distutils.util, sys; print "lib.%s-%s" % (distutils.util.get_platform(), sys.version[0:3])') +SUBBUILDDIR = $(shell python -c 'import distutils.util, sys; print("lib.%s-%s" % (distutils.util.get_platform(), sys.version[0:3]))') BUILDDIR := $(BUILDDIR)/$(SUBBUILDDIR) COVERAGE = $(or $(shell which coverage), $(shell which python-coverage), \ diff --git a/src/passfd.c b/src/passfd.c index 04e23e6..b7dea34 100644 --- a/src/passfd.c +++ b/src/passfd.c @@ -106,12 +106,26 @@ static PyMethodDef methods[] = { {NULL, NULL, 0, NULL} }; +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef passfd_module = { + PyModuleDef_HEAD_INIT, + "_passfd", + "Functions to pass file descriptors across UNIX domain sockets", + -1, + methods +}; + +PyMODINIT_FUNC PyInit__passfd(void) { + return PyModule_Create(&passfd_module); +} +#else PyMODINIT_FUNC init_passfd(void) { PyObject *m; m = Py_InitModule("_passfd", methods); if (m == NULL) return; } +#endif /* PY_MAJOR_VERSION >= 3 */ /* Size of the cmsg including one file descriptor */ #define CMSG_SIZE CMSG_SPACE(sizeof(int))