{"id":2227556,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2227556/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260423222125.29097-3-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":"<20260423222125.29097-3-vfazio@gmail.com>","list_archive_url":null,"date":"2026-04-23T22:21:19","name":"[libgpiod,v2,2/8] bindings: python: avoid PyObject_CallMethod during request finalize","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b59e709746717682e65f9a20b7fcce884632ab6c","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/20260423222125.29097-3-vfazio@gmail.com/mbox/","series":[{"id":501257,"url":"http://patchwork.ozlabs.org/api/1.2/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/2227556/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2227556/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-gpio+bounces-35434-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=Oe13W0hL;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-gpio+bounces-35434-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=\"Oe13W0hL\"","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\n [IPv6:2600:3c0a:e001:db::12fc:5321])\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 4g1rDN4HtJz1yHv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 08:21:56 +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 E1A43301D6B3\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 22:21:51 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id AFE3B33C507;\n\tThu, 23 Apr 2026 22:21:51 +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 2FB9B2D6407\n\tfor <linux-gpio@vger.kernel.org>; Thu, 23 Apr 2026 22:21:50 +0000 (UTC)","by mail-ot1-f43.google.com with SMTP id\n 46e09a7af769-7d55b97f358so4600678a34.3\n        for <linux-gpio@vger.kernel.org>;\n Thu, 23 Apr 2026 15:21:50 -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.48\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 23 Apr 2026 15:21:48 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776982911; cv=none;\n b=pEsuwmmvmlS+UsU5qP2I3vVsHf++ucAjrq2zAMYRlSqwqF3vB8bdeDYTHHNu1brSWkg/wGSeJ4YrIM1G4Oykxz4NlOfZi06MzvuCuk0uFo9z3Uqfzp8yfm/1Ik53oD3/DSPoAi2zI8mLR8oZGeTcAvdBlKVPRRdIzUhUzyOvevI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776982911; c=relaxed/simple;\n\tbh=eqvSFyfwY6bbgfeWS/g/PltErTOLHkYeQS0ydrF0CdM=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=XwwqkzE2UVISfLSQZqwnsDd+WvmtDeJmxB4+NYS0yLA13Lkr8DCDp11fIcqARzK+/HdAN31NpVYnHpstbfmMVtPBuEQuH5ytSnAkj75fTp3siwRvvN46gBAhtrHFrH+WMPc19+nZQ1GsiAuBze+mu6JRufovwwG5tt4XpREDE/E=","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=Oe13W0hL; 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=1776982909; x=1777587709;\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=AgUyaG7HDk70n5OPkaHwN9Mf4h1G9e5+i3TRPeCafQ8=;\n        b=Oe13W0hL84jYIrLNcKAobXP2xw+A9PWfDi/tq2a3M821ZT0HV+2N+7l45ncOjyOjzS\n         tLVV19Upin+5yWU732K0EtWejKXFR7dKFoXr1JBY/bhMdZex8Tcz2537HLMS/49EU5a2\n         lsrZ/lv0HPcVtwL3Z1iQK7xlgPi8nePAwpwAVfOuKDalutGx7jX8ZjTCufvM4WJEEHyi\n         ztwrxVl3zePpod4hOVVOEqSmW9LafaUoOcdZVUD+ML48B2hW58w6sKF+L6gmQqBaicHy\n         erOyOclbXJpdV3+kBR49Er55sOgia+XIPlO6SMNV6lbKtFfqNhmmeWD/InDIkD5Re97K\n         tKMw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776982909; x=1777587709;\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=AgUyaG7HDk70n5OPkaHwN9Mf4h1G9e5+i3TRPeCafQ8=;\n        b=nUYDhxfS8lYV11lalH1nMQzbf2Tmk9fA9xccnYMyBJY2sr9gAuolnfj+N19NbdLRGb\n         VDfX1duguwKvQPouDGadvpcMU6MQd2goBpnejEO9bRtfBoq91X9S4ySLBLaZq9RfP/MV\n         zUKjuSdeBNJIvSvbCbnTUvDti5MZvbrJqxvN9EIEVbJTf3lluLktMgwuLs49XQoREx/S\n         KOn1TyseXGiRX6m8/IY9rCxMAD1iXAq48ZQq7afyCcYsnWYdfe5OZqgfI5YQgk3UCXTB\n         iVkl9VUgR8prJ/WlcS30g09aUlZa8MZxiYWTa/KP5lyMvwy9e6Zr7t+yqy8g4O3Vp/hv\n         eVMA==","X-Gm-Message-State":"AOJu0Yz5JaE0BlnYDmEUfTk0lFMXieWU+iv9mpjZy6CNHLNrT1kAoTwa\n\t6HyljQ+WfvtVdS8csN/PQDQEm7ZGaheBH6vo2HqV/CH2irAh+VKJ9pMje31bGw==","X-Gm-Gg":"AeBDievz25olafu5T8aEMcjRLi4hyX3LTxqcOpjbMcwQCyiIQMUcWFOPqnY2xvXzpvn\n\tKkIfAv8SssJVCF0iuL3hbd85T5nRzeWxzoRDl2Vl0EE7zNFYmbVgCAgugec0n/qESoShVR3bcEH\n\tSkyVKK7x2LaZyhbnh38/cDz0VSaDJHh/I2zVUqIClomQynf7BRd2V/v90nzKWBQ09NveEjyXjOw\n\t6OG2MfCyOtr6iaYKobFuZFwmZ4LVJTvYAiCQ7CRdGuow0l5H9HrQn7IbS3n9ut/7B48EI3HMeix\n\tjlDioazwFV8A2wpCkxtailpop103C8rm172XvIM2SJrvNMUh6VTd5bLsvSpPvhpTJoKdZVbhrEU\n\tyefbcc2iN5MZzJgF2yirj5z0aN5Pvx8AmnVo9kmIp8wkhx4yqNTen8XhOT8J+Fvsy5/z0eiyoad\n\tg+JHaoMImjxQV+6jQTeGGFyS4cJ7Vdnm9moeXkrnGPxRpbrEJBtNxBvkXb5g3fU+bl07liAcnQ","X-Received":"by 2002:a05:6820:220d:b0:692:234a:e202 with SMTP id\n 006d021491bc7-69462f296dfmr16603245eaf.55.1776982908924;\n        Thu, 23 Apr 2026 15:21:48 -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 2/8] bindings: python: avoid PyObject_CallMethod\n during request finalize","Date":"Thu, 23 Apr 2026 17:21:19 -0500","Message-ID":"<20260423222125.29097-3-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":"The PyObject_CallMethod function jumps through hoops to find the method\nto call and to build a stack (if necessary) to call a given method.\n\nIn the case of finalizing the request object, that overhead can be\navoided by simply sharing a function with `request_release` to close the\nunderlying gpiod_line_request object.\n\nSigned-off-by: Vincent Fazio <vfazio@gmail.com>\n---\n bindings/python/gpiod/ext/request.c | 18 ++++++++++++------\n 1 file changed, 12 insertions(+), 6 deletions(-)","diff":"diff --git a/bindings/python/gpiod/ext/request.c b/bindings/python/gpiod/ext/request.c\nindex 9acf828..1e1f65a 100644\n--- a/bindings/python/gpiod/ext/request.c\n+++ b/bindings/python/gpiod/ext/request.c\n@@ -22,10 +22,19 @@ static int request_init(PyObject *Py_UNUSED(ignored0),\n \treturn -1;\n }\n \n+static void internal_request_release(request_object *self)\n+{\n+\tif (self->request){\n+\t\tPy_BEGIN_ALLOW_THREADS;\n+\t\tgpiod_line_request_release(self->request);\n+\t\tPy_END_ALLOW_THREADS;\n+\t\tself->request = NULL;\n+\t}\n+}\n+\n static void request_finalize(request_object *self)\n {\n-\tif (self->request)\n-\t\tPyObject_CallMethod((PyObject *)self, \"release\", \"\");\n+\tinternal_request_release(self);\n \n \tif (self->offsets)\n \t\tPyMem_Free(self->offsets);\n@@ -121,10 +130,7 @@ static PyGetSetDef request_getset[] = {\n static PyObject *\n request_release(request_object *self, PyObject *Py_UNUSED(ignored))\n {\n-\tPy_BEGIN_ALLOW_THREADS;\n-\tgpiod_line_request_release(self->request);\n-\tPy_END_ALLOW_THREADS;\n-\tself->request = NULL;\n+\tinternal_request_release(self);\n \n \tPy_RETURN_NONE;\n }\n","prefixes":["libgpiod","v2","2/8"]}