{"id":2227559,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2227559/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260423222125.29097-7-vfazio@gmail.com/","project":{"id":42,"url":"http://patchwork.ozlabs.org/api/1.1/projects/42/?format=json","name":"Linux GPIO development","link_name":"linux-gpio","list_id":"linux-gpio.vger.kernel.org","list_email":"linux-gpio@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260423222125.29097-7-vfazio@gmail.com>","date":"2026-04-23T22:21:23","name":"[libgpiod,v2,6/8] bindings: python: migrate the gpiod._ext module to multi-phase init","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"67d0fea3c56e1f8127a73d246faef66a089eaadf","submitter":{"id":78694,"url":"http://patchwork.ozlabs.org/api/1.1/people/78694/?format=json","name":"Vincent Fazio","email":"vfazio@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260423222125.29097-7-vfazio@gmail.com/mbox/","series":[{"id":501257,"url":"http://patchwork.ozlabs.org/api/1.1/series/501257/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/list/?series=501257","date":"2026-04-23T22:21:18","name":"bindings: python: modernize C extensions","version":2,"mbox":"http://patchwork.ozlabs.org/series/501257/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2227559/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2227559/checks/","tags":{},"headers":{"Return-Path":"\n <linux-gpio+bounces-35438-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-gpio@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=sMRL3yAv;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-gpio+bounces-35438-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"sMRL3yAv\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.160.41","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g1rDR6vDkz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 08:21:59 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id D351C301E3E4\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 22:21:55 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 7660B3537E1;\n\tThu, 23 Apr 2026 22:21:55 +0000 (UTC)","from mail-oa1-f41.google.com (mail-oa1-f41.google.com\n [209.85.160.41])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id F2DD536165E\n\tfor <linux-gpio@vger.kernel.org>; Thu, 23 Apr 2026 22:21:53 +0000 (UTC)","by mail-oa1-f41.google.com with SMTP id\n 586e51a60fabf-40efc77933fso4770818fac.3\n        for <linux-gpio@vger.kernel.org>;\n Thu, 23 Apr 2026 15:21:53 -0700 (PDT)","from Zephyrus.localdomain ([131.93.209.211])\n        by smtp.gmail.com with ESMTPSA id\n 586e51a60fabf-42b930afa63sm17784598fac.5.2026.04.23.15.21.51\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 23 Apr 2026 15:21:52 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776982915; cv=none;\n b=EOf2RYzRtDAwWNNBFOUlXYNyvH4phuglsHraALpAmW8Qfhzl5OVFOOiCYD8WC9JTTjR4u28ahDZR3iqOOglWhiTvTGVpbJveAQs3xBHuTVDCh72QLnGSlXCR44V0lZwGAVErnj/WatwDDeEJgw86TvAeplRQJSFOfPKCnpLDzDE=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776982915; c=relaxed/simple;\n\tbh=wqRyhsFL8/PIgzivNJzkf8YlO5l40oaLKAULRs6+7TA=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=b+1g+799knXWSDGsTTnxS/mL3SAMEAnP9prssWOFtmkXRr+Tdv1bTtZrFsgvM+j1usF2ND8MCYRiYi69wOkllRjuVb2Cvr5Dm8FHKkPgMu9q47Pp/gMBeT2pCY/qyeaNKr8Ixyvf7IhnF/TWL4c0tYszU3ZJ/BY9W/mXURnNoOA=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=sMRL3yAv; arc=none smtp.client-ip=209.85.160.41","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776982913; x=1777587713;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=yvrJ9Pts7vZlG4WnMIz51B8f/2gipKmeAo6LHOfYmKY=;\n        b=sMRL3yAvK+BkA3ezuieVyYsB56KJWM9ybJXctPVuUevkB9HcDKZHDLR/nO00mEvhUs\n         ZILqO5MEYWohEty8JNYrqKyN4ue/eYAEC29Aq5BghZHmMMHICIPRkn6B8OlEUG6Q0oGa\n         vyLW3Wvybt0TO7P5rqAAtGztjVEO15+7ciIwsc1BDA8RIuz8Yj1frmt32QZaONmXTPBD\n         GRjFxY1KdJp9jT/46n25ar+g1Vep9jznxH1nofpdr9jNOwzr7pf9XJNrMuWA21D3fnMi\n         SK1T/OVlL/w0Nv3Mf0G4/Pa/GYNerU1qRAVwCVyVEyXZBOl/JtATaFYAqtdqNJXLEE5T\n         UUqA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776982913; x=1777587713;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=yvrJ9Pts7vZlG4WnMIz51B8f/2gipKmeAo6LHOfYmKY=;\n        b=PFbksfrOv4uT44MIxprkpLri3J1fZWYOVjyuZRmK/V1h+DVSXWdidsg/hCPkk5FcCl\n         p+iI69qDb83GxZ3Esm8UfhlhwrghuE36o4cEOHbVJGeMGXkKzYH1Ab9qJRprTnCcesiw\n         E1QISNv6mmehZK/q4og6dUc4QMlQwL5GXQpFqtqzEGTrRj90RRefSrQeqSpZBXtw/6Vd\n         ltFgSXUVXm78PecrS6s4pq6tMrPsaNVf7exup7b1Hls0Ea3966o6rxwstzJBJgZcBP4/\n         Nk7gxDjhnc6+VwFuMy/yphnUDDGtOT+A88jaJgRTJdDPfN1rsmiDn6G10wNoax7YiOKr\n         LZHw==","X-Gm-Message-State":"AOJu0YyMEJWGmC8qjq+ayi0TYysNeTUZvapwDNCr0AoUh6gCQwF450u0\n\tt9SN1AlzYVrlM67UA29rCrM9CXBK+SIk4dkigu4VQW791wuIi6pNDdNbfFLw2w==","X-Gm-Gg":"AeBDiet3CE1HE/Wp7raxG5EPvcfkaFG9uuAZm6C/bhxkbzT5d5pEO0/iVFdIge5rgV1\n\tNEXhSJXlNwxZwzW+MM8eBsqqKnq6umdVQNlNqGbZgpAtRj22EL028AuHb2ep14VW+WOtboCG6wS\n\txw4NSAFkhd3nioFIh3smQbBZLnb6tM7SNLgsEVS44rS5kjqU82PtgWZs6J3RLuvk0JDXGOSf8ym\n\tkZK/Cta4wQPUl2MAnYf4aRxe6Dnim3kxI4wTg79NlY+I21waeVpfmMWYWAV7o/jr/ivtLjY8qhi\n\tH9mfyv6xfUzrEb4gr0hhgwAQFIAkMvwg6H3EaIU1AbwDei/qwOqJNmUEQOnRldOAIOFfAsAPDlx\n\tTPzHgyDaTHIspvAQRwfStm5I36eGK+T15C1nW5mwtFk+eZ1VnrXccHdUpwudEtKJfG0+xja63UB\n\t+6IP8vh0LjEETZcxzoEUUf+BG9DbqbhT5PipIcQcGW4l//O4MJvDM4Ckv1RAfciieCGOnztDnTJ\n\tp0O7cQlFp8=","X-Received":"by 2002:a05:6870:b3f0:b0:42c:d98:9540 with SMTP id\n 586e51a60fabf-42c0d989f78mr10431260fac.0.1776982912658;\n        Thu, 23 Apr 2026 15:21:52 -0700 (PDT)","From":"Vincent Fazio <vfazio@gmail.com>","To":"linux-gpio@vger.kernel.org","Cc":"brgl@kernel.org,\n\tVincent Fazio <vfazio@gmail.com>","Subject":"[libgpiod][PATCH v2 6/8] bindings: python: migrate the gpiod._ext\n module to multi-phase init","Date":"Thu, 23 Apr 2026 17:21:23 -0500","Message-ID":"<20260423222125.29097-7-vfazio@gmail.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260423222125.29097-1-vfazio@gmail.com>","References":"<20260423222125.29097-1-vfazio@gmail.com>","Precedence":"bulk","X-Mailing-List":"linux-gpio@vger.kernel.org","List-Id":"<linux-gpio.vger.kernel.org>","List-Subscribe":"<mailto:linux-gpio+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-gpio+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Single-phase initialization has been classified as legacy within CPython\ndocumentation [0] with multi-phase being its successor [1].\n\nAs such, switch to the new methodology.\n\n[0]: https://docs.python.org/3/c-api/extension-modules.html#legacy-single-phase-initialization\n[1]: https://docs.python.org/3/c-api/extension-modules.html#multi-phase-initialization\n\nSigned-off-by: Vincent Fazio <vfazio@gmail.com>\n---\n bindings/python/gpiod/ext/module.c | 68 +++++++++++++++---------------\n 1 file changed, 33 insertions(+), 35 deletions(-)","diff":"diff --git a/bindings/python/gpiod/ext/module.c b/bindings/python/gpiod/ext/module.c\nindex 25c252a..71fa3c2 100644\n--- a/bindings/python/gpiod/ext/module.c\n+++ b/bindings/python/gpiod/ext/module.c\n@@ -135,12 +135,6 @@ static PyMethodDef module_methods[] = {\n \t{ }\n };\n \n-static PyModuleDef module_def = {\n-\tPyModuleDef_HEAD_INIT,\n-\t.m_name = \"gpiod._ext\",\n-\t.m_methods = module_methods,\n-};\n-\n extern PyTypeObject chip_type;\n extern PyTypeObject line_config_type;\n extern PyTypeObject line_settings_type;\n@@ -154,53 +148,57 @@ static PyTypeObject *types[] = {\n \tNULL,\n };\n \n-PyMODINIT_FUNC PyInit__ext(void)\n+static int module_exec(PyObject* module)\n {\n \tconst struct module_const *modconst;\n-\tPyObject *module, *all;\n+\tPyObject *all;\n \tPyTypeObject **type;\n \tint ret;\n \n-\tmodule = PyModule_Create(&module_def);\n-\tif (!module)\n-\t\treturn NULL;\n-\n \tret = PyModule_AddStringConstant(module, \"api_version\",\n \t\t\t\t\t gpiod_api_version());\n-\tif (ret) {\n-\t\tPy_DECREF(module);\n-\t\treturn NULL;\n-\t}\n+\n+\tif (ret < 0)\n+\t\treturn -1;\n \n \tall = PyList_New(0);\n-\tif (!all) {\n-\t\tPy_DECREF(module);\n-\t\treturn NULL;\n-\t}\n+\tif (!all)\n+\t\treturn -1;\n \n \tret = PyModule_AddObjectRef(module, \"__all__\", all);\n \tPy_DECREF(all);\n-\tif (ret) {\n-\t\tPy_DECREF(module);\n-\t\treturn NULL;\n-\t}\n+\tif (ret)\n+\t\treturn -1;\n \n \tfor (type = types; *type; type++) {\n \t\tret = PyModule_AddType(module, *type);\n-\t\tif (ret) {\n-\t\t\tPy_DECREF(module);\n-\t\t\treturn NULL;\n-\t\t}\n+\t\tif (ret < 0)\n+\t\t\treturn -1;\n \t}\n \n \tfor (modconst = module_constants; modconst->name; modconst++) {\n-\t\tret = PyModule_AddIntConstant(module,\n-\t\t\t\t\t      modconst->name, modconst->val);\n-\t\tif (ret) {\n-\t\t\tPy_DECREF(module);\n-\t\t\treturn NULL;\n-\t\t}\n+\t\tret = PyModule_AddIntConstant(module, modconst->name,\n+\t\t\t\t\t      modconst->val);\n+\t\tif (ret < 0)\n+\t\t\treturn -1;\n \t}\n \n-\treturn module;\n+\treturn 0;\n+}\n+\n+static struct PyModuleDef_Slot module_slots[] = {\n+\t{Py_mod_exec, module_exec},\n+\t{0, NULL},\n+};\n+\n+static PyModuleDef module_def = {\n+\tPyModuleDef_HEAD_INIT,\n+\t.m_name = \"gpiod._ext\",\n+\t.m_methods = module_methods,\n+\t.m_slots = module_slots,\n+};\n+\n+PyMODINIT_FUNC PyInit__ext(void)\n+{\n+\treturn PyModuleDef_Init(&module_def);\n }\n","prefixes":["libgpiod","v2","6/8"]}