{"id":2225988,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2225988/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260422012041.39933-7-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-7-vfazio@gmail.com>","list_archive_url":null,"date":"2026-04-22T01:20:38","name":"[libgpiod,6/9] bindings: python: use PyImport_ImportModuleAttrString when available","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6e7a81fa6f60233c62dd60ffa9f2f6eba2576784","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-7-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/2225988/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225988/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-gpio+bounces-35327-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=fhfAU4+Z;\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-35327-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=\"fhfAU4+Z\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.160.54","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 4g0hJn2tpPz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:21:45 +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 0B58A303B7F9\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 DD95B2D5436;\n\tWed, 22 Apr 2026 01:21:03 +0000 (UTC)","from mail-oa1-f54.google.com (mail-oa1-f54.google.com\n [209.85.160.54])\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 6CEA3200C2\n\tfor <linux-gpio@vger.kernel.org>; Wed, 22 Apr 2026 01:21:02 +0000 (UTC)","by mail-oa1-f54.google.com with SMTP id\n 586e51a60fabf-42fbf95cca8so317019fac.0\n        for <linux-gpio@vger.kernel.org>;\n Tue, 21 Apr 2026 18:21:02 -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.00\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 21 Apr 2026 18:21:00 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776820863; cv=none;\n b=LbCkwLnjtfXMlqwdMzK7bYHrpDo/LWMSSwG7OLDR3KfkDcA8nan/j6Ie5m/ub0Kv074hXsW43MPRL6bBMFaDzI+5Yg/MsiIceIglDasRayqJkfQxR94CNF6z4znOqWAohTlWKY2ml/ZpCHv8RHqg7ULZRswoaca2KoEbzNBgoTw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776820863; c=relaxed/simple;\n\tbh=tpuxXJ4fKIV8MkMtvscHa5DQXdXPFwcCok4985Xen8M=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=WJzeGhBE8gjutvj9DL/Z4A674nD4WlFwMZBGts/EIWg9CNGdDpS6FvFo09fSNjiWJvIHn1GXn/WZMMhJ4I39zXlVnpMigQ9UCYxifjpgMVI1CvoqTBGDoeLH5AqbtPaSDSKWzpyEYJyrZl9cJHTme0R37/uZBkVGdYZOo2zDQwo=","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=fhfAU4+Z; arc=none smtp.client-ip=209.85.160.54","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776820861; x=1777425661;\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=Z2nMEq+vh8lDv5J7/vwrmy0PP3tp5v9ohfw+PwdcpIQ=;\n        b=fhfAU4+ZDgyp6Go3Ta/d+8X7W8eeqsS1zbLQHYvSfaRO4s6MfUHX3YMGnjXb8UW05o\n         2oFskavHET5rzQ5vJI90lwupJfh3vLOMc0goomMqTZIxIZFVdOSuGMJaePMuhylNWyb0\n         BtZu2baGQRRUmkG4HtOABRUm7xJiuein9QpKT8L34i6FuVF0aHZ4+wFJKH989ctAzA8f\n         PYkjvNhYfhbfAhEZPM3g+wH1WILxbL6JD/WgttXK58RXE2F2uywOwcmANhYXu+HEh2ta\n         7A+Yi3RiBpjJMK3ST0spreB702EGnuhnGfIq/2wJ146Sc06fXEcjIz/SUANHS5IYO6W/\n         738A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776820861; x=1777425661;\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=Z2nMEq+vh8lDv5J7/vwrmy0PP3tp5v9ohfw+PwdcpIQ=;\n        b=TdHBQdBQsrKQI8jsb8Pe7ubmFjGamB3bitLNCcXXEjUmO+/Zol8vcgKJrz46W8DPw/\n         CEXbfs0CyulaidP2RSI5B8K7etkpyxwSSwfbSm6eJnLrqHaVR0hluzQb5lkwtptOr5PF\n         oK2E4SLnqV4xZ8wbAPSwLh92R2xzUZXDiDHdS8jHnc/18PRKVUtxfvc8NbSnf3RNrN7j\n         98Ns+aNu6m53kua590fYN6N6hctQ2ySNYS59iOZRSbEdSGOy/1MZo5LtQn0HRWBmP5t0\n         XxLbANZQYuZgWXH48gsBNu/S0N73O20aFdF+EsSxPTLs+0jzc1nOCNJqa4U48oGkKjWz\n         UYQw==","X-Gm-Message-State":"AOJu0YzFv6RF9/Ps4itajo1LO0BE7IfnJY1mRIzOYZvhI3RHThGW+KmH\n\tECMpZ62T4q0toMWUOn4QUJPGZmc0Bz6mogQ3Yg9A1TWUjUzliFU/BQKP6R0DiA==","X-Gm-Gg":"AeBDieubNzPklF8LrdlbC009dQfclZ0IRdXaH/EPY53RWZiVpLOMMPOUd9Wrx0j7Qb3\n\tIDJi9i1SmDk2Rxgi8LrXOBBDcW4ky9hRR7kAZ69zsicaFVo+n+u2VoTFTj6FrAZkEKDf0HEQIjS\n\tx5hkdl+yr1Nn6dRnXChvJZfpwrCkVc0g78fi1u7yOb3FikMIAN3A6iKhz7JmcVoiSdEmqmaInS2\n\tiT/NQ8J2GJmInNfwDpZQGHqE+uybzyo8WxQqOwCnd9mgkkvAhkTR0d4Iti9YZ8OLGjxefMF7Lc/\n\thiiBiTkEEGCbV8Wf9/UU148EHNAKJE653DCXtuVxMa+L3oWrqXk7fMFaD17mr5BSBObi1B5WDEe\n\ty/TuekACkWXrpQEdVmMaHKnpWfhUTJ/DZIH7w93IcdPvw24KfmPtM1ORJ01+NInngWZfroc8jsy\n\td2ieQeqB6F+0OrHT9dNxi9ECraVdwjyOrkNOlhGINmWV5CXnJYZn8eGdZN7fRkB555c+j0T83d","X-Received":"by 2002:a05:6820:f024:b0:694:9d60:99ab with SMTP id\n 006d021491bc7-6949d60a6d0mr2308570eaf.6.1776820861200;\n        Tue, 21 Apr 2026 18:21:01 -0700 (PDT)","From":"Vincent Fazio <vfazio@gmail.com>","To":"linux-gpio@vger.kernel.org","Cc":"Vincent Fazio <vfazio@gmail.com>","Subject":"[libgpiod][PATCH 6/9] bindings: python: use\n PyImport_ImportModuleAttrString when available","Date":"Tue, 21 Apr 2026 20:20:38 -0500","Message-ID":"<20260422012041.39933-7-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":"Commit 035ad74fdd introduced Py_gpiod_GetModuleAttrString as a way to\nget a module's attribute and was inspired by CPython's internal function\n_PyImport_GetModuleAttrString.\n\nCPython 3.14 added PyImport_ImportModuleAttrString to the public API [0]\nwhich allows us to use the standard function when available.\n\n[0]: https://github.com/python/cpython/pull/128912\n\nSigned-off-by: Vincent Fazio <vfazio@gmail.com>\n---\n bindings/python/gpiod/ext/common.c   |  3 +++\n bindings/python/gpiod/ext/internal.h | 10 ++++++++--\n 2 files changed, 11 insertions(+), 2 deletions(-)","diff":"diff --git a/bindings/python/gpiod/ext/common.c b/bindings/python/gpiod/ext/common.c\nindex 7d2dda7..fc28e96 100644\n--- a/bindings/python/gpiod/ext/common.c\n+++ b/bindings/python/gpiod/ext/common.c\n@@ -64,6 +64,8 @@ PyObject *Py_gpiod_SetErrFromErrno(void)\n \treturn PyErr_SetFromErrno(exc);\n }\n \n+/* TODO: remove when 3.14 is the minimum version */\n+#if PY_VERSION_HEX < 0x030E0000\n PyObject *Py_gpiod_GetModuleAttrString(const char *modname,\n \t\t\t\t       const char *attrname)\n {\n@@ -78,6 +80,7 @@ PyObject *Py_gpiod_GetModuleAttrString(const char *modname,\n \n \treturn attribute;\n }\n+#endif\n \n unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong)\n {\ndiff --git a/bindings/python/gpiod/ext/internal.h b/bindings/python/gpiod/ext/internal.h\nindex 15aedfb..2996884 100644\n--- a/bindings/python/gpiod/ext/internal.h\n+++ b/bindings/python/gpiod/ext/internal.h\n@@ -8,8 +8,6 @@\n #include <Python.h>\n \n PyObject *Py_gpiod_SetErrFromErrno(void);\n-PyObject *Py_gpiod_GetModuleAttrString(const char *modname,\n-\t\t\t\t       const char *attrname);\n unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong);\n void Py_gpiod_dealloc(PyObject *self);\n PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,\n@@ -17,4 +15,12 @@ PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,\n struct gpiod_line_config *Py_gpiod_LineConfigGetData(PyObject *obj);\n struct gpiod_line_settings *Py_gpiod_LineSettingsGetData(PyObject *obj);\n \n+#if PY_VERSION_HEX >= 0x030E0000\n+/* Alias to standard function available in 3.14 */\n+#define Py_gpiod_GetModuleAttrString PyImport_ImportModuleAttrString\n+#else\n+PyObject *Py_gpiod_GetModuleAttrString(const char *modname,\n+\t\t\t\t       const char *attrname);\n+#endif /* PY_VERSION_HEX >= 0x030E0000 */\n+\n #endif /* __LIBGPIOD_PYTHON_MODULE_H__ */\n","prefixes":["libgpiod","6/9"]}