From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eWhbHkiF12muzg4AWB0awg (envelope-from ) for ; Thu, 09 Apr 2026 06:54:00 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=YZuXUxjn; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=YZuXUxjn; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 765B41E0BC; Thu, 09 Apr 2026 06:54:00 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 CA3B41E08C for ; Thu, 09 Apr 2026 06:53:59 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 7A25D4BA2E1B for ; Thu, 9 Apr 2026 10:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A25D4BA2E1B Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=YZuXUxjn; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=YZuXUxjn Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11010070.outbound.protection.outlook.com [52.101.84.70]) by sourceware.org (Postfix) with ESMTPS id A74FA4BA2E06 for ; Thu, 9 Apr 2026 10:53:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A74FA4BA2E06 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A74FA4BA2E06 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=52.101.84.70 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1775732001; cv=pass; b=kG6R95A3QIODjpF+FLXt87pvgDlJPx/xZdz1DS6vTdRUylly7Qcj28qESeCJbyEOui+WJoZv4ilNWgdWg09Nez1q0QOCqxUQcFbZrluJDIUQlRcpdKCtiGkQRLmFQH5yv7MWCCBt4bkmx6D7p4I/uC746V3QgLW+kSd5IMUtx8w= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1775732001; c=relaxed/simple; bh=xNZQxajee7IBJvsCWRP2uMjihiz3TEjjilWJAKXP87E=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=H+WM928FtmHkU85vUawDS17XAMMHRTa3XiXGzC3/k0ig5rSHyG3M5yHEr0ck8uQi62DlDLgHk+nohP5L9d0A0pu3urQOO4AiJ62IOjht5wjBaP+DlfuNovpaoUF1UwUB+KOjzqcXaNUEG/hJ97DomCXmGBhn/MJ+0QpZI5+5Qnk= ARC-Authentication-Results: i=3; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A74FA4BA2E06 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=G+exhgSYUXvgrw2lSSqjH1wNENS96CE4QU407JUhR24fbNyoNqNTU5RXe5/lGHimjvz1QsfSxgQcBdTJBV3esnTrLIr4YR98d34HjVQR9iAJ24ePY+cdKe8bC1pO7B86L1k74JeZThgXsNKfrPQrLE4WRly/gPC/y2Axk5Wfrue0BymfGiofDyt2Y6xVOvZexstVaFU5Wc9HnrfjLEFyVgDxBm34xTqUkPQTamK4XccKWPF2OyxeJGgrBpN3lFUrKa5PNDfiEdImnEEYK39BhyafutaFto/mB9iF2TlgbkHPcvf19r/Aae0GOpo2Y+RuVFAtxcjyRgm5CNkf9XxYZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lXZlKj8soS3UY6veISt5MpDwe8aPwvolOQsJy3LRrY4=; b=ww4ZN1wnnqzAHKUfo+6OAeSa4pu47UlGAa3SvPVRPt8rHclm1OGDIt9YBcbBhuVd22JCifauoMsc93C8lYagE7UlPIGnHJf/3cWWTAxhWkeRsxvNTz0wEYYYr5ZpFTZIf1v81SeaZoeAS1nP/645S9ViXp4BVEO6Gdsgk0X53jAUFv+bOdl/ui02h1WWg4swZ+esgYC4ZDV/Cy51FWA6qsCe/C3d+nJ8PR+xmqzzM5Sz5dkA0z18sXKkMmjrRFotEAJJun3cY1ACCc3VcdhcvbzBqnhrMWsIuw6SRbrwQUMIEK0Qwsu4r5V+Q45Va7TXCyJdByclvOKETXnw/8tWhA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lXZlKj8soS3UY6veISt5MpDwe8aPwvolOQsJy3LRrY4=; b=YZuXUxjnLc2RfO50FcNfT/lP4YFQkuvvLCpAKXSoaRJXQntS6j/Nqax2ny1vLcqLZAVHln5sxsjiIEnkBfeBSOKBk9H0MeHL8sGOc4k3mepYEjGQt9B4FoQhiO/t43TxoQIudt3reQLM7lHvJCaRObRsOUDT62O3pW62JQN0fMo= Received: from DU7P189CA0023.EURP189.PROD.OUTLOOK.COM (2603:10a6:10:552::16) by PAXPR08MB7491.eurprd08.prod.outlook.com (2603:10a6:102:2b6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.27; Thu, 9 Apr 2026 10:53:13 +0000 Received: from DU6PEPF00009529.eurprd02.prod.outlook.com (2603:10a6:10:552:cafe::76) by DU7P189CA0023.outlook.office365.com (2603:10a6:10:552::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9769.37 via Frontend Transport; Thu, 9 Apr 2026 10:53:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 4.158.2.129) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 4.158.2.129 as permitted sender) receiver=protection.outlook.com; client-ip=4.158.2.129; helo=outbound-uk1.az.dlp.m.darktrace.com; pr=C Received: from outbound-uk1.az.dlp.m.darktrace.com (4.158.2.129) by DU6PEPF00009529.mail.protection.outlook.com (10.167.8.10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9769.17 via Frontend Transport; Thu, 9 Apr 2026 10:53:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZGEt61c9NaWwbkDYCLky4DYL1EIJc8d4N9L8acPj6yHu6wWLI04Of7Ma75wLWjtW4yp9lni4RwLzEmy0WYnyNayGZBoJwzm4KjgfOcsJypGiYUzlyl9p2TCmtVNm5ZDWNn4Jp8pjcwGzcMtXZlXZzFSFvn1zuFiLwUnjBnFdLgEhDU4xY5HNWk6Pzon/g36+quckx412nj/F+LTO7CiqkXnmnTUQbDzzmIRyPuvefUF9aSVKhyG1bIUpOyH5jPgS9/xMNC7ds4kRAM252T2bVnsCj6J9scMcXcZHDa0vm0Rk+Ro3WU5xhuyvzTigR94nb8A7WRSy93/1UdvXTvlAGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lXZlKj8soS3UY6veISt5MpDwe8aPwvolOQsJy3LRrY4=; b=yrVVxashC5MQ76Fnjk3LO17VZOq5V4fW82ZwJRX4jx85AXEa9hxZeW+DC/zor3JcIy8UAlkQ+mM0H3sivBtOSlrNXu4AEimJs01eg/A1PnVnmGEyEOuxLtiXdKl0Re2zyT1vpENkL4V8f/q/PI/ZWK0iZPbV5gtR/95NtnIrtvCSm0shH0K7W2rNBk6SVcVxbw45Io/fQlhJSKO8sAapWBmVdapALy/9rePGgg7+pfI5bXLQENpQSt73SnBE40BXOF1SymF8XZrOBP8SbguWZ2dnJ6QUKWystJKBQtN+qd5ZYQ7tAep+MvLe3u49QA7UAs/6YvbW7epDhkoNWvb1VQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 172.205.89.229) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lXZlKj8soS3UY6veISt5MpDwe8aPwvolOQsJy3LRrY4=; b=YZuXUxjnLc2RfO50FcNfT/lP4YFQkuvvLCpAKXSoaRJXQntS6j/Nqax2ny1vLcqLZAVHln5sxsjiIEnkBfeBSOKBk9H0MeHL8sGOc4k3mepYEjGQt9B4FoQhiO/t43TxoQIudt3reQLM7lHvJCaRObRsOUDT62O3pW62JQN0fMo= Received: from DU7P191CA0018.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:54e::11) by AS2PR08MB10324.eurprd08.prod.outlook.com (2603:10a6:20b:5e7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.15; Thu, 9 Apr 2026 10:52:09 +0000 Received: from DB1PEPF00039232.eurprd03.prod.outlook.com (2603:10a6:10:54e:cafe::bd) by DU7P191CA0018.outlook.office365.com (2603:10a6:10:54e::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9769.40 via Frontend Transport; Thu, 9 Apr 2026 10:52:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 172.205.89.229) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 172.205.89.229 as permitted sender) receiver=protection.outlook.com; client-ip=172.205.89.229; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (172.205.89.229) by DB1PEPF00039232.mail.protection.outlook.com (10.167.8.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.21 via Frontend Transport; Thu, 9 Apr 2026 10:52:09 +0000 Received: from AZ-NEU-EX04.Arm.com (10.240.25.138) by AZ-NEU-EX04.Arm.com (10.240.25.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Thu, 9 Apr 2026 10:52:08 +0000 Received: from PF4S4363.arm.com (10.1.34.63) by mail.arm.com (10.240.25.138) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Thu, 9 Apr 2026 10:52:08 +0000 From: Matthieu Longo To: , Tom Tromey Subject: [PATCH v1 1/4] gdb/python: add gdbpy_borrowed_ref Date: Thu, 9 Apr 2026 11:51:52 +0100 Message-ID: <20260409105155.1416274-2-matthieu.longo@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260409105155.1416274-1-matthieu.longo@arm.com> References: <20260409105155.1416274-1-matthieu.longo@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DB1PEPF00039232:EE_|AS2PR08MB10324:EE_|DU6PEPF00009529:EE_|PAXPR08MB7491:EE_ X-MS-Office365-Filtering-Correlation-Id: 7b6e559b-229a-4c90-3eb3-08de962632bd x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|82310400026|36860700016|1800799024|376014|18002099003|56012099003|22082099003; X-Microsoft-Antispam-Message-Info-Original: kEXU2ov27owCiUtTOyhcCS5eG/vdF3CAupuAS17zCcICiD4eJ59qvjPhEZHyLrIqyNij00zfYNrF1SbryNIYHPzFNH6PBJD2srsIJheImKbNufy2ETrvyI6D3Y8sTEMC5HWE2jJ+OlZ3iH3mxGC6ujA4VpOpa55MyTV5NAUEAzM2wuk1ai4ut9NKJjabAeL+KLqHlwZIwiZeK+yyBzAXMnLuMpmR0szvJ4KuGl2clKTmM7BCjL3YoxfR+NwcoIg+sr+xc9vigzdkanU1+fCpsdoqHvVccTWDLz0/110FExI/N+W3yKCLL50JU3Iw/N4RFARX3NhInpjWmMfDxuisErwEmg1qK3oGuy/GM+ixvw38pFahXutvQmbYs3GR9GgPz4vqxfkE5PMhJaM6h7JmViXBdqKRhG1n17ENaB9YXaeZlEORXa/2YWqlRPTGhoErbgax3uwEQOrsQoQwtEwKH5u2EdEyK8Jxz1SiLI5ZUtfafNoDN0491aH8lluWoZnfQKOxSLxFRYKcKmwlm4jKky0u4V1dUL4XR3MGsVOwF223W/qXmMrIO/hki40RlmhaTn8iJyzbCHS+S/BjxVRZtcWnZr8itKCN6v4ySC6x0vsNuI0k9GVoMnwuiaT1EVPhmBXm+yidziHgrR2SZbTPNanKAk++pWSaBy5Zd2aigHILarYPB5ntbTY9HTMNfTit/pvpwFtER5RqR+Shq+ohRnue00AkdHAFvMpZOYxZdRAjk0H1OcyXgrh7OZRz3BDD9MKoerVLOE4WYql/rV3KiQ== X-Forefront-Antispam-Report-Untrusted: CIP:172.205.89.229; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(36860700016)(1800799024)(376014)(18002099003)(56012099003)(22082099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: P3mx+yGIhJLQRr2++MIuKB4qVRrHTz1v0s5xmPDoOZNb9NeYGdPlwr6EJMUnSRWqva5AnixYbFdyCMLGfCs2QRDh3c6bKU/NrXDjoeT12Rs8kTTTuAkrHEj45Sp/h0fAvA/yD+rMTfNCRw6XiimhkwLs6AIYL+Gt4g4ZeLPqzUp2j6fHpGKopQOu9H2T3PiYeQewNJ/HsObBl3ddEuywEoMkdw6e7qLuXpaaWRLJTUBUktzgZBosz2H5znr4H1ZYAc7fD1X87i+uothBYnH99dDzMEc4Rij7T/NlrSfNa+pnQSpb5UT6cwC9euTourqZEaJyGa826CbEGZByM1bzXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB10324 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU6PEPF00009529.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 295c00e8-3b07-4a97-9b1a-08de96260c39 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|82310400026|35042699022|36860700016|14060799003|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: rhFsxgBYVrpafSJn2fCkayKWbtOCTarYzQHqJrD4h1ldDCqq9WHe7rNzYBjXJRxOdG6l71sJMD7EyaWhh9gd/KIALkxl4xlq1lSTIXqMvAsWfiOwXHyUnOkcH5IGMoRoSjTglmbAw9kZ69688gRWwwhbOkcbRiMPgOzCTm0GffgqpAo2fotl5uTkmZnrGd/aCorT5ZgFQv0GTkPnrDwav+rDFPFJSzglUag+ud7PE1hzz+eWsgGVPEl9zm9EoRjXSi+MZIY2zvU0KarSg8mAy7G+qKqLGQ10bgx4IdTrUHz/cDLyW7AY6tVLAUCcMoxMbOUGxdCVVp9FpnC3AJ9A9nAwn3Q0SOlQpUvXcUU+7XVwnFn06uYrO32HEyz0PH24CFn3pd+S7wBIMIu+a9M5p/AbWFUlM5nFw++uBIqLkeGbmEBHv5kY7oTQBSyMyUtTkgtOEVdkdmFBRE1JbE85Z/wiFCphcg/KeOIbnylvRipPRWwI7wNrU+BkMQ9WuVfj+lNHu/WAzbA0lA8S+RGv/JCfCf0R0l1KB5Zp27zpzk3LNrgD+5aS2hxLXEaFuY1YaiIc9BSnvxvm4vAHKQ1auJaapbAOSsoY0AekkfPUO5XpFI05RczN6XMskWWXJC9OTvyGsf6pBlOqofSLmYEXCfgUgh/JPLpn8abGV464kGGQzQraFZeIbMZdi3PV/wvUo1zPGmIZ9mBnu4bRw5ydY9sQaOJ0xcWrCqwzSagHiVInrgYE6JwXwMwJs8Hc4IWQKOcv4XhGQ2Z0s3lIQFua+A== X-Forefront-Antispam-Report: CIP:4.158.2.129; CTRY:GB; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:outbound-uk1.az.dlp.m.darktrace.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(376014)(82310400026)(35042699022)(36860700016)(14060799003)(22082099003)(18002099003)(56012099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3lTYOWqPN9KUKoUOfY4jGRG5Ix+6zEQOk95/fj+dzr0aSHde0wP9rg3x5KVqq/zogGsofOZK4SjiPQKhF803aJ9hRHSqAiWMMgmtFphQM4f0L47BXKEnt4OZEq1M638IkuNH2vo/YHznlsQt+Fgt5UxPy5Q8Qs5pQxqTP4NDjla/RD2GI07ZoCI7UIZe2k7HOKncO1bAR2Y7MtlMN2ZRLnkH3sbjvQHZfoVfMEWioueRnKz9Eg3I3pkPA0x0wGGNcG6HE1y+08kFoKh9UfZpt/He/hNDCW+1NkQ1fP3xC2GrabxnMLtRKBzUI0y9wfxTAEXDESjM/KzJSslB6DFUDcvMhbQiua3KLFWRA8fkuERx9Cn6kPWPE0Rf2M+NwM8/FtN3NOVAwD+okaXbg5L+bMfwvCh1iKAffx3bjA30n5O0VNHf0Na807i7s9DC1aIn X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2026 10:53:13.6853 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7b6e559b-229a-4c90-3eb3-08de962632bd X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[4.158.2.129]; Helo=[outbound-uk1.az.dlp.m.darktrace.com] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF00009529.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7491 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 From: Tom Tromey This adds a new gdbpy_borrowed_ref class. This class is primarily for code "documentation" purposes -- it makes it clear to the reader that a given reference is borrowed. However, it also adds a tiny bit of safety, in that conversion to gdbpy_ref<> will acquire a new reference. --- gdb/python/py-ref.h | 114 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/gdb/python/py-ref.h b/gdb/python/py-ref.h index dc0b14814af..80a08b55288 100644 --- a/gdb/python/py-ref.h +++ b/gdb/python/py-ref.h @@ -41,6 +41,120 @@ struct gdbpy_ref_policy template using gdbpy_ref = gdb::ref_ptr; +/* A class representing a borrowed reference. + + This is a simple wrapper for a PyObject*. Aside from documenting + what the code does, the main advantage of using this is that + conversion to a gdbpy_ref<> is guaranteed to make a new + reference. */ +template +class gdbpy_borrowed_ref +{ +public: + + gdbpy_borrowed_ref () noexcept + : m_obj (nullptr) + { + } + + gdbpy_borrowed_ref (const std::nullptr_t) noexcept + : m_obj (nullptr) + { + } + + template > + gdbpy_borrowed_ref (U *obj) noexcept + : m_obj (obj) + { + } + + template > + gdbpy_borrowed_ref (const gdbpy_ref &ref) noexcept + : m_obj (ref.get ()) + { + } + + gdbpy_borrowed_ref (const gdbpy_borrowed_ref &other) noexcept + : m_obj (other.m_obj) + { + } + + gdbpy_borrowed_ref &operator= (const gdbpy_borrowed_ref &other) + { + m_obj = other.m_obj; + return *this; + } + + /* Allow a (checked) conversion to any subclass of PyObject. */ + template> + operator TObj * () + { + //gdb_assert (PyObject_TypeCheck (m_obj, T::corresponding_object_type)); + return static_cast (m_obj); + } + + operator T * () const noexcept + { + return m_obj; + } + + /* When converting a borrowed reference to a gdbpy_ref<>, a new + reference is acquired. */ + template > + operator gdbpy_ref () + { + gdb_assert (m_obj != nullptr); + return gdbpy_ref::new_reference (m_obj); + } + + gdbpy_ref strong_ref () const noexcept + { + return static_cast> (*this); + } + + /* Let users refer to members of the underlying pointer. */ + T *operator-> () const noexcept + { + return m_obj; + } + + T *get () const noexcept + { + return m_obj; + } + +private: + T *m_obj; +}; + +template +inline bool operator== (const gdbpy_borrowed_ref &lhs, const std::nullptr_t) +{ + return lhs.get () == nullptr; +} + +template +inline bool operator!= (const gdbpy_borrowed_ref &lhs, const std::nullptr_t) +{ + return lhs.get () != nullptr; +} + +template +inline bool operator== (const std::nullptr_t, const gdbpy_borrowed_ref &rhs) +{ + return nullptr == rhs.get (); +} + +template +inline bool operator!= (const std::nullptr_t, const gdbpy_borrowed_ref &rhs) +{ + return nullptr != rhs.get (); +} + /* A wrapper class for Python extension objects that have a __dict__ attribute. Any Python C object extension needing __dict__ should inherit from this -- 2.53.0