get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2225991/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2225991,
    "url": "http://patchwork.ozlabs.org/api/patches/2225991/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260422012041.39933-10-vfazio@gmail.com/",
    "project": {
        "id": 42,
        "url": "http://patchwork.ozlabs.org/api/projects/42/?format=api",
        "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-10-vfazio@gmail.com>",
    "list_archive_url": null,
    "date": "2026-04-22T01:20:41",
    "name": "[libgpiod,9/9] bindings: python: tests: migrate the gpiosim module to multi-phase init",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "f62357c786a9b4c646e7cfc01e18781fdeca08e7",
    "submitter": {
        "id": 78694,
        "url": "http://patchwork.ozlabs.org/api/people/78694/?format=api",
        "name": "Vincent Fazio",
        "email": "vfazio@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260422012041.39933-10-vfazio@gmail.com/mbox/",
    "series": [
        {
            "id": 500906,
            "url": "http://patchwork.ozlabs.org/api/series/500906/?format=api",
            "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/2225991/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2225991/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "\n <linux-gpio+bounces-35330-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=O6fnmi97;\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-35330-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=\"O6fnmi97\"",
            "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.160.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 4g0hJv2d9Jz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:21:51 +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 C146F303D2F8\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 01:21:06 +0000 (UTC)",
            "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 9A0D02D5937;\n\tWed, 22 Apr 2026 01:21:06 +0000 (UTC)",
            "from mail-oa1-f43.google.com (mail-oa1-f43.google.com\n [209.85.160.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 011A317BED0\n\tfor <linux-gpio@vger.kernel.org>; Wed, 22 Apr 2026 01:21:04 +0000 (UTC)",
            "by mail-oa1-f43.google.com with SMTP id\n 586e51a60fabf-40f0e14b9f9so2860151fac.1\n        for <linux-gpio@vger.kernel.org>;\n Tue, 21 Apr 2026 18:21:04 -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.03\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 21 Apr 2026 18:21:03 -0700 (PDT)"
        ],
        "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776820866; cv=none;\n b=f/DRbYC2bRBa+wGzCSAWAQymqGMxbtZD+rvrIbzyHOuYLXcERxzliyxo+r4q/TD4Kav5uUMPSm7l+DOSKlUWnFwRzahDcW4DhmxJuhVuwupcoSXIXj+WKViO7ap+WRCH/9UY2bO+CtVoWXmL+xh5QGG6tEtLRSK2vbF4bqOh5ME=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776820866; c=relaxed/simple;\n\tbh=nDW3zQJrJEzfq2EQ1zRjT1Yq/XLcigrgez47P0cyZR0=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=ZbQe0cz5pMuSU3Gu/8D4tGWkVhwOBUkLSYWfSMz8sfIryIDiFltKx17z4NzpvmkZOe3I+vVSx6aisN6EHiBpuMLjUQ+aAG1sn4asLa1O76ENme4JfwC9RWW/YPYI2tInWJTagglve3qHfEkTEWs/V7XGuuGOc5C30ZxBqzGceaY=",
        "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=O6fnmi97; arc=none smtp.client-ip=209.85.160.43",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776820864; x=1777425664;\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=QLcmhIcwdWxUpVcuACLh1E0xbICxTuenu22WdCqYPJw=;\n        b=O6fnmi97Gx04eOUibtgJ/Yj8/oYn/9lpcuTOxcQxzxfpaEDEQMo2QPH0pZ9DSpgW6z\n         0FCDfDs0DG4TQq0fiye9UdLWg/y3tRwoy20MiS9cbd+0QBxh7OjKbUKStb0ixOYhSlqP\n         rROwmnNx16AbtDv1BhGstrwj3vWTchMBBCRRhJ6aVY6h0pLG7E4nz0DuYMHwF20/oCoY\n         39VcB0+uWp1PrNeZONv5y6OHLoalhpw62cUiu29/whis6RW4aCKpjxZ2aqDYKOeeV5ns\n         y8SK3nBxMl+qVWrJFQmB1pS1qI3PwoqEiJOX+F2OL7RVsVZv9uUESrfNlfTCf+8NUzGQ\n         9XGQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776820864; x=1777425664;\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=QLcmhIcwdWxUpVcuACLh1E0xbICxTuenu22WdCqYPJw=;\n        b=H3viibiQV0keIGeWg8fjaaWFnpNrDJcq5n8EAs5wLyohGK62fhCEVz2bx3LKHreXhO\n         VYxNQqTPt8qvbe2f8qRaAmd9w8ZfkuREjBtvpzW9ZlPy0cS44A/YVZCnfJ2l4qSnQtfz\n         sRJfSxhzgj2HmRzRaft38m8AOvsxz490sagHLi1gDlCoynYjDPuTzi+VenKlrvQgoogI\n         F6nCZdzcS8cSplMmmwD8Zl7kFgLbZJnuqhZ9xB9Mad0MUMeUqdkG3xmosGQVgja0fwXA\n         QyaP3fLs075FJo1NmU+yoy9GbIizJpr+k4a8YasbbHDqV+uqshCkSvVPLXbHMSyXyp4z\n         bdfQ==",
        "X-Gm-Message-State": "AOJu0YxZ0pQydSJX4K/eSBTrr8aRddvjgJHMuBSuVuXQLV8BoimNqwah\n\t457PanfRrsKgPfvLJ47aeWuFyk5cYdhAPvtu2Tz/2CpzqR7Y27CbJrkB0N89dQ==",
        "X-Gm-Gg": "AeBDiestkIRV0fvAvGsdx+L75NVm3x48myaF+4lKlYBaKOlVQZjngoiJz0fLglmZSDI\n\tDLwEVcZmAUg83kqPQTMUSBjZR41avsOtIOnPkWrtL8vjsw/czESNAa5e79v4rGlwxComttnnCAr\n\tqIJflCGxCIr4HfxFEfLBPGQJ649RlFfyWUZOuBlylveHfsIFMvmQwi/Na2brOBXWJyMx1mjff9p\n\ti3MMOP3fk7Nn4MNz4RNnxdRya2aWSyXugN69KoGVsHpYV2mfhAAwKo6YJU2Pt73mUK6L2GVOQcf\n\tLkWBpa5526bWryVPctkaboVEa4EWO6zwZEiSSXQOnTPPkfSAq2ne9yUaXm8Ozrx0OhHq3dQOujW\n\t4sq7OXCq5PQwhJH5NIsfIsHUKv/YiQ1CgRsrLNLrce1sc9unkr7FzHX1COsVVXFheLEcs8sN1rI\n\tI88WnN24gsBEDdnMqtm+AeFecLjNJ6cu8RSKkvaooq6+sNl+LeIwiwCS8MuREOX3SVeUAiDv4b",
        "X-Received": "by 2002:a4a:ee87:0:b0:67e:367c:998b with SMTP id\n 006d021491bc7-69462f2f144mr11010324eaf.59.1776820863717;\n        Tue, 21 Apr 2026 18:21:03 -0700 (PDT)",
        "From": "Vincent Fazio <vfazio@gmail.com>",
        "To": "linux-gpio@vger.kernel.org",
        "Cc": "Vincent Fazio <vfazio@gmail.com>",
        "Subject": "[libgpiod][PATCH 9/9] bindings: python: tests: migrate the gpiosim\n module to multi-phase init",
        "Date": "Tue, 21 Apr 2026 20:20:41 -0500",
        "Message-ID": "<20260422012041.39933-10-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\nSwitching requires converting `gpiosim.Chip` to be a heap-type [2] in\norder to access the module's state [3].\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[2]: https://docs.python.org/3/c-api/typeobj.html#heap-types\n[3]: https://docs.python.org/3/howto/isolating-extensions.html#heap-types\n\nSigned-off-by: Vincent Fazio <vfazio@gmail.com>\n---\n bindings/python/tests/gpiosim/ext.c | 151 +++++++++++++++++-----------\n 1 file changed, 94 insertions(+), 57 deletions(-)",
    "diff": "diff --git a/bindings/python/tests/gpiosim/ext.c b/bindings/python/tests/gpiosim/ext.c\nindex 1ebd5af..9954dd5 100644\n--- a/bindings/python/tests/gpiosim/ext.c\n+++ b/bindings/python/tests/gpiosim/ext.c\n@@ -45,21 +45,6 @@ struct module_state {\n \tstruct gpiosim_ctx *sim_ctx;\n };\n \n-static void free_module_state(void *mod)\n-{\n-\tstruct module_state *state = PyModule_GetState((PyObject *)mod);\n-\n-\tif (state->sim_ctx)\n-\t\tgpiosim_ctx_unref(state->sim_ctx);\n-}\n-\n-static PyModuleDef module_def = {\n-\tPyModuleDef_HEAD_INIT,\n-\t.m_name = \"gpiosim._ext\",\n-\t.m_size = sizeof(struct module_state),\n-\t.m_free = free_module_state,\n-};\n-\n typedef struct {\n \tPyObject_HEAD\n \tstruct gpiosim_dev *dev;\n@@ -71,13 +56,11 @@ static int chip_init(chip_object *self,\n \t\t     PyObject *Py_UNUSED(ignored1))\n {\n \tstruct module_state *state;\n-\tPyObject *mod;\n \n-\tmod = PyState_FindModule(&module_def);\n-\tif (!mod)\n-\t\treturn -1;\n+\tstate = PyType_GetModuleState(Py_TYPE(self));\n \n-\tstate = PyModule_GetState(mod);\n+\tif (!state)\n+\t\treturn -1;\n \n \tself->dev = gpiosim_dev_new(state->sim_ctx);\n \tif (!self->dev) {\n@@ -111,12 +94,14 @@ static void chip_finalize(chip_object *self)\n static void chip_dealloc(PyObject *self)\n {\n \tint ret;\n+\tPyTypeObject *tp = Py_TYPE(self);\n \n \tret = PyObject_CallFinalizerFromDealloc(self);\n \tif (ret < 0)\n \t\treturn;\n \n \tPyObject_Free(self);\n+\tPy_DECREF(tp);\n }\n \n static PyObject *chip_dev_path(chip_object *self, void *Py_UNUSED(ignored))\n@@ -289,58 +274,110 @@ static PyMethodDef chip_methods[] = {\n \t{ }\n };\n \n-static PyTypeObject chip_type = {\n-\tPyVarObject_HEAD_INIT(NULL, 0)\n-\t.tp_name = \"gpiosim.Chip\",\n-\t.tp_basicsize = sizeof(chip_object),\n-\t.tp_flags = Py_TPFLAGS_DEFAULT,\n-\t.tp_new = PyType_GenericNew,\n-\t.tp_init = (initproc)chip_init,\n-\t.tp_finalize = (destructor)chip_finalize,\n-\t.tp_dealloc = (destructor)chip_dealloc,\n-\t.tp_methods = chip_methods,\n-\t.tp_getset = chip_getset,\n+static PyType_Slot chip_type_slots[] = {\n+\t{Py_tp_new, PyType_GenericNew},\n+\t{Py_tp_init, (initproc)chip_init},\n+\t{Py_tp_finalize, (destructor)chip_finalize},\n+\t{Py_tp_dealloc, (destructor)chip_dealloc},\n+\t{Py_tp_methods, chip_methods},\n+\t{Py_tp_getset, chip_getset},\n+\t{0, 0}\n };\n \n-PyMODINIT_FUNC PyInit__ext(void)\n+/*\n+See xxlimited.c and _bz2module.c for inspiration.\n+\n+As part of transitioning to multi-phase module initialization, the\n+gpiosim.Chip type needs to become heap allocated so that it can access\n+module state.\n+\n+We disallow subclassing by not specifying Py_TPFLAGS_BASETYPE. This\n+allows the module to use PyType_GetModuleState() since it may otherwise\n+not return the proper module if a subclass is invoking the method.\n+\n+Note:\n+We do not hold PyObject references so no reference cycles should exist. As such,\n+we do not set Py_TPFLAGS_HAVE_GC nor define either tp_traverse or tp_clear.\n+\n+There is still some ongoing debate about this this use case however:\n+  https://github.com/python/cpython/issues/116946\n+\n+Note:\n+If we allow subclassing in the future, reconsider use of PyObject_Free vs using\n+the function defined in the tp_free slot.\n+\n+See also:\n+  https://github.com/python/cpython/pull/138329#issuecomment-3242079564\n+  https://github.com/python/cpython/issues/116946#issuecomment-3242135537\n+  https://github.com/python/cpython/pull/139073\n+  https://github.com/python/cpython/commit/ec689187957cc80af56b9a63251bbc295bafd781\n+*/\n+static PyType_Spec chip_type_spec = {\n+\t.name = \"gpiosim.Chip\",\n+\t.basicsize = sizeof(chip_object),\n+\t.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),\n+\t.slots = chip_type_slots,\n+};\n+\n+static int module_exec(PyObject *module)\n {\n \tconst struct module_const *modconst;\n \tstruct module_state *state;\n-\tPyObject *module;\n+\tPyObject *chip_type_obj;\n \tint ret;\n \n-\tmodule = PyModule_Create(&module_def);\n-\tif (!module)\n-\t\treturn NULL;\n-\n-\tret = PyState_AddModule(module, &module_def);\n-\tif (ret) {\n-\t\tPy_DECREF(module);\n-\t\treturn NULL;\n-\t}\n-\n \tstate = PyModule_GetState(module);\n \n \tstate->sim_ctx = gpiosim_ctx_new();\n \tif (!state->sim_ctx) {\n-\t\tPy_DECREF(module);\n-\t\treturn PyErr_SetFromErrno(PyExc_OSError);\n+\t\tPyErr_SetFromErrno(PyExc_OSError);\n+\t\treturn -1;\n \t}\n \n-\tret = PyModule_AddType(module, &chip_type);\n-\tif (ret) {\n-\t\tPy_DECREF(module);\n-\t\treturn NULL;\n-\t}\n+\tchip_type_obj = PyType_FromModuleAndSpec(module, &chip_type_spec, NULL);\n+\n+\tif (!chip_type_obj)\n+\t\treturn -1;\n+\n+\tret = PyModule_AddType(module, (PyTypeObject*)chip_type_obj);\n+\tPy_DECREF(chip_type_obj);\n+\tif (ret < 0)\n+\t\treturn -1;\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 0;\n+}\n+\n+static void free_module_state(void *mod)\n+{\n+\tstruct module_state *state = PyModule_GetState((PyObject *)mod);\n+\n+\tif (state->sim_ctx) {\n+\t\tgpiosim_ctx_unref(state->sim_ctx);\n+\t\tstate->sim_ctx = NULL;\n \t}\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 = \"gpiosim._ext\",\n+\t.m_size = sizeof(struct module_state),\n+\t.m_free = free_module_state,\n+\t.m_slots = module_slots,\n+};\n \n-\treturn module;\n+PyMODINIT_FUNC PyInit__ext(void)\n+{\n+\treturn PyModuleDef_Init(&module_def);\n }\n",
    "prefixes": [
        "libgpiod",
        "9/9"
    ]
}