From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id tDJGOBEWqGpmVwwAWB0awg (envelope-from ) for ; Mon, 14 Sep 2026 11:43:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1789400593; bh=dZeyad4s/k8RKpBei7dAScD3e3+jSZ1QzttRVjZCVmk=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EF/wSqzqpqb4EGpjh0r/cb/EESAIOJW+HWnGN/4vf/iLTIaeURxvy0DFsUado4WMq FgJ5+6hgbDleNyESdQEVhOJoY6ywyzCqo+M3AhADQkO9cav8308tfpLQt6roiISiCQ TeZLFvp04lu3SZxBaNihXi216hheLcZz9D0IqSck= Received: by simark.ca (Postfix, from userid 112) id D62491E01F; Mon, 14 Sep 2026 11:43:13 -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 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=jXX1XhIG; dkim-atps=neutral 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 4CF651E01F for ; Mon, 14 Sep 2026 11:43:13 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 161CE4B99F7E for ; Mon, 14 Sep 2026 15:43:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 161CE4B99F7E Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=jXX1XhIG Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 6E85F4B9DB5E for ; Mon, 14 Sep 2026 15:42:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E85F4B9DB5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6E85F4B9DB5E Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789400568; cv=none; b=tauXm8Wn9hqWfC8ZUmVnvLh0/hzQN0ogGJ2U1BSaoP0cElYIDZjeHaVsn3kIpXLrsM7cHMMWeM8Wm/j+hjyI21xdjWhOjs3rVsdBo/R0bSIaMHgZqlJbC7iZIX7BQWZalk+2krXWvhH4DFnw1p/3LtC9u2X0jhoSpfq2vabAGc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789400568; c=relaxed/simple; bh=dZeyad4s/k8RKpBei7dAScD3e3+jSZ1QzttRVjZCVmk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=teVsAlgs4EoSdziC2wYNqSs5BnWlxQHGsoIaDrvTHJjoAStEw4xLKTzftFoxKq45EQK8Z9yAF593cQc5yDLUp+EFEIK16gOsRpcAPSpUofom9i4LFqr2gq+z9kP179mZqk4hsHp0tj4yXa0slSs47LcMejnwgMBY3MUEh0bDA0A= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=jXX1XhIG DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E85F4B9DB5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1789400568; bh=dZeyad4s/k8RKpBei7dAScD3e3+jSZ1QzttRVjZCVmk=; h=Date:Subject:To:References:From:In-Reply-To:From; b=jXX1XhIGSC+t/48arTwuvRdP26hbsbIiXNoZrh5da3V1kS1XbEEA0OZEfFFTLgR9w F0/GR9w5f1D2cb6xeC4m7p5lTOOKe6qf8yKu/gIblTwM6+BKaGRLNPUzUMkaTb2u2b 42dKaGClt90D3LOVZPk5I11BTxjw+NhyzTTfiL2k= Received: by simark.ca (Postfix) id 0D8F61E01F; Mon, 14 Sep 2026 11:42:48 -0400 (EDT) Message-ID: <8c6dadb8-d305-4df8-b5ac-42c15a34b734@simark.ca> Date: Mon, 14 Sep 2026 11:42:47 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/4] Change evpy_emit_event to accept a gdbpy_opt_borrowed_ref To: Tom Tromey , gdb-patches@sourceware.org References: <20260808-python-safety-events-simple-v1-0-132aea40c801@tromey.com> <20260808-python-safety-events-simple-v1-1-132aea40c801@tromey.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20260808-python-safety-events-simple-v1-1-132aea40c801@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 8/8/26 5:47 PM, Tom Tromey wrote: > This changes evpy_emit_event to accept a gdbpy_opt_borrowed_ref. An > "opt" type is used because one caller explicitly passes NULL, meaning > that the event should be emitted without a payload object. > > This patch is a small step toward using the safety API in event > generation, though for the time being it mainly allows the removal of > calls to "get". > --- > gdb/python/py-breakpoint.c | 5 ++--- > gdb/python/py-connection.c | 2 +- > gdb/python/py-continueevent.c | 2 +- > gdb/python/py-corefile.c | 2 +- > gdb/python/py-event.c | 2 +- > gdb/python/py-event.h | 7 ++++++- > gdb/python/py-exitedevent.c | 2 +- > gdb/python/py-inferior.c | 8 ++++---- > gdb/python/py-infevents.c | 6 +++--- > gdb/python/py-newobjfileevent.c | 6 +++--- > gdb/python/py-progspace.c | 4 ++-- > gdb/python/py-stopevent.c | 2 +- > gdb/python/py-threadevent.c | 2 +- > gdb/python/py-tui.c | 2 +- > gdb/python/python.c | 2 +- > 15 files changed, 29 insertions(+), 25 deletions(-) > > diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c > index ecb42cee5f9..b628e14ae4e 100644 > --- a/gdb/python/py-breakpoint.c > +++ b/gdb/python/py-breakpoint.c > @@ -1283,8 +1283,7 @@ gdbpy_breakpoint_created (struct breakpoint *bp) > > if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_created)) > { > - if (evpy_emit_event ((PyObject *) newbp, > - gdb_py_events.breakpoint_created) < 0) > + if (evpy_emit_event (newbp, gdb_py_events.breakpoint_created) < 0) Unrelated, but those two if could be collapsed into one with &&. Also unrelated: I would change evregpy_no_listeners_p to evregpy_has_listeners_p, because double-negative is confusing. I can make following patches to change those. > gdbpy_print_stack (); > } > } > @@ -1312,7 +1311,7 @@ gdbpy_breakpoint_deleted (struct breakpoint *b) > > if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_deleted)) > { > - if (evpy_emit_event ((PyObject *) bp_obj.get (), > + if (evpy_emit_event (bp_obj, > gdb_py_events.breakpoint_deleted) < 0) > gdbpy_print_stack (); > } > diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c > index bc738669b79..99bed238b6c 100644 > --- a/gdb/python/py-connection.c > +++ b/gdb/python/py-connection.c > @@ -146,7 +146,7 @@ emit_connection_event (process_stratum_target *target, > if (evpy_add_attribute (event_obj.get (), "connection", conn.get ()) < 0) > return -1; > > - return evpy_emit_event (event_obj.get (), registry); > + return evpy_emit_event (event_obj, registry); > } > > /* Callback for the connection_removed observer. */ > diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c > index 15404157062..06d4dabadd9 100644 > --- a/gdb/python/py-continueevent.c > +++ b/gdb/python/py-continueevent.c > @@ -51,6 +51,6 @@ emit_continue_event (ptid_t ptid) > > gdbpy_ref<> event = create_continue_event_object (ptid); > if (event != NULL) > - return evpy_emit_event (event.get (), gdb_py_events.cont); > + return evpy_emit_event (event, gdb_py_events.cont); > return -1; > } > diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c > index fc5b4889fdc..542bc05f560 100644 > --- a/gdb/python/py-corefile.c > +++ b/gdb/python/py-corefile.c > @@ -346,7 +346,7 @@ emit_corefile_changed_event (inferior *inf) > inf_obj.get ()) < 0) > return -1; > > - return evpy_emit_event (event_obj.get (), gdb_py_events.corefile_changed); > + return evpy_emit_event (event_obj, gdb_py_events.corefile_changed); > } > > /* Callback from gdb::observers::core_file_changed. The core file for > diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c > index a7aa46dcb6f..6dd6f3bf356 100644 > --- a/gdb/python/py-event.c > +++ b/gdb/python/py-event.c > @@ -62,7 +62,7 @@ gdbpy_initialize_event () > returns 0 if emit is successful -1 otherwise. */ > > int > -evpy_emit_event (PyObject *event, > +evpy_emit_event (gdbpy_opt_borrowed_ref<> event, > eventregistry_object *registry) > { > Py_ssize_t i; Copying a review comment from Claude that seems important: - gdb/python/py-event.c:88: PyObject_CallFunctionObjArgs (func, event, NULL) — event is now a gdbpy_opt_borrowed_ref<> and sits in the ... of a true variadic C function. Variadic arguments get default argument promotions only; the user-defined operator T * is never applied, so the class object is passed, not a PyObject *. It compiles silently (reduced case, g++ -std=c++17 -Wall -Wextra: no diagnostic) and happens to work only because a trivially-copyable one-pointer struct is passed like a pointer on the usual ABIs. Introduce a local PyObject *ev = event; and pass that. Otherwise, it also noted: - gdb/python/py-breakpoint.c:1309 and :1340: both calls now fit on one line. Simon