From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hHdQCqEkC2oZmwUAWB0awg (envelope-from ) for ; Mon, 18 May 2026 10:39:29 -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=j8UApmrr; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=j8UApmrr; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 189EF1E024; Mon, 18 May 2026 10:39:29 -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 16D281E024 for ; Mon, 18 May 2026 10:39:28 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB0674BAE7E9 for ; Mon, 18 May 2026 14:39:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB0674BAE7E9 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=j8UApmrr; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=j8UApmrr Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011070.outbound.protection.outlook.com [40.107.130.70]) by sourceware.org (Postfix) with ESMTPS id 64E8D4BB24D0 for ; Mon, 18 May 2026 14:38:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64E8D4BB24D0 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 64E8D4BB24D0 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=40.107.130.70 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1779115138; cv=pass; b=PDc2LcyBItKE5FhU91gRW2HsAQPbpfX+Or1g/Fe3uBKM6qSXhfSJu8/f7+qd8pEB7LubAIpkyUWl8ECHuIrUc0CjmS3+Hks3R2nJJALgNWbNoCW0r1eJnZB59nYG8AuNS4lyVROMrBDsffohJ1gQDUVcqWbG3PYBH/x3vhB9Vhs= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1779115138; c=relaxed/simple; bh=jbcrt1ehAUywHkOb34/m13LeF4b6eafjlt+EIsnEe28=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=KA9qWOme7a02DDuJkeqbL3sM/PhvPpFzGsKb0TKmxe+Y2M53zzj9zECdxJpRKHWvr0H/qpTbMKV1QnSEV3iKR6P3SlE6dJzZHFpweys5Dywehu4SFtvDtDW5YAU1U1Wc0ijumMrrdS0TU2rcuWcM4XlR3fIPEAUN/4tC8OHkKXA= 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=j8UApmrr; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=j8UApmrr DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64E8D4BB24D0 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=mL1kXYCsk8b+FpQF53gbemE6XAXyej6jqsq+C3z2fxxcn39ZI+ugWWCkc1SyXh/l8JPfVkoNMN+TcextAQISYKtXFo/k+UeoHh/tB2xo9i6S7aY7SdsPJ3yE/HfF9fGzEf8km790qWHoFngtwBtxU7sCJKeqrUJfj4wUFuFRt0ca6pTPYGdcrTdMZzAXhmGZud/rjAyhAeTHt4EW0QaGMIgnGRiZYHjo8BU/o9db8T/fU/KGmETWZRZVoB1raHpO8Sc19oR7gWg1nG6cXYiDdrNqEi0yRxGre7Uk5Fvmk+u6i1Yh3kN5y91uCa/pmIJXHC0EG9/O7oL6Q+yDDlDlpA== 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=RTqqHg9PT9aIe/5BuOVgYR9n0KKv9uARGdnVv+Qm+qo=; b=mTdUq4zbvkpcnATnFK0SzUkWfd0RkTZx8KIx/gjyJv99ainbS7GqeWd41O6Bzl4YI1zEtzW8Iaxfyca6VocioNXrwitiQ4kPMvuFoLa1VtUryOkeNHTUOGu1zJVlVCCQLzaJcf814Li50ePybO5pV1fbBFBsNMn3Ao22tuKICs02dsODRoPytTMmIX9bcoNXJP9ISSEIeyqVFGlNNrXSvk1fxw7rE8N9jLn2wifULRSMFUqkLPR6oVBzQGGm3byl93yI2E0mRLZes0qb7MDPrmdyZajMZvLieLu72jrVmaHq4wyYkxdOfowOV5+90mRZGftTGl8wzvnoWItJ3MYuNQ== 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=RTqqHg9PT9aIe/5BuOVgYR9n0KKv9uARGdnVv+Qm+qo=; b=j8UApmrrEDeUbRAMtvag17pXr3DqTOwOZrQv9/zWdAop8cMjOL+BiRZ9zTG1QO1JctxefTCbY+L24xIR97AiRF4wg2ClcityYS7HSBSpcHaCe7QJ9wY3etKWztahEofFXuTl7yK5LHcoSuiLVcrrSsrkgHcBuOtXdHOpeXlQdmw= Received: from DUZPR01CA0156.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bd::19) by PA1PR08MB11238.eurprd08.prod.outlook.com (2603:10a6:102:4df::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9913.12; Mon, 18 May 2026 14:38:41 +0000 Received: from DB1PEPF000509F2.eurprd02.prod.outlook.com (2603:10a6:10:4bd:cafe::4c) by DUZPR01CA0156.outlook.office365.com (2603:10a6:10:4bd::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.23 via Frontend Transport; Mon, 18 May 2026 14:38:41 +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 DB1PEPF000509F2.mail.protection.outlook.com (10.167.242.148) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 14:38:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oW7Nh0/UmfBH6xTOeZRQlNzs9TXr6q+Z/yGeP4hYP1azJJ5pi+5sUaDqvI9ISFd0hQa+QCwnEBpJXPEAX11wwhjNinTnBov8YJ74axM/kyRIr8Gl3KDpZDSKqBCuyJTThUefP7LKBwHplb8yQCINhjoD92GilWmLOwgW4gv2KEm5pAEbKRf8QWv7rqoewOHWFKgYoHL3pTNGAd21Atzn99jENMBRWAa6ixFSinW82hRjDwld+UhlMl4aYsECfmbH8H0Y5dm6T3H5HLyajq9LhfCFDPKhnl0cUyxDSvisRzymYtGwlfBXDk7Ojz1VpKpgv0XM2v3IM0/ijEzR2sDDLQ== 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=RTqqHg9PT9aIe/5BuOVgYR9n0KKv9uARGdnVv+Qm+qo=; b=ebhUONcR2IHeXDOjFaU13qBKneUm2aEtXxwy7yOzym5RlUtNXe9i4PX+xTyLdtTFDrx3pKCq80TWQcZqkpw+QivLnyPCfP2Uwlj0sW5So7EgcA60gbHT04XLe4ys1YYsUnudGEtRZ1FLV6wQiUpyaT0fket/SJhkxApN985AFcueAsIaOKaQduFs/woZb1gzCcWks1pkSbVBu+1FJp9lMEvSlqhrvcjlE3ELWvGVL5se9vcBwUe1Sq2tyxymawsgqQ7WFIqSskpDZc+m+RHltSKNH/0H0v0F43YGoAq2KyE4vWi0YjNuncMC8229n64LU+hV3R951i3D49f7vyUD6w== 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=RTqqHg9PT9aIe/5BuOVgYR9n0KKv9uARGdnVv+Qm+qo=; b=j8UApmrrEDeUbRAMtvag17pXr3DqTOwOZrQv9/zWdAop8cMjOL+BiRZ9zTG1QO1JctxefTCbY+L24xIR97AiRF4wg2ClcityYS7HSBSpcHaCe7QJ9wY3etKWztahEofFXuTl7yK5LHcoSuiLVcrrSsrkgHcBuOtXdHOpeXlQdmw= 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 AS8PR08MB8468.eurprd08.prod.outlook.com (2603:10a6:20b:566::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.23; Mon, 18 May 2026 14:37:37 +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.9913.009; Mon, 18 May 2026 14:37:36 +0000 Message-ID: Date: Mon, 18 May 2026 15:37:35 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/4] gdb/python: eval_python_command returns result of the evaluation To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20260428162416.511367-1-matthieu.longo@arm.com> <20260428162416.511367-3-matthieu.longo@arm.com> <87cxywipkx.fsf@tromey.com> Content-Language: en-US From: Matthieu Longo In-Reply-To: <87cxywipkx.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PA7P264CA0132.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:36e::13) To DU0PR08MB8663.eurprd08.prod.outlook.com (2603:10a6:10:401::6) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DU0PR08MB8663:EE_|AS8PR08MB8468:EE_|DB1PEPF000509F2:EE_|PA1PR08MB11238:EE_ X-MS-Office365-Filtering-Correlation-Id: 294e1fd3-bf56-4f90-cd49-08deb4eb2807 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|366016|376014|1800799024|4143699003|11063799003|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info-Original: IR6h+DomZjd91jfW+fSyaIONJaa17pfDRR1iL/B1hfXQ73KBCCXZ3q40N4YVl37PWtzaYT8TV6hPO719rE138UB/iFZpUgZn6ABGgv7KcWrNlpZUkzXIYBkT3halFI4OhIo6FSPNWmxLEFJRILwmDFZ2Lc8I0Xs04ke6Gl/kNrA6GwFmlPw1jFZvYtQgy42UR76RQ0sSdg1RdXf/2RpoLQBSUssw9qAdKAezZ+Bv5CBBVDeFaLKpcw2kMdxqdGpIYSyAM4fhSSB8A7VyklQN3ubehfxvOX5RVthNltpTh1dJCEFOavqmmW9eH+64vIVmLt9+UDK2guzjUnAl75D6doJyZv1K2sSbgpxfdwR8XYvAgiUh14MLnnCYmW3TktMBJHkyPZf7i/PhognEwE3B5xSN7uzj3z9EMvRCjl8tVFRG+/Wf8FK/cgIve/ytJcBEfIH/dcDXAe1Zutv9VYaMs429D8qk1KdG8hn3fzybneasL24t7ULnpeg9AXrSboP0HAA2NYdtUsCrStdcILenm+OFrwcLKjqZplw2jPuFRkjUce8qJFT2BuFWGLzc7oywtG2D7MhU2Tv3D105pE0y0XJMorEvxdSBXhxLkuf2FW57FtRoGyiPdiZHrQnyM3CiLUDnNBs/40/4VhgVuoJtiz0diVLSw9uNkpG2NoJqEQw9EqkGLTvENZ2A3v+C7lYU 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)(366016)(376014)(1800799024)(4143699003)(11063799003)(18002099003)(22082099003)(56012099003); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: KxlOR5sYFLSZxoSjwtdEK7dpxfS0Hyc5gokF+YFMiQXLlNM6qOTI1j00Z3lmbgu/mfYwdYmaXDNuPJjpSuGYkCN4R1KO15qDpppCjWQ2uG8G5uUuuq/eEh32vASMaleelZ11XaBZnIuMwEnhVXHI6FUlfTD6KwS//ET4evWHt1QwrjcYNSjkml454hzLpeYMhyVzC0GYbIbRDUWCtJe+5adA0jqy2PSzKXEQ/gjoCHV3UvO/2j4f7JpP+JL+8ILVPAAZCQhKGjlQKDU41yIX54q+vAOqge+19OjgLBqhniBZrrcv0YQrNk/AbquoJjKqgDsk6/LiZPjK+OQQ+9lfEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8468 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB1PEPF000509F2.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c7b324fe-1cb2-4fe2-f48c-08deb4eb014a X-Microsoft-Antispam: BCL:0; ARA:13230040|14060799003|35042699022|376014|82310400026|1800799024|36860700016|22082099003|18002099003|11063799003|56012099003|4143699003; X-Microsoft-Antispam-Message-Info: 2x3RWtXGAJQ/9u673JSxTDM64c9xjPx7+QUk6BhzI2slsjz5GuA81jMxszJAHCkM75B2yRfsNqh3/5kua94nHw3rPH1JSOZIMCBdyFi17IjXkak+FmwAtTHytKAh1M2X2jX7sFNoGBE+14anNb8NTBO96G6rjAMcIoLk9Cn5JH7JGthuH6/6XIFWAOwlYBR00rhY8rmqnGIOC/1jNk7czp84FaMh5joI0rCLNVLpBvcJtjBfBMDsa9EZyCKka0s2Km9+0wAiN75CGCSukYDhPBEbu3+ttnYyhJW6JfJ1AIheu9LHEaSVaOGKjbZXeYUf5NrCgPtsDJ0E7j4nYhemVxUDVm3uyF2Nhs8BauMZaokA3eWDnbLOk3JJ21KDjBWScKm9ADrdd5lhHNh0cXaW2juFDpM7dJlR5QTsqKVliXg6DQbPXljqy/B7E0RTSkPw491IIkV+/08RuF6K6Tcesj9aOacPcdBmnvA0UODTDYdbS0ITVMr5ySsk7Ibtoconw6IySt7MgjLBtO0/cF6CDZrodH4QDHmCv3ieXRe30UMd92G+x3Fr4yJo4wDMuCIGBz2VJFbbOEeL1gpqT9DaX3h8+ZMp3GlFn9/JPMbwUICDuFn5PBY/qkBVGmovSHK7GUw4eixso6Uhpzj5naY/kGkJYVzqsYYIbTUM7GM68nYNjuP7OOEdzutRZR7zzNwqhPmNrWS8NXEdww4NXvC2FA034HTsC4IcN8fYW3FGRJo= 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)(376014)(82310400026)(1800799024)(36860700016)(22082099003)(18002099003)(11063799003)(56012099003)(4143699003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /dHNybNmCkQAKzrBKqc15PSuSDYcOro5NqtRZeaoK+HDoUjBoZ7bYremGLMvJfCiW19g9LVMFN8fFg4kCVnyu/8NGo/Ri+MATHQdA+irL+N/v52C4i+aK3sy6TSfXRo4tCE1PCHtBQILS1NYwWl5JqJqXiEhCXpMfVKd+auVLqBZhDMddIhTC9YD1ubCEhh/zIThCdydf4KHMXSD3ymT5g9T8eUbijgfIgEtfrXag9mxOk/pb4yvpvHqbW2CXv0SUlWTtAOae1XYHur1vnDm6UaTDeA5uNq4+oV3m8+75Md7PlEz4pTjERADSRzHFsS7LlHQSkPZ0TALoT/CP6cXIzkJ6YEpYdmTSqi0YKUzbx1hKuNTLQ+ZjWdsqE4VCW5DZ2UAPvqpqqhfOiVKjWRfoiYcgmwz3eMAE8X2otv14/WDnxSF8qqOMfaSyK4E4CjO X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 14:38:41.4518 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 294e1fd3-bf56-4f90-cd49-08deb4eb2807 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: DB1PEPF000509F2.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR08MB11238 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 15/05/2026 17:51, Tom Tromey wrote: >>>>>> Matthieu Longo writes: > >> +++ b/gdbsupport/gdb_ref_ptr.h >> @@ -179,6 +179,11 @@ class ref_ptr >> return m_obj; >> } > >> + operator bool () const noexcept >> + { >> + return m_obj != nullptr; >> + } > > gdb is normally explicit instead, and since there aren't many call sites > I think this operator should be dropped and those spots updated to check > against nullptr. > > Tom Here is the updated diff. (1) if (eval_python_command (...) == nullptr) VS (2) if (! eval_python_command (...)) As you can see below, (1) is significantly more verbose than (2) and makes more difficult to respect the "80 characters per line" rule. Matthieu diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index e8e2c23547c..f3d87e0ae25 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -114,7 +114,7 @@ class GdbRemoveReadlineFinder(MetaPathFinder):\n\ \n\ sys.meta_path.insert(2, GdbRemoveReadlineFinder())\n\ "; - if (eval_python_command (code, Py_file_input) == 0) + if (eval_python_command (code, Py_file_input) != nullptr) PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper; return 0; diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 82f3262ae07..a26e33c33a1 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -1342,8 +1342,8 @@ class gdbpy_memoizing_registry_storage gdb::unordered_map m_objects; }; -extern int eval_python_command (const char *command, int start_symbol, - const char *filename = nullptr); +extern gdbpy_ref<> eval_python_command + (const char *command, int start_symbol, const char *filename = nullptr); /* The following four functions are refcount-safe wrappers around Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED}. */ diff --git a/gdb/python/python.c b/gdb/python/python.c index fd254a340d8..2b266a56759 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -298,44 +298,43 @@ gdbpy_check_quit_flag (const struct extension_language_defn *extlang) Python start symbol, and does not automatically print the stack on errors. FILENAME is used to set the file name in error messages; NULL means that this is evaluating a string, not the contents of a - file. */ + file. + Return the result of the evaluation on success, NULL on failure. */ -int +gdbpy_ref<> eval_python_command (const char *command, int start_symbol, const char *filename) { - PyObject *m, *d; - - m = PyImport_AddModule ("__main__"); - if (m == NULL) - return -1; + gdbpy_borrowed_ref<> mainmod = PyImport_AddModule ("__main__"); + if (mainmod == nullptr) + return nullptr; - d = PyModule_GetDict (m); - if (d == NULL) - return -1; + gdbpy_borrowed_ref<> globals = PyModule_GetDict (mainmod); + if (globals == nullptr) + return nullptr; bool file_set = false; if (filename != nullptr) { gdbpy_ref<> file = host_string_to_python_string ("__file__"); if (file == nullptr) - return -1; + return nullptr; /* PyDict_GetItemWithError returns a borrowed reference. */ - PyObject *found = PyDict_GetItemWithError (d, file.get ()); + PyObject *found = PyDict_GetItemWithError (globals, file.get ()); if (found == nullptr) { if (PyErr_Occurred ()) - return -1; + return nullptr; gdbpy_ref<> filename_obj = host_string_to_python_string (filename); if (filename_obj == nullptr) - return -1; + return nullptr; - if (PyDict_SetItem (d, file.get (), filename_obj.get ()) < 0) - return -1; - if (PyDict_SetItemString (d, "__cached__", Py_None) < 0) - return -1; + if (PyDict_SetItem (globals, file.get (), filename_obj.get ()) < 0) + return nullptr; + if (PyDict_SetItemString (globals, "__cached__", Py_None) < 0) + return nullptr; file_set = true; } @@ -348,12 +347,12 @@ eval_python_command (const char *command, int start_symbol, : filename, start_symbol)); - int result = -1; + gdbpy_ref<> eval_result; if (code != nullptr) { - gdbpy_ref<> eval_result (PyEval_EvalCode (code.get (), d, d)); - if (eval_result != nullptr) - result = 0; + eval_result.reset (PyEval_EvalCode (code.get (), globals, globals)); + if (eval_result == nullptr) + gdb_assert (PyErr_Occurred ()); } if (file_set) @@ -361,21 +360,21 @@ eval_python_command (const char *command, int start_symbol, /* If there's already an exception occurring, preserve it and restore it before returning from this function. */ std::optional save_error; - if (result < 0) + if (eval_result == nullptr) save_error.emplace (); /* CPython also just ignores errors here. These should be expected to be exceedingly rare anyway. */ - if (PyDict_DelItemString (d, "__file__") < 0) + if (PyDict_DelItemString (globals, "__file__") < 0) PyErr_Clear (); - if (PyDict_DelItemString (d, "__cached__") < 0) + if (PyDict_DelItemString (globals, "__cached__") < 0) PyErr_Clear (); if (save_error.has_value ()) save_error->restore (); } - return result; + return eval_result; } /* Implementation of the gdb "python-interactive" command. */ @@ -384,7 +383,7 @@ static void python_interactive_command (const char *arg, int from_tty) { struct ui *ui = current_ui; - int err; + bool err; scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); @@ -396,11 +395,11 @@ python_interactive_command (const char *arg, int from_tty) { std::string script = std::string (arg) + "\n"; /* Py_single_input causes the result to be displayed. */ - err = eval_python_command (script.c_str (), Py_single_input); + err = (eval_python_command (script.c_str (), Py_single_input) == nullptr); } else { - err = PyRun_InteractiveLoop (ui->instream, ""); + err = PyRun_InteractiveLoop (ui->instream, "") != 0; dont_repeat (); } @@ -411,6 +410,7 @@ python_interactive_command (const char *arg, int from_tty) /* Like PyRun_SimpleFile, but if there is an exception, it is not automatically displayed. FILE is the Python script to run named FILENAME. + Return true on success, false on failure. On Windows hosts few users would build Python themselves (this is no trivial task on this platform), and thus use binaries built by @@ -421,11 +421,11 @@ python_interactive_command (const char *arg, int from_tty) A FILE * from one runtime does not necessarily operate correctly in the other runtime. */ -static int +static bool python_run_simple_file (FILE *file, const char *filename) { std::string contents = read_remainder_of_file (file); - return eval_python_command (contents.c_str (), Py_file_input, filename); + return eval_python_command (contents.c_str (), Py_file_input, filename) != nullptr; } /* Given a command_line, return a command string suitable for passing @@ -459,8 +459,7 @@ gdbpy_eval_from_control_command (const struct extension_language_defn *extlang, gdbpy_enter enter_py; std::string script = compute_python_string (cmd->body_list_0.get ()); - int ret = eval_python_command (script.c_str (), Py_file_input); - if (ret != 0) + if (eval_python_command (script.c_str (), Py_file_input) == nullptr) gdbpy_handle_exception (); } @@ -476,8 +475,7 @@ python_command (const char *arg, int from_tty) arg = skip_spaces (arg); if (arg && *arg) { - int ret = eval_python_command (arg, Py_file_input); - if (ret != 0) + if (eval_python_command (arg, Py_file_input) == nullptr) gdbpy_handle_exception (); } else @@ -1120,8 +1118,7 @@ gdbpy_source_script (const struct extension_language_defn *extlang, FILE *file, const char *filename) { gdbpy_enter enter_py; - int result = python_run_simple_file (file, filename); - if (result != 0) + if (! python_run_simple_file (file, filename)) gdbpy_handle_exception (); } @@ -1827,8 +1824,7 @@ gdbpy_source_objfile_script (const struct extension_language_defn *extlang, scoped_restore restire_current_objfile = make_scoped_restore (&gdbpy_current_objfile, objfile); - int result = python_run_simple_file (file, filename); - if (result != 0) + if (! python_run_simple_file (file, filename)) gdbpy_print_stack (); } @@ -1850,8 +1846,7 @@ gdbpy_execute_objfile_script (const struct extension_language_defn *extlang, scoped_restore restire_current_objfile = make_scoped_restore (&gdbpy_current_objfile, objfile); - int ret = eval_python_command (script, Py_file_input); - if (ret != 0) + if (eval_python_command (script, Py_file_input) == nullptr) gdbpy_print_stack (); } diff --git a/gdb/varobj.c b/gdb/varobj.c index edd94ea4963..a8c991e50eb 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -1365,20 +1365,13 @@ void varobj_set_visualizer (struct varobj *var, const char *visualizer) { #if HAVE_PYTHON - PyObject *mainmod; - if (!gdb_python_initialized) return; gdbpy_enter_varobj enter_py (var); - mainmod = PyImport_AddModule ("__main__"); - gdbpy_ref<> globals - = gdbpy_ref<>::new_reference (PyModule_GetDict (mainmod)); - gdbpy_ref<> constructor (PyRun_String (visualizer, Py_eval_input, - globals.get (), globals.get ())); - - if (constructor == NULL) + auto constructor = eval_python_command (visualizer, Py_eval_input); + if (constructor == nullptr) { gdbpy_print_stack (); error (_("Could not evaluate visualizer expression: %s"), visualizer);