From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 7wUqDdh4Qmovzh0AWB0awg (envelope-from ) for ; Mon, 29 Jun 2026 09:53:28 -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=rVdnU3xA; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=rVdnU3xA; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2427B1E098; Mon, 29 Jun 2026 09:53:28 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 ECDAA1E024 for ; Mon, 29 Jun 2026 09:53:25 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFDA34BA2E3F for ; Mon, 29 Jun 2026 13:53:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFDA34BA2E3F 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=rVdnU3xA; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=rVdnU3xA Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazlp170130007.outbound.protection.outlook.com [IPv6:2a01:111:f403:c20f::7]) by sourceware.org (Postfix) with ESMTPS id 628E34BA2E15 for ; Mon, 29 Jun 2026 13:52:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 628E34BA2E15 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 628E34BA2E15 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c20f::7 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1782741177; cv=pass; b=jnXdRzAqBP+uUV35hRpkPRfHzWmswFMKScyFYRxxhEy9s/E8F6xENSk4OBLGVYIHIkARn9AJlVDvx4t+R+LzAQ9ujN82pGaKSLwKPINWcIZN7XpifkkCnhBthHcqn718tsyYVyAEjwOxaIW1pSMSS1UffoM6pK3+l0aziE6aoXQ= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1782741177; c=relaxed/simple; bh=2lCHBFg0O2ooczQ1RRneJ99Zf318conurAKuYbqRfO4=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=iupvrd7UbWOfN19NGk/GFoSy/wHDbTFyTGSEIrdtaIV5WI7xSiAj7sU9FjKhIHTyHjDXNSl1cmLliTsF4emUWFDBtCjKFGJtawpLH8IBWagRHy0vnJJnM261fAd3NN/a3Vr9V8IxCsc29Ir141eR/N4vwfFgSnc78V649ucRL5s= ARC-Authentication-Results: i=3; 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=rVdnU3xA; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=rVdnU3xA DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 628E34BA2E15 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=U1HXXTB4khWrf6KakBjxSNMzv0ZxbJyeoGXGHfiK5ya4s0VvZovVP2YUNHgIk6C1VNthzXgqtGy7wLYL9G1mF0mDhBW7HR3pr3+DZiFq/oZAcyW4FYC0e/r3uqa/GA8fcI3z6SgCJoL5WbpStEcu5XeKixvcD03gywoe6R+9YNuy9Kq63RKXdXRo65aTiKGRV0SnwpoP+08rXrvYEOfVngw4i189unaKGChmo8yH1DRP/YjAKz+1iGveF/Lx/0QXCNtSE1WJjKwJpJES2i/QFVofGKI9EBizG8CS669AoLEAIFvbAwmMhYxHNgYgNFCYUpwFhBhZo8MXgw/ZO9lukw== 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=jfPK99rCaTh1uvbn3tEJ396pC1Ed3ciRIjyjr6jiKSM=; b=SYb9F8uFzmCqx5L1J6fmxpSXldpzWB6dmiAGTxz+rdflu125P9FKqGwgt+SND7aKsWXYUFBOM0CyezEUD0eKI3oHbwyU3XqLlYGH634ZVbKqb7Gyt4hvvZuqT5EwL6O7c7Onu0VFZGKHmTDwEQ8YLtLjjhWt3CYtMy+z/go93Zl4ULX+ebr8amkJV8AbAmEk7lfLRmlE7U0ucFhZt+BVtuB4DWer26bHQXC12spBC+t1FrTjZ7MijmbPkmWc2OUrRCHoYkc47cgNyZleZ8c2Uj3tPQ8M1gwvBqDBfqjNTrtdB+z7BzaSascgvteaI2EB+ComFXvRoL9MeKXDZuaXsA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=tromey.com 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] dkim=[1,1,header.d=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=jfPK99rCaTh1uvbn3tEJ396pC1Ed3ciRIjyjr6jiKSM=; b=rVdnU3xAqH0kCtRQm6RE3uV59hP4rCgV50Oj5svrZGNopGtpiJkWJcQZMBq8wSASUTuYyuV08LWIfIPeBrF2JN4brTz1YJTPKJlfiwGbwG60zPk4eCE495zm1vjtbOYeC8ofIAKu4e3WTtQh/wFWvn0FK5Bs1rL8NlTi/8vI8zY= Received: from AS4P190CA0026.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:5d0::13) by AM8PR08MB5587.eurprd08.prod.outlook.com (2603:10a6:20b:1dd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.19; Mon, 29 Jun 2026 13:52:48 +0000 Received: from AMS1EPF00000043.eurprd04.prod.outlook.com (2603:10a6:20b:5d0:cafe::66) by AS4P190CA0026.outlook.office365.com (2603:10a6:20b:5d0::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.159.19 via Frontend Transport; Mon, 29 Jun 2026 13:52:48 +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 AMS1EPF00000043.mail.protection.outlook.com (10.167.16.40) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Mon, 29 Jun 2026 13:52:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NPEUav69P4UMhtp4JVh1TFAdBqkCOP9a3lB7vC6M7vc+aK4wLV2iJuva1zXfwIEAstDk2DWpp2GU/0mtXDR9Q+HsnAs1L7TBp8b/1U7JR3f4QTf0674k0yEEkKumHxgMc6vRjh6aRb8BtlOsYvs/VbVag4Xa+Io2iIoXEvLrL6KCh0mBTTXk65SvPeSlzq3tw09yt81t7ivuiEzSd+W1IgDF2z9zhrE/z65+/WVUafaO5Bbzhl2zZJnwkserkjAab4PqQcavGXQEkI3V6S9/b/zI76UysBZ3tRnWyyF7eaaHHwsdSrifgr+hSZ4OuEmBzfE8YXAPI2fGSFAGUEcDKA== 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=jfPK99rCaTh1uvbn3tEJ396pC1Ed3ciRIjyjr6jiKSM=; b=uS/HQ2117jxb7gA4Wi/0fISDT5ygtDCD0/KXxJoe/9ws3Q1QTc/0dmuLlvbzpJvWsat39Fopvxc44CqBP9CTxOaVencoL4794MHOeys2O6h3qXtCgOrfe4PuuEQziu9Zg6yMByQ3SvDxS7yi17wEbiOS0gllqsc9HwT4E0CGRkshkWHQFWMTmM+e41YbHYSqYXl4o7IOoibxbAc5/qsiPFPlI6nhlcgnX5N1ekRuMfv8qgBNQEorI8nfO79uK7jFt7EgOKwUC3eeS0c3GYOEFKLONiG+lhVHV6v3BenzJQEf68tezY72L3Mt29GlT4wc2SoXGBe+B58Q3CoZiYl/eA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none 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=jfPK99rCaTh1uvbn3tEJ396pC1Ed3ciRIjyjr6jiKSM=; b=rVdnU3xAqH0kCtRQm6RE3uV59hP4rCgV50Oj5svrZGNopGtpiJkWJcQZMBq8wSASUTuYyuV08LWIfIPeBrF2JN4brTz1YJTPKJlfiwGbwG60zPk4eCE495zm1vjtbOYeC8ofIAKu4e3WTtQh/wFWvn0FK5Bs1rL8NlTi/8vI8zY= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DU0PR08MB8663.eurprd08.prod.outlook.com (2603:10a6:10:401::6) by GV1PR08MB8498.eurprd08.prod.outlook.com (2603:10a6:150:82::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.19; Mon, 29 Jun 2026 13:51:40 +0000 Received: from DU0PR08MB8663.eurprd08.prod.outlook.com ([fe80::f957:cec9:ec8d:7968]) by DU0PR08MB8663.eurprd08.prod.outlook.com ([fe80::f957:cec9:ec8d:7968%2]) with mapi id 15.21.0159.018; Mon, 29 Jun 2026 13:51:40 +0000 Message-ID: <16f2909b-c91c-42b4-9a12-7bba24f6949e@arm.com> Date: Mon, 29 Jun 2026 14:51:39 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/4] Add gdbpy_borrowed_ref To: Tom Tromey , gdb-patches@sourceware.org References: <20260521-python-safety-initial-v3-0-d0679c36e499@tromey.com> <20260521-python-safety-initial-v3-1-d0679c36e499@tromey.com> Content-Language: en-US From: Matthieu Longo In-Reply-To: <20260521-python-safety-initial-v3-1-d0679c36e499@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0188.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:311::17) To DU0PR08MB8663.eurprd08.prod.outlook.com (2603:10a6:10:401::6) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DU0PR08MB8663:EE_|GV1PR08MB8498:EE_|AMS1EPF00000043:EE_|AM8PR08MB5587:EE_ X-MS-Office365-Filtering-Correlation-Id: 70319f73-6958-4379-58d5-08ded5e5b408 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|1800799024|366016|376014|23010399003|6133799003|22082099003|18002099003|56012099006|4143699003|11063799006; X-Microsoft-Antispam-Message-Info-Original: CG/wmWoNIwkxut2gxrFR4v8NubbGu8J0U0z0FjmYmg6NaLzedXoVqY/ySgQ+dtY4JE2hqn7Ad3L1fCu/EcH8uEo6XvryI0SC6QMPm4AJ0yVwn+NRoujdjazl9jVcWbFd7rC2hU6VAk0ybZ/ZRXKQrOJ9DJE50HYP1CsBeqgZrHBMRuxsKxFBaokoI8/YY/uokxhoF8053tCDhYSSniyOoc2Fe/9s3QMgqU1OR9DLjYt+64Se9pASvdbcUu+pfOvShDF1zSoZQmg5l9/XrNQndy4JUXbl4ZENr3DK6sOg1MG0ALlbsUjDOhK9pxHM74hnWVAyAumKnO6PN98Bzd7KNBB2rEil/kuC8C0ULES0LZGNsAEaZmaprEddysjU5odLVDHhs6OqCRuXdyx/mQWANo3QkVJg3HrKL39q5LbvGgF8o5u+unkeStRgluIqpDubr3p1n+g/eB/S6u7plPzf/P1VUdJpp2J5rK4dbZECVsyybdI+Io3ngvOKh0QdEKCrBcoyQbY/ZyJTgEGRY7BrtexzE4nXmIKyyN1yLZJyBaHt7BFU5XlLHLi3dBtVV6g3HB+s/qghISbF+RcSGd7OY0FvIkSrwYzZYqtQOfwe7SE/8HdL8dF++96kgIzut6wKHwW9H5IwtIKDl67kXkRM/0f1MnSL/fJ7iRYq8OILh7U= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR08MB8663.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014)(23010399003)(6133799003)(22082099003)(18002099003)(56012099006)(4143699003)(11063799006); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: HcUOr/X9fS17pd8BS0u2ywz17NPE6acE34xSTwQFQ4Nx3h2KcDAfKw2YX/wkmSuG+z3IxSt0aVHQJX48+WhZyQiLUVmV3xU+Hi1xqxQp93G9b/7USnp9or5rnsLnJt2GZAAxQO7wFfyk/tpR5h82qgU48disTPo6u3SzDv4bmx58flknq0OUrUh4M2iEz0l2ya44dYgOoDudcoOp1/S/gRup8ze/nTMIKs0etMGUaI7PVzFLHpYENHy9WDOhl1Q6mNhLqCuWp2NKE7w95UAoeYsynTBtq1WWmLZwnkIYkUDSlLnHCYXbm69RGJFF0Lm9CwP6ao2KxeMl2ILNYIqHSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB8498 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS1EPF00000043.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c145a2f0-8655-4c00-ab9b-08ded5e58bf9 X-Microsoft-Antispam: BCL:0; ARA:13230040|14060799003|35042699022|36860700016|82310400026|1800799024|23010399003|376014|22082099003|18002099003|6133799003|11063799006|4143699003|56012099006; X-Microsoft-Antispam-Message-Info: 4nxA7V1PPlUQ2w54nN5r5MFE3fPjFoO2uI+Lv5PXti2f53TCZZhJQOnkXHJxte758lbY1uWits0nLIx2vrjr+bIp5DyCrkf07o8utBEJo++Pg9F4X50ZAoTTf3/VHU4qHolqo1mNrI9HLBb629SvzHeCAMK4zLx2kZBNHJOl9uyXcRF5XD9kFlWOBR1hSoKo9Kl8fwSsdsOz7cv3Vm1p9bau3m0ZRkHU/mboLlhjIU7uUJMFUlZecdPVmTEImZgWytv5HKEdUfpf0mviDEOYyeIZyTP2PreOw9DtHRRlGsXoGYmmNBq8KF+6YV+h+XcRcVHtC5zg0oPEBiTuPvSg5iSdrD0jtDk0QLvnnO7V9V2WOKiuE0YDT8nkGfZWUdmGptdVpATXZxALS2rYQLSvEjk79zjwObyJNSAWSvUIBOocXpvLo0l/e7AYzQC0wBj9VzTY0FCCeiJx8ijnEiHUK2ndkQ2UQrrsbHyLBtumfM5Dnacg90pecnnFHje7N/fgR/HGXGZb44/FUCfqe3lXTy4qoyXGbPt/RZ/B6IHHF6ZHBFEuiBLQit98FL5fN/xs78VLhdg3AzXJN8jy1PkmRij2TFBMnwrPPQRLCDR5FrzZViojQLPmLF8JKarWasjcZNKdBchpJP4J8Iut6HNQ7peT1FGuL2SQsemt+G3SMv8oK2IfBso1ph7CYnLGdmSVHest8gpKEvHH20DIeQR1Gw== 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)(14060799003)(35042699022)(36860700016)(82310400026)(1800799024)(23010399003)(376014)(22082099003)(18002099003)(6133799003)(11063799006)(4143699003)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xeqdFRjw67Sm87KekEPztLyFmDLXDthavHAf7JN8HZFq/xxugLicLdP93xKdPyhPE6oZMTAFaTYmll7UrrqWSHZLD1eUCShlxw6szLcLqAkBsPdHoT/Dii/98Hcjuo6n4yia6zPch+t2a+Isb1Nrk849gE4DhE1hDr47F4bJL+6FO8J0pidlHJ5K4bjNd+SDHJUWkUIzsHf1bxVa9y8AYCqh9FKOdqGL+anSjqS9FHlbOpt3dOQ7XpJoyEdfsrAQ0M+IT/e57E9fhXnD3QaXYgCtcerqfV8Y5QJxA5i9OAynctJjN4+gnSDsjAOod4RaJ9+rBRgR8J4vhIem3PAv6IxQJvnVn5vQ0ecbyP9gnCIGPwe8jH+ELl660RQ4zISh1Yk38ab4xtrVMcqAYvTANGs+ahTv8C7ieBZbP6jMSJijmYb8DkHUTfKBKClnfWOd X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2026 13:52:47.7498 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 70319f73-6958-4379-58d5-08ded5e5b408 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: AMS1EPF00000043.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5587 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 On 22/05/2026 00:27, Tom Tromey wrote: > This adds new gdbpy_opt_borrowed_ref and gdbpy_borrowed_ref classes. > These classes are primarily for code "documentation" purposes -- it > makes it clear to the reader that a given reference is borrowed. > However, they also add a tiny bit of safety, in that conversion to > gdbpy_ref<> will either be rejected (by the "opt" class) or acquire a > new reference. > --- > gdb/python/py-ref.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 86 insertions(+) > > diff --git a/gdb/python/py-ref.h b/gdb/python/py-ref.h > index 3d2906fd7f5..3d0373b7001 100644 > --- a/gdb/python/py-ref.h > +++ b/gdb/python/py-ref.h > @@ -21,6 +21,7 @@ > #define GDB_PYTHON_PY_REF_H > > #include "gdbsupport/gdb_ref_ptr.h" > +#include "gdbsupport/traits.h" > #include "python-traits.h" > > /* A policy class for gdb::ref_ptr for Python reference counting. */ > @@ -42,6 +43,91 @@ struct gdbpy_ref_policy > template using gdbpy_ref > = gdb::ref_ptr; > > +/* A class representing an optional borrowed reference. It is > + "optional" because NULL is a valid value. > + > + This is a simple wrapper for a pointer to PyObject or some subclass > + of it. Aside from documenting what the code does, the main > + advantage of using this is that conversion to a gdbpy_ref is > + prevented. > + > + An optional borrowed reference is only used in situations where > + Python says NULL is valid. For example, it is used as the type of > + the "keywords" argument to a varargs method. Most code should > + prefer an ordinary gdbpy_borrowed_ref, see below. */ > +template > +class gdbpy_opt_borrowed_ref > +{ > +public: > + > + gdbpy_opt_borrowed_ref (T *obj) > + : m_obj (obj) > + { > + } > + > + template > + gdbpy_opt_borrowed_ref (const gdbpy_ref &ref) > + : m_obj (ref.get ()) > + { > + } > + > + operator T * () const noexcept ? > + { > + return m_obj; > + } > + > + operator gdbpy_ref () = delete; Is there any possibility to add a bool operator to avoid "if (my_ref == nullptr)" ? Also, what about: - T *operator-> () const noexcept - T *get () const noexcept > + > +protected: > + > + T *m_obj; > +}; > + > +/* A borrowed reference that is guaranteed not to be NULL. > + > + Like gdbpy_opt_borrowed_ref, this mostly serves a documentary > + purpose. However, it also allows a checked cast to any subclass of > + T, and conversion to a gdbpy_ref will automatically acquire a > + new reference -- a safety improvement over plain PyObject * or the > + like. */ > +template > +class gdbpy_borrowed_ref : public gdbpy_opt_borrowed_ref > +{ > +public: > + > + gdbpy_borrowed_ref (T *obj) > + : gdbpy_opt_borrowed_ref (obj) > + { > + gdb_assert (this->m_obj != nullptr); > + } > + > + template > + gdbpy_borrowed_ref (const gdbpy_ref &ref) > + : gdbpy_opt_borrowed_ref (ref) > + { > + gdb_assert (this->m_obj != nullptr); > + } > + > + gdbpy_borrowed_ref (std::nullptr_t) = delete; > + > + /* Allow a (checked) conversion to any subclass of T. */ > + template + typename = gdb::Requires>> > + operator U * () const > + { > + gdb_assert (PyObject_TypeCheck (this->m_obj, > + U::corresponding_object_type)); > + return static_cast (this->m_obj); > + } > + > + /* When converting a borrowed reference to a gdbpy_ref<>, a new > + reference is acquired. */ > + operator gdbpy_ref () const > + { > + return gdbpy_ref::new_reference (this->m_obj); > + } > +}; > + > /* A wrapper class for Python extension objects that have a __dict__ attribute. > > Any Python C object extension needing __dict__ should inherit from this > Hi Tom, How can I help to make this patch be merged ? Are you waiting for inputs from others maintainers ? Matthieu