From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id zUJ0JdAMeWkPaBgAWB0awg (envelope-from ) for ; Tue, 27 Jan 2026 14:06:56 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=iCACXCFv; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8AAB51E08D; Tue, 27 Jan 2026 14:06:56 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id CE17C1E08D for ; Tue, 27 Jan 2026 14:06:55 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 2B6A24BA23F3 for ; Tue, 27 Jan 2026 19:06:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B6A24BA23F3 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=iCACXCFv Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id C7AF64BA2E2F for ; Tue, 27 Jan 2026 19:06:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7AF64BA2E2F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C7AF64BA2E2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769540787; cv=none; b=ZWSp+k3ADMpqvcF5cbZYAgpHwZrwb/3puhDV7YXdiujNQch7S5r+qrm1lzvPvJUNNwin4xebQcRGWc/gDWMUSGmvKxtpxTf5Toa8odJNmTAQiGE+4cXj5p23kWfPP1S9s4MkoYQPdHoCXN7OFQ6xp6GxrVynGARx5+G0BX4L1uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769540787; c=relaxed/simple; bh=JXMwWw+y07qh7ietSWiCs06xT7/IeKka+I/dIR/W3WI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pR1WrMxydCRJ9vERPXATeZAHbiA/D3/gzybtyvC7fz83Sdnhx5Ff+PibpafQa40PSMsgw9yyvFrUFYoUnAcdUI8s5Czh3ixt7gHbI71B3VjrZi0hOELUPVMy/w8MixUzy5y9K8y8NsI7pn1BBDH1NKbf2p/YKuLblwXNTOVw/U0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7AF64BA2E2F Received: from eig-obgw-6002b.ext.cloudfilter.net ([10.0.30.203]) by cmsmtp with ESMTPS id knDxvWQwzCxrGkoORvs9ij; Tue, 27 Jan 2026 19:06:27 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id koOQv51iOPL32koOQvgmwD; Tue, 27 Jan 2026 19:06:26 +0000 X-Authority-Analysis: v=2.4 cv=MqhS63ae c=1 sm=1 tr=0 ts=69790cb2 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=vUbySO9Y5rIA:10 a=ItBw4LHWJt0A:10 a=7CQSdrXTAAAA:8 a=uZJGHJeVYeGgBXeglkcA:9 a=a-qgeE7W1pNrGK8U0ZQC:22 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=eOBTyrKvZdPetL10p2nkxHRe2seXJ7im2VK/io4jBtY=; b=iCACXCFvqn5zvBp4rcoYR+MvwT FX8jVejkInX5eZaRT6cMCD06srGCpThSjzNhQc7iD20cspzb49GIJKL+M0+4dqhNzJ6rlftsm5wLX ORpWMKmw59HpFr5y7MKIUR/2I; Received: from 97-122-114-32.hlrn.qwest.net ([97.122.114.32]:49706 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vkoOQ-00000001Nra-1YcC; Tue, 27 Jan 2026 12:06:26 -0700 From: Tom Tromey To: Matthieu Longo Cc: , Tom Tromey Subject: Re: [PATCH v2 4/6] gdb: new setters and getters for __dict__, and attributes In-Reply-To: <20260127170215.1803582-5-matthieu.longo@arm.com> (Matthieu Longo's message of "Tue, 27 Jan 2026 17:02:13 +0000") References: <20260127170215.1803582-1-matthieu.longo@arm.com> <20260127170215.1803582-5-matthieu.longo@arm.com> X-Attribution: Tom Date: Tue, 27 Jan 2026 12:06:24 -0700 Message-ID: <878qdian9r.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.114.32 X-Source-L: No X-Exim-ID: 1vkoOQ-00000001Nra-1YcC X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-114-32.hlrn.qwest.net (bapiya) [97.122.114.32]:49706 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfMJO17O4usW14CZCkRch0vF9/zyz00fB0R0oljbs3XoJDv2PUZQ7WTSQL+3OT5QnNz4shnDC3iyejG8kzc8BCK2m0wt48RUcYr9KBODlsStenxxl2gFa RDAtS0xd4mDqXRYjQTakCLzsROcfaCOw0LXkDS50RcqQy9r370sehrEUTB+dMkXO2ucasP0nURCIJiYx7Aa1OH3eVVK9yLqQRLg= X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org >>>>> "Matthieu" == Matthieu Longo writes: Matthieu> GDB is currently using the Python unlimited API. Migrating the codebase Matthieu> to the Python limited API would have for benefit to make a GDB build Matthieu> artifacts compatible with older and newer versions of Python that they Matthieu> were built with. Matthieu> This patch prepares the ground for migrating the existing C extension Matthieu> types from static types to heap-allocated ones, by removing the Matthieu> dependency on tp_dictoffset, which is unavailable when using the limited Matthieu> API. Thanks. Matthieu> - gdbpy__dict__wrapper: a base class for C extension objects that own a Matthieu> __dict__. I think a double underscore in a name is reserved by the C++ implementation, so "gdbpy__dict__wrapper" can't be used. I think the same name with single underscores would be fine. Matthieu> - gdb_py_generic_dict_setter: a __dict__ setter provided for completeness. Matthieu> It should not be used, as __dict__ should be read-only after the object Matthieu> initialization. If it shouldn't be used, it should just not exist, I think. Matthieu> -using thread_map_t Matthieu> - = gdb::unordered_map>; Matthieu> - Matthieu> -struct inferior_object Matthieu> -{ Matthieu> - PyObject_HEAD This moved to python-internal.h, but I don't understand why that move is needed. Matthieu> + /* Compute the address of the __dict__ attribute for the given PyObject. Matthieu> + The CLOSURE argument is unused. */ Matthieu> + static PyObject ** Matthieu> + compute_addr (PyObject *self, void *closure ATTRIBUTE_UNUSED) In classes there doesn't have to be a newline before the method name. Also since the closure isn't used here it should probably just be dropped. If it's needed in the future we can add it then, but I'm going to guess it won't be. Matthieu> +/* Generic attribute getter function similar to PyObject_GenericGetAttr () but Matthieu> + that should be used when the object has a dictionary __dict__. */ Matthieu> +PyObject * Matthieu> +gdb_py_generic_getattro (PyObject *self, PyObject *attr) Matthieu> +{ Matthieu> + PyObject *value = PyObject_GenericGetAttr (self, attr); Matthieu> + if (value != nullptr) Matthieu> + return value; Matthieu> + Matthieu> + if (! PyErr_ExceptionMatches (PyExc_AttributeError)) Matthieu> + return nullptr; Matthieu> + Matthieu> + /* Clear previous AttributeError set by PyObject_GenericGetAttr. */ Matthieu> + PyErr_Clear(); Matthieu> + Matthieu> + gdbpy_ref<> dict (gdb_py_generic_dict_getter (self, nullptr)); Matthieu> + value = PyDict_GetItemWithError (dict.get (), attr); I think this has to do check 'dict == nullptr' before this call. Matthieu> + if (value != nullptr) Matthieu> + return Py_NewRef (value); Matthieu> + Matthieu> + PyErr_Format (PyExc_AttributeError, Matthieu> + "'%s' object has no attribute '%s'", Matthieu> + Py_TYPE (self)->tp_name, Matthieu> + PyUnicode_AsUTF8AndSize (attr, nullptr)); Matthieu> + return nullptr; PyDict_GetItemWithError sets the error, so is this just here to make a nicer message? That's fine if so, though I am not sure if you have to clear the existing error here first? Matthieu> + gdbpy_ref<> dict (gdb_py_generic_dict_getter (self, nullptr)); Matthieu> + /* Delete the old value (if there is one). */ Matthieu> + PyObject *old_value = PyDict_GetItem (dict.get (), attr); dict==nullptr check Matthieu> + if (old_value != nullptr) Matthieu> + Py_DECREF (old_value); Matthieu> + /* Set the new value. */ Matthieu> + return PyDict_SetItem (dict.get (), attr, value); I think this ordering means self-assignment can break. IMO it's better to use gdbpy_ref to manage the lifetime of the old value. Matthieu> +#if PY_VERSION_HEX < 0x030a0000 Matthieu> +static inline PyObject* Matthieu> +Py_NewRef (PyObject *obj) The return type is missing a space before the "*" Tom