{"id":2225985,"url":"http://patchwork.ozlabs.org/api/patches/2225985/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260422012041.39933-4-vfazio@gmail.com/","project":{"id":42,"url":"http://patchwork.ozlabs.org/api/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-4-vfazio@gmail.com>","list_archive_url":null,"date":"2026-04-22T01:20:35","name":"[libgpiod,3/9] 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/people/78694/?format=json","name":"Vincent Fazio","email":"vfazio@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20260422012041.39933-4-vfazio@gmail.com/mbox/","series":[{"id":500906,"url":"http://patchwork.ozlabs.org/api/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/2225985/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225985/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-gpio+bounces-35324-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=Laq8SqpB;\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-35324-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=\"Laq8SqpB\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.161.52","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 4g0hJj4DPNz1yHB\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:21:41 +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 05E89303A6CC\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 01:21:01 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id D9ACC258EF3;\n\tWed, 22 Apr 2026 01:21:00 +0000 (UTC)","from mail-oo1-f52.google.com (mail-oo1-f52.google.com\n [209.85.161.52])\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 6ACD217BED0\n\tfor <linux-gpio@vger.kernel.org>; Wed, 22 Apr 2026 01:20:59 +0000 (UTC)","by mail-oo1-f52.google.com with SMTP id\n 006d021491bc7-6949831a7bcso737496eaf.1\n        for <linux-gpio@vger.kernel.org>;\n Tue, 21 Apr 2026 18:20:59 -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.20.57\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 21 Apr 2026 18:20:57 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776820860; cv=none;\n b=p1BJua1U1kJZ30Q+t4sq0+OWQ2cQdY726IGvHdTaqCWp1cDjpLA8aQZi6PMa43lFrbs5bJvKeRQMn8n7ybzGkkbebLIaR2kzJ8UbWhOUy6QeKDGZ+PRuxIv1J86Zn+l2ABYOmj75WEYknAxiuJowzb7BoOTeu0zFE3zwRWoTkZI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776820860; 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=d+r1YKt5Gz5sTNEuHvowhwFIF7jfYiUEDAsk3rT8vN43mYb5C+y2THdLx5d0DEhwN5oKAITK/4s/c+AngGmGQQviKzhPUUVc+KuwRycR+OMObakmSR6lkKe2TnSe+3Nd0XqCowZMUKUOQBPSHN6w/M8J00QoZv9B3KkuyrJfDU4=","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=Laq8SqpB; arc=none smtp.client-ip=209.85.161.52","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776820858; x=1777425658;\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=Laq8SqpBLEXcv2qnLmpUexqadZ6oX8jAWQv/voi88oRiXBpGWcFU0v3ECoEzzn1jAY\n         4IFrhArn1mfJZjqOEmIaSXJIk6i51FtPmwRTGL9YZtjor6Tpy/9JttBXVsuhZ7vLUamu\n         wlP5f+uc6F2wB3uACvPcXw9bauc11AJ6UkUjTG/KyhEWeZ0hyXOEpXHdZ/znlhsD3fsV\n         vg5mEnkjWnx4wInr9jlXPs97N1Xnq/jF/1Mrjj5A5e/LOp2fqXZUs0v0MoPexJN6ZsvE\n         k7yhVOhyNIS6N1dn67yJq7dVisj2IzyTk+umc6vTB+90Bx/wKthZwCut3osSENYmelVD\n         9n5w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776820858; x=1777425658;\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=Zq7uyKNz+FT0Xcyv5Ch0sIqG6EzM6cZQJn85E/XpeHTo3daEMMi50eDaiYPPVVIhKz\n         aeFCHzNZ974oLspJiBTSqQGzcyCf56FeVMA9PQ8hj86YYQPHpv1UvOIMF+QjO+BqELvP\n         p0gA7szWxFNMYxg8SnhO6HhvExf57zYk60jvNwLyqUcbZQ2HwBD8dk+WCbuHnyPLu1dx\n         DdX7h0v8T1WLOudwkmEyBJzWQHo1fPuktJ5mBHSRFYTCVzjcsIewcN1R/DWNj2yY6QHY\n         ostgY9QKyuttihASKDwcAa17hJaZynurQxqb6iaobPuklHTUpKoCei04ZF0JLxAm6GhU\n         x8pg==","X-Gm-Message-State":"AOJu0Yw2AnbgA3fI9YdtcDSt+6B1lsqXZGYaPgi00wZlG6XLbgs4q3ag\n\tw83VRdVxOuapqHm6011gEaQeig/RVM1hePk7NdTNmdTvsOT9PmhG2LEjM2nGhA==","X-Gm-Gg":"AeBDieuNao6rlX93IvshG+nFANIIE/yQC/KBDMpwPo/f0n1Pla1V3cLPE+FN/zn4Gey\n\tJ4kmpaoMoC6enNT+rhS8sV1DuYFQYHQEgHuchC4ZXMQXBSv3jF7qNnp7Y2bka5qaTxgmndCKJca\n\tBZZKLls+KES2hiIpeSS4A2maPs6ZAjpaoi+wRTT4mI2peNgoyWIcrkcg5FqEUVLiyHRg7jKc1XC\n\tyTbkff6DBwDSxZd6zaitK9AjMoCSy1+CWe39uktT8ERWVaaMTO85+3FSrK5fCVkNpIcwluc+M0x\n\tQbmp9ZV9uA7RITqehSoubOIy8OPChZoi+D3B1PczavOO2+84JFaPwu5waS7a3jZ9gHs1ihNBWvP\n\tO99tP/xKkVrmqbjRYRl24+0yopiAsAtJafYzlLuVA6dOnXzdL4en0OmjQhrb6Kx1mx/mh848cv1\n\tDD5fQKsGn5DPRY7VEhXwcQHLl+nSs2cOmB4tM3FuSlSPXznsefNeTfGroYT4VT2yYqnOt163cD","X-Received":"by 2002:a05:6820:3098:b0:694:8e29:a920 with SMTP id\n 006d021491bc7-6948e29ac68mr4826381eaf.39.1776820858162;\n        Tue, 21 Apr 2026 18:20:58 -0700 (PDT)","From":"Vincent Fazio <vfazio@gmail.com>","To":"linux-gpio@vger.kernel.org","Cc":"Vincent Fazio <vfazio@gmail.com>","Subject":"[libgpiod][PATCH 3/9] bindings: python: avoid PyObject_CallMethod\n during request finalize","Date":"Tue, 21 Apr 2026 20:20:35 -0500","Message-ID":"<20260422012041.39933-4-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":"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","3/9"]}