From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QcpDOcFzD2rqbA0AWB0awg (envelope-from ) for ; Thu, 21 May 2026 17:06:09 -0400 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=oa17n3xk; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E42561E091; Thu, 21 May 2026 17:06:09 -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.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 5125E1E024 for ; Thu, 21 May 2026 17:06:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0330948FE0BD for ; Thu, 21 May 2026 21:06:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0330948FE0BD 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=oa17n3xk Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id F41B34BA79A6 for ; Thu, 21 May 2026 21:05:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F41B34BA79A6 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 F41B34BA79A6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=35.89.44.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779397543; cv=none; b=IV/l88QQes6j3deSaa4JwMEO2oP7FmTpTH6kf8LyyXzCVrRSIRJpdoxBWKL2iwLLJs+G8fqg4RtLS9ZQu+FQgo2ORf0Ct4VYe7iNvSvimUSA++tAb1qdilLSIhSYOC0lpceINxFDJoNS+g4r2AIrkZrVzrqncllvxvoToPMcxr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779397543; c=relaxed/simple; bh=FWVwK+rzkKV/2kjtfC7NBRd4voC6iJw3VeqQzUDcoRk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NBRBIKgld+y5UItumpSqi6DZvUMqVyRRqHGxDUzPNRkSiteBNJGdGIxy/usSGqIHlXHszHsrFHl6KOwI4TmHSIZFPLIFN79FhjBd7GxoKVpJQIJH3y5WfsSfTfdzCpnelOD1Y6mOK8cvYZ5sq/2StmNNFTIbbSHyn1zNAeaEnXs= ARC-Authentication-Results: i=1; sourceware.org; dkim=policy (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=oa17n3xk reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F41B34BA79A6 Received: from eig-obgw-6004b.ext.cloudfilter.net ([10.0.30.210]) by cmsmtp with ESMTPS id QAUswdiFHMFEgQAaMwxwgX; Thu, 21 May 2026 21:05:42 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id QAaKwk5es7Q5NQAaLwSq1K; Thu, 21 May 2026 21:05:41 +0000 X-Authority-Analysis: v=2.4 cv=UIDdHDfy c=1 sm=1 tr=0 ts=6a0f73a5 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=NGcC8JguVDcA:10 a=ItBw4LHWJt0A:10 a=20KFwNOVAAAA:8 a=JrTrlp1lw67J6K6AE_0A:9 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=GFZDkOq4PMqqt9UCp1PT4MURPrMCes2qT7mFk0F1vHs=; b=oa17n3xksUI6IcCMH156+c4d1X Emq/tVzggQPmSZNt+JlfuVe85K/9aAs+wypBvEQ4viFlIxe8xLEkMyLsd/qxOPYh4781N6FrVPGjF NaXxUft7DgOcyNdDmTpZsXBqv; Received: from 75-166-225-82.hlrn.qwest.net ([75.166.225.82]:52496 helo=prentzel) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.99.2) (envelope-from ) id 1wQAaK-00000000UgJ-2fDM; Thu, 21 May 2026 15:05:40 -0600 From: Tom Tromey To: Andrew Burgess Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH v2 2/4] Add wrappers for some Python APIs In-Reply-To: <87a4tyckb5.fsf@redhat.com> (Andrew Burgess's message of "Sun, 17 May 2026 13:06:06 +0100") References: <20260515-python-safety-initial-v2-0-6129cadf258a@tromey.com> <20260515-python-safety-initial-v2-2-6129cadf258a@tromey.com> <87a4tyckb5.fsf@redhat.com> X-Attribution: Tom Date: Thu, 21 May 2026 15:05:38 -0600 Message-ID: <87fr3kjwwt.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: 75.166.225.82 X-Source-L: No X-Exim-ID: 1wQAaK-00000000UgJ-2fDM X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-225-82.hlrn.qwest.net (prentzel) [75.166.225.82]:52496 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfNgweHbR+c2xoyej6tWUAHJkxTfLtMAriN8rHnCNrT2s7FvSHxU8Xg6ZTl0ev9el3co6xDScuM2PZBNfKBwT+wiGivCXhNjtX+SQRlcNZCSXFo2Cdf/N 56kNo0R8rkNrQEcH/Mr/XIkgJnvMXHNoFpnBkWHe3X92c2lfMGPXFOz5ajBMs7ybAUKcCzxBltS4E6r0sWXJXJhkZM6car/kPXk= 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 >>>>> "Andrew" == Andrew Burgess writes: >> +static inline gdbpy_borrowed_ref >> +gdbpy_dict_get_item_with_error (gdbpy_borrowed_ref dict, >> + gdbpy_borrowed_ref key) >> +{ >> + PyObject *result = PyDict_GetItemWithError (dict, key); >> + if (result == nullptr) >> + throw gdb_python_exception (); >> + return result; Andrew> PyDict_GetItemWithError will return NULL *without* an exception set if Andrew> KEY is not found in DICT. This will then trigger an assert in the Andrew> gdb_python_exception constructor. Because of the *cough* lack of Andrew> comments, it's unclear what the function's intended behaviour is, but Andrew> this feels like a bug. Thanks for catching this, it is indeed a bug. I added small comments to most of the functions, and then expanded on them where I thought it made sense. In most cases I figured the big comment at the top of the file covers the details. I changed this particular function to return gdbpy_opt_borrowed_ref in the case where PyDict_GetItemWithError returns NULL without setting the exception. >> +static inline gdbpy_ref<> >> +gdbpy_unicode_from_format (const char *fmt, ...) >> +{ >> + va_list args; >> + va_start (args, fmt); >> + gdbpy_ref<> result (PyUnicode_FromFormatV (fmt, args)); >> + if (result == nullptr) >> + throw gdb_python_exception (); >> + va_end (args); Andrew> If an exception is thrown in this case then we fail to call va_end, Andrew> which I believe is technically undefined behaviour (though in reality Andrew> it's probably harmless), still, we should fix this. I used a template function here and elsewhere in this file. Note that this discovery means that many other uses of va_end in gdb are already wrong. >> +template >> +[[noreturn]] void >> +gdbpy_err_format (gdbpy_borrowed_ref type, const char *fmt, Arg... args) >> +{ >> + PyErr_Format (type, fmt, std::forward (args)...); Andrew> This isn't really a request for a change, more a question for my own Andrew> education. My understanding is that std::forward is intended to be used Andrew> with forwarding reference arguments, which ARGS is not. Yeah, I agree with your analysis. We don't need perfect forwarding here so I've removed the std::forward. Tom