From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id waO9JOBX6mkVDzcAWB0awg (envelope-from ) for ; Thu, 23 Apr 2026 13:33:20 -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=hnKWG0nF; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=hnKWG0nF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8FD521E0BA; Thu, 23 Apr 2026 13:33:20 -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 4BC881E093 for ; Thu, 23 Apr 2026 13:33:19 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 03D7F4BAE7D8 for ; Thu, 23 Apr 2026 17:33:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03D7F4BAE7D8 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=hnKWG0nF; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=hnKWG0nF 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 6961D4BA9021 for ; Thu, 23 Apr 2026 17:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6961D4BA9021 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 6961D4BA9021 Authentication-Results: server2.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=1776965568; cv=pass; b=oxF9C9mACUCmQkwFaY1k/cOSFb7ZwNazhL6YqIqMz7ZdyL2c+dBPlEYwirZ2cUk+17RLn4qG7o5KNqdd39ouW61ZHzmuyP2SyaggyPMmAlPKKRoFJIUtj46lDGGWeZ67WChqxuewcfo1ow/wU/nn5mDEgNbz8faXjoxbyD4VNBE= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1776965568; c=relaxed/simple; bh=ggM43Mwi8RClTtzN4Vm+QHznpNvTpJHlHQwhYLeGMe0=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=D7n5noXpg/bYavM5H+xyjL6QHyHacXkEJJoAWvjcrx2YYMBQUCSE12ABrUHcBJhSP4nl/Xw5DeFee5aaMj8dvDy5B7aH0YlTaewQCXHlu0mSObTp2yYUg8IA779STLB5+HvbP8QCW3kGmMs+DrMwNeB1/LG0wyalWfBCRV0UosY= ARC-Authentication-Results: i=3; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6961D4BA9021 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=BLDMcXMr28fC4PJzXyJrPVpoayc04o7J5/Wa1dWhKgMmzKh+12K4HsKtZehrCpHrxaj/7WdkJA7K6flRNXqivP5HM77g0sfp3LpqluHIuiijwHG4ClkWsldlqWN0pfq9rqtIDyhsBC3K7vGzzDAN6VtzB5BjhK+WTFog1baghcdxVyCGy+lPwfGpzxksxCbbw3oGeqxPM2gEQqv5kA2yHJgnxktcA7kXNDzv0WHxSO75r9p1Q6S9FMwU9hrPM2nDAMoahj34+WEfpGOhw5ghXEQMMry0TcpKTre/SgHAirCDEQbzaPYLDOkMbf+4EUid717G2R8BOGOlsXn3ANzd7w== 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=XuJL8+UUmTZeXm+w6J8PlFBwB0dIx45QizeMhg0ZgIA=; b=ue9uXObGqdth0Ap9gLSpJ9EGMzY3xDn4VXjDkW/vBOj4PBXjZhxjqJpMVbgVFbNJImR7e8M1kCIU9txwVUL3dMP8QeuRs9EBAb/aF3eQ799mjs76+w9c5/N2hKGMaBEr4C6aCZ6rIy3Lg/f5Iwtg/QMdyvqEsSsW7IdvGOj8wnNOzZB6z7v2Gpwbr2PYV5aqJ/vHhAuavaNGLV98PWKtd9fvIvDO7jlm4Z4QyvKOTodHx02s9TfoTTAZXNVda447A4i2CXOzzEWkDfJKNxBqgMEQQzN0DaPtBSDXAYgm4VlQH3iM/APiQYk+j+PDVzbNIX/XqdI3UTYmQB0Qj01kBA== 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=XuJL8+UUmTZeXm+w6J8PlFBwB0dIx45QizeMhg0ZgIA=; b=hnKWG0nFmKMaYPD60t2hbzvZekn0/ABTCMIjikGdIBYm/4mD87kz2k6HCxa3acyhkI0vteJyXSk6bQan1AwVVY4RLT19fiPy00s8CTCh68kWbrJ7WHTmcZQQgT5jFW4G2nD9yB/6c3v6Kz1qj9v+Yt10wF2T4KsZEpmFnLC3FcE= Received: from AM5PR0301CA0033.eurprd03.prod.outlook.com (2603:10a6:206:14::46) by AM9PR08MB6689.eurprd08.prod.outlook.com (2603:10a6:20b:30f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.21; Thu, 23 Apr 2026 17:32:40 +0000 Received: from AMS0EPF0000019D.eurprd05.prod.outlook.com (2603:10a6:206:14:cafe::50) by AM5PR0301CA0033.outlook.office365.com (2603:10a6:206:14::46) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.21 via Frontend Transport; Thu, 23 Apr 2026 17:32:40 +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 AMS0EPF0000019D.mail.protection.outlook.com (10.167.16.249) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.18 via Frontend Transport; Thu, 23 Apr 2026 17:32:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EniAdiCxg4IFJFNWg8Ivnm7norknwlFeWmlskkq4qmUmT6TLe20ANh/qN9WbF+D0TYyeAiMNnjlCGO9CKwfcP7StIPxQvAHpL+lSIhuFhE3JI4Dyz5AQs9GoBnSVQnQhMfTbcLWQagUGy03umxo/4NBIudlDyoROA8WjaKT+9DQWKW94Qb6Yl21cJZwfhddDKM/JlUfiJS0C/hB4nwC5RACP5JRbAKRgha8xugMOrnrOwl8RRVhmNIo5Mo3oSL2BGZUcKxuanvbJc3bPTySIUGvG2RLgHx8psGJnq4mcpBlpcpHRGo/X71/ExH4W5xBljywFHyMo0fY+QU1ZxDOFfA== 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=XuJL8+UUmTZeXm+w6J8PlFBwB0dIx45QizeMhg0ZgIA=; b=mCHAAhIWJ3NZ6bS9R7eygCm81r40NXGaLHki7xf0pqXMOJtsVAINm0+dJMD9ZkvTC/jq8xesjHmahpZ3uzqgLGHj6xL7lxAZK2BauGcdElNdu7yW5M21z9WGZLLyKANlUt3jXOVq3nG262+L4SkGqr8wl2LIaAgvBBZytyhqew4Jj8HCF+WWuol0h6U0XDLmnaCQ7XRCp0PFFj25xibLKcOXMZBM7J+M0BErK36Pbaha+pCeUXCbWvkjQAK4NcL/Jx0RT1MWE/O3vKom5npBBejdiVqt/H0/Bep0jsQdq8stcnA9zZ3qYmQIgEw+iWbi8mQVf0wqH7LxvI1ClCg5Sw== 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=XuJL8+UUmTZeXm+w6J8PlFBwB0dIx45QizeMhg0ZgIA=; b=hnKWG0nFmKMaYPD60t2hbzvZekn0/ABTCMIjikGdIBYm/4mD87kz2k6HCxa3acyhkI0vteJyXSk6bQan1AwVVY4RLT19fiPy00s8CTCh68kWbrJ7WHTmcZQQgT5jFW4G2nD9yB/6c3v6Kz1qj9v+Yt10wF2T4KsZEpmFnLC3FcE= 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 FRZPR08MB11901.eurprd08.prod.outlook.com (2603:10a6:d10:1cb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.17; Thu, 23 Apr 2026 17:31:38 +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.20.9846.021; Thu, 23 Apr 2026 17:31:38 +0000 Message-ID: Date: Thu, 23 Apr 2026 18:31:36 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/4] gdb/python: add gdbpy_borrowed_ref To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20260409105155.1416274-1-matthieu.longo@arm.com> <20260409105155.1416274-2-matthieu.longo@arm.com> <87340ttx27.fsf@tromey.com> Content-Language: en-US From: Matthieu Longo In-Reply-To: <87340ttx27.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO0P265CA0013.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::8) To DU0PR08MB8663.eurprd08.prod.outlook.com (2603:10a6:10:401::6) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DU0PR08MB8663:EE_|FRZPR08MB11901:EE_|AMS0EPF0000019D:EE_|AM9PR08MB6689:EE_ X-MS-Office365-Filtering-Correlation-Id: 20b3afc1-d99a-4dba-e4a5-08dea15e51cc 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|376014|366016|18002099003|56012099003|18096099003|22082099003; X-Microsoft-Antispam-Message-Info-Original: XCMPbJAiPDhy0+rLJB5A2T9XPp5CFn/K+XDzjw5wjI8gDcYtHuJqCXduZK9fixOA0f2lmjJnIYGjxPvUHus2w156ukREmtAXRNCCPDz78y3MACGwBStbWedTtdNsO0YIjdyFOke+sAtn8tQpzK25q4JP50VTgjrYoL/3M1C7kKLCFZjIXmpk0vfaSCysrPGyE30JDRJw2IZOtTgcUOjusOMmFZmSnCr780Pv6fb/9mZ6txzhcTpwU4DTN0tUgblLL3UE1B8j/wR14p3xcw78JreSzFdY2K8RnaGCm8USBLdwKDKcOlZr1ow71tgHvcJoD5uAjuzxn/gFVy5r609K0Yaw8cjqTlLC7U2PBoUFRr+08E3oA4JEA/ja2BTH7QWZdnyDI/d4zm3vKf8CVcugSKq8B39d4IfforHn/++F14m/XmFSZoKEgd4Q8Fwmwd+M8Yroj/T9ibW0pbe/VpSmgwNK8QuoePIlyt5VaBKoGszmMcfTsW7Xk35fpcr2Ae3aw0LnL+diAXCQBFjBIgajHhEw7I6hl2GpKUfJZgxl07O194Ql7eFqW95JPynfFIa5ATQoJPW5LOkzAjiWTbePVj4JLRHCRouABdxxKz3vG7XEUPPodHW8QJDOPme7WzxMpPMEHfMLCZBKCn18e9rzJbQrFeGAmZnj3I9WiikXTjqVGotLPBDuQq2Cf8TwDeZqIS0eFnvTPewCZJ2DWCWoXIgGnvdZKeCp2xVl/lITAeg= 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)(376014)(366016)(18002099003)(56012099003)(18096099003)(22082099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: EuXSagPOomK9Ex1sqfAxRWJdXHZR0bFpBMFH+fBFTxQ1ZvtrdQbWSZ6jfb+6pMx1iz5FGNdTnicutFI3VqpSfnA+iiVoKaGa8MHKEO8a5SmuSdCcBBHkI4IWaGFCEK4A5lwygn9NoFUyWcWjpScsPGphd1O1j51TYicC0mAfHMhYfu34xAf4uOjGHbDBG5NkfXlwp7tGgd6PLhOGhSICF+KmipnxoV/FKIHg8DpYSbJTGu6AxEm83V9WdU6dvXOB2Q+uCUquyRUvQOCtNOOV3aMBU6n3R+/O2lIoNuLhXZb/YqeD6ll73pi1L0rCCxAIhv0efL7vbVGGDR/oi+HJRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: FRZPR08MB11901 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS0EPF0000019D.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1b106275-333f-4f19-9504-08dea15e2c8b X-Microsoft-Antispam: BCL:0; ARA:13230040|35042699022|14060799003|1800799024|82310400026|376014|36860700016|18096099003|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: bnyQL/eAnwoHlBkvJwd8XID6evdYprG571AJwXV/pXWlnBpzHaQ5I2swGb5wZ5TS0HCTdETkWDU1x2r4MOsY4lHwUyFhQAehmAXhxq1Hl9oqAROq/wSQOJavI8JQGYRpPKkVmoVFAx7ZF59HpCnwITxHU1NQLBp4M+5Bd/a1WI+lu8BPdR9WdsGKzSFcoJEgBJcgmtNp7ncHln+sbKERXHtPkZlrl8eXV3l/GqvmMT+vl2/gGzngHCEHL/tK704F8RRaHy9LsRRmbnmYbT4O6uU6L7qGu9/VnZuXw3RnM+Gmvqlw9NjC3Lcrn8VaShy3PhhSn4BX4OM8/tM8uIqaM70B5APSV14hBz4NAQ2oUL0WzDJuOUbk/kx8S27jaKxiHDunFki5yF0bu6g+tXQetrLazNO+GSpmE4Ayurp+cx3wveXidax4dKn/J0KmKoTe23wjJJ1an2EMri2AU5z7LlwduTupt8gxnygaryOLWPkOyttXwMgJLUw3LTQCW0PaU5fX57rnl/GtIEjyUg9r/wIWtYtICXzB0KtANo48D0bCmNLh/vDMqXhZZ1hCw3ovCK2ShsF2LM72wEMKfn4C2G0/17jJXBLddqv9ZpUnX6yN4xEyBDIrGV0kF9JUSbpSV44DWyLZP+Hvu9hB5UKQwZe+lpSzu/PVdYXqJaWz2xe6Ds5FRq2FVGV8UM0d3nw2EyLBTER+52sKVccOaCzvXhYHvblmNNm/TFnwRd9R6+6sdejt0bkvVX10L9aGPtZc2k9hRM/5LnFlZJP+RZ1ZCQ== 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)(35042699022)(14060799003)(1800799024)(82310400026)(376014)(36860700016)(18096099003)(18002099003)(22082099003)(56012099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5HqSkz9LKm0BAFaKqwGv5dAq0eGLKPSK7In5o4JeM0w6/sYl47R72Cku/2Yv1PndSOF0drFHij3Z03qmFEYpmcJ66PWofCcSOkZtTcFxq7e84cBlhaWZxZZS1gQ/Q4HIhvEyITYmSxRKKE8rmOE+QVYLS31UcYL0KogbE/Q7i5LrU33XFlZHtqGh64tKn+/LJHKnwC0wsxdaY83yAHPhRh5sFNfJy26pKnQVJnDriTaBHHLFVJlKwRbVNl4VRaHKg4+a1Z51YUqk7zuoSVxzB5ATlHRJ3OPaEdrkxQ0E0tsvDTBRCBEV+O2vewq01WLEQDq2o8Dkj6ztlcsjheloS0YLWmm+EvmptDAHRRSabLW4Z9SnYi9Vw73FZiJb7LDOjvCtOAjTyFTfS2gh0HWPpAbubqpfZU3aS+xbiZEt69j3C4KQ9Pk3aenWrAqhN2bn X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2026 17:32:40.4064 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 20b3afc1-d99a-4dba-e4a5-08dea15e51cc 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: AMS0EPF0000019D.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6689 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 17/04/2026 16:40, Tom Tromey wrote: >>>>>> Matthieu Longo writes: > >> 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. > > On my branch I ended up giving this a gdbpy_opt_borrowed_ref base class. > Is this branch public ? >> +/* 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 > > Also mine isn't templated like this though I guess this makes some > sense. > This templating is handy when you need to access fields from the subclass. > IIRC I felt like this was overkill. I didn't read your subsequent > patches yet but I assume there's some use for it. > For instance, : static PyObject * pyuw_create_unwind_info (gdbpy_borrowed_ref pyo_pending_frame, struct frame_id frame_id) { gdb_assert (pyo_pending_frame->frame_info != nullptr); gdbpy_heap_type_allocate_or_bailout (unwind_info_wrapper, unwind_info_object, unwind_info_object_type); unwind_info_wrapper->frame_id = frame_id; unwind_info_wrapper->pending_frame = pyo_pending_frame.strong_ref ().release (); unwind_info_wrapper->saved_regs = new std::vector; return unwind_info_wrapper.track ().release (); } >> + /* Allow a (checked) conversion to any subclass of PyObject. */ >> + template> + typename = std::is_convertible> >> + operator TObj * () >> + { >> + //gdb_assert (PyObject_TypeCheck (m_obj, T::corresponding_object_type)); > > No commented-out code. This is unsafe though. I would prefer a check. > > I think a name other than "TObj" would be good. > Even "U" would be better. "T" and "TObj" are too close. > I deleted this method, it was not needed. >> + /* When converting a borrowed reference to a gdbpy_ref<>, a new >> + reference is acquired. */ >> + template > + typename = std::is_convertible> >> + operator gdbpy_ref () >> + { >> + gdb_assert (m_obj != nullptr); >> + return gdbpy_ref::new_reference (m_obj); >> + } > > The naming thing here too. And also safety if we can get it. > Replaced TObj by U. /* When converting a borrowed reference to a gdbpy_ref<>, a new reference is acquired. */ template > operator gdbpy_ref () { if (m_obj != nullptr) return gdbpy_ref::new_reference (m_obj); return nullptr; } >> + >> + gdbpy_ref strong_ref () const noexcept >> + { >> + return static_cast> (*this); >> + } > > I think it would be clearer to directly write this in terms of > new_reference. /* Convert a borrowed reference to a strong one, i.e. gdbpy_ref<>. */ gdbpy_ref strong_ref () const noexcept { if (m_obj != nullptr) return gdbpy_ref::new_reference (m_obj); return nullptr; } > > Tom Here is the complete version with the modification. Matthieu /* 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; } operator T * () const noexcept { return m_obj; } /* Explicit version of the previous implicit cast operator. */ T *get () const noexcept { return m_obj; } /* When converting a borrowed reference to a gdbpy_ref<>, a new reference is acquired. */ template > operator gdbpy_ref () { if (m_obj != nullptr) return gdbpy_ref::new_reference (m_obj); return nullptr; } /* Convert a borrowed reference to a strong one, i.e. gdbpy_ref<>. */ gdbpy_ref strong_ref () const noexcept { if (m_obj != nullptr) return gdbpy_ref::new_reference (m_obj); return nullptr; } /* Let users refer to members of the underlying pointer. */ T *operator-> () const noexcept { return m_obj; } private: T *m_obj; };