{"id":2225989,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2225989/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260422012041.39933-8-vfazio@gmail.com/","project":{"id":42,"url":"http://patchwork.ozlabs.org/api/1.2/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":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260422012041.39933-8-vfazio@gmail.com>","list_archive_url":null,"date":"2026-04-22T01:20:39","name":"[libgpiod,7/9] 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.2/people/78694/?format=json","name":"Vincent Fazio","email":"vfazio@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260422012041.39933-8-vfazio@gmail.com/mbox/","series":[{"id":500906,"url":"http://patchwork.ozlabs.org/api/1.2/series/500906/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/list/?series=500906","date":"2026-04-22T01:20:32","name":"bindings: python: modernize C extensions","version":1,"mbox":"http://patchwork.ozlabs.org/series/500906/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225989/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225989/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-gpio+bounces-35328-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=VplCcp/r;\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-35328-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=\"VplCcp/r\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.210.43","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 4g0hJr2Qvkz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:21:48 +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 D961A303C4D2\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 01:21:04 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id B8A422D3A6A;\n\tWed, 22 Apr 2026 01:21:04 +0000 (UTC)","from mail-ot1-f43.google.com (mail-ot1-f43.google.com\n [209.85.210.43])\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 40CA417BED0\n\tfor <linux-gpio@vger.kernel.org>; Wed, 22 Apr 2026 01:21:03 +0000 (UTC)","by mail-ot1-f43.google.com with SMTP id\n 46e09a7af769-7d9bba96f7dso2844208a34.1\n        for <linux-gpio@vger.kernel.org>;\n Tue, 21 Apr 2026 18:21:03 -0700 (PDT)","from Zephyrus.localdomain ([131.93.209.211])\n        by smtp.gmail.com with ESMTPSA id\n 006d021491bc7-69464eeee56sm9876036eaf.8.2026.04.21.18.21.01\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 21 Apr 2026 18:21:01 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776820864; cv=none;\n b=Fco9qUXrPSjhA4c6Pa4yxTeAJ5TVKLU/7fkGGwAHXFLzA1TKgesckWFC4a8y2fgcvFs9rO1A3o4m/oljIoU751vHNwJqeiFsyO+FD4FBGqxHDc8/0RxVxsWRmzwyZfytfeLsqgCpRQXqpSBYjXEpkd+YEqzxH05AsqXFJ6FuEIQ=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776820864; 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=quW6jctxV7kmqtNPq5u5V72//8w3w/E4pS/LD5/EsYRl3bQBWfyv7BxyfbRttLUh86fYhxO29lmRlVTtzuZ2ftqfHWFp2L9NU6YpxnaTjRXtDlx5I4QnqqFdROQFvPZUqEFb534ssjKopnE9n/ihJurP+RqrWOeT7+lNGXNtiSE=","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=VplCcp/r; arc=none smtp.client-ip=209.85.210.43","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776820862; x=1777425662;\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=VplCcp/rq3oP1q67T+MkWbqA6OW0NakE81OkdLNsYwQa3lSCXTbwAiRHhjjXuQWrZm\n         3uPpiODnhF7Kx9ZPJcjSZ+IVrMIT6HqdVVjWk29JHDCYxDjn8/iacL2x8ZdoH7FN4tSo\n         qTdd4CJhoBLCsOn5sQywuy1dizmY/gmWAD4JMSYZE2p15jFm+uNLJA57b8tXzbxlBcfa\n         r9AZWk6mxKJL72k97hmcKAgFH9VvWlap9wrxuTW9w7+wVW31StsFcJAbcTQPvp6ribj4\n         iDczEltstpkw3DdFNTJdcNfwP9SrnQyVWNyLfUxJzwI9sO4ah7HRuWGTG5TDBAKdJBZ/\n         n6Zg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776820862; x=1777425662;\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=HZFvjMfLrcD/hz+QPkYfVeq+UUWyL+eyxCL20uGq9+hYnx/xsL0SgLKItJemgYKHE+\n         GoD1Vn8gNsLOgGrdwce70Z5KLeXvQPtFf9Dofjl8nRRsNzRu4n5QPSUBddP6XrmSamEm\n         7GVn2B6Cb+jcXPBuCfUvszybFZqfMjaFN22DnOMnOJXM3VNGK3H6dtvmeYNcicNHlQGJ\n         jYkOIFDQ7VmTD9i4SD+3qLaDFykwA0xfbQjn+kpGHsbo12HB3FjlrtgcqYe+BQP/6iDY\n         +WPwLI+myYVM0xqCU75kUp1AGRLHKe1ZzSSsdgYRXlQyg75jhac4LFmjYX6Snpk/rD0H\n         vv+Q==","X-Gm-Message-State":"AOJu0Yxo2KRAHqeEYxdO+E7CMegHRV/Ot18ewuj5uzxVTd8ztqMYS7oy\n\tIRTPVK6fl2SmqVJT8sr/vYxtV6q/ut+2D/sTNccyDtmsOMEo5qcsfHWIejsICQ==","X-Gm-Gg":"AeBDiethn47BHHDkGp0eJCS9nUhmxw7M2NQ9ajwVXKcXtoitmgjIVMOsycQOCVviJvl\n\t5xMaBSxukYmPndRGpFZQG922BSuFSmDfIdfYBxW1O8XfBroia+kr+7LZBDy9V7/NOIJvUj79PTv\n\tNrze1DMcx7VFBMGBIPxg2h//Ay7iLPGSs/pLykChwCgKUOLx2jfCupFfCp7oRXNzBgOF/G5CkMN\n\ty6iir+H8lfKbp2cDsT4e6kQA7w4wK+oFTGExODKvRAXwk26wqmfDdHQ24dRJUgrdj6qAhJ7EItN\n\tanbq9whnykLh/c4w/nB1ZXvslGq3ny45cNVwH7YWu/eakeQhJ59LCHNvpPxxo/jn61ki1Qobi21\n\t3zPeR0MGZcqgyd9ToS11J+hoXPAieuKBHg/hMMjGfe8jvTTT++ep3AQNS1Z6fceqvx6ngSvfTyL\n\tlGuGA8V4HcmrP59dPcC6VCR0cCRX5wm9HvNp6/o0m0Ne4Usbn3faTTamjxBWjjIDcjC4wudP4p","X-Received":"by 2002:a05:6820:150e:b0:67e:295e:42a7 with SMTP id\n 006d021491bc7-69462e57d0fmr11601101eaf.16.1776820862071;\n        Tue, 21 Apr 2026 18:21:02 -0700 (PDT)","From":"Vincent Fazio <vfazio@gmail.com>","To":"linux-gpio@vger.kernel.org","Cc":"Vincent Fazio <vfazio@gmail.com>","Subject":"[libgpiod][PATCH 7/9] bindings: python: migrate the gpiod._ext module\n to multi-phase init","Date":"Tue, 21 Apr 2026 20:20:39 -0500","Message-ID":"<20260422012041.39933-8-vfazio@gmail.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260422012041.39933-1-vfazio@gmail.com>","References":"<20260422012041.39933-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","7/9"]}