From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0TLQLBukd2rfFhUAWB0awg (envelope-from ) for ; Sat, 08 Aug 2026 17:48:11 -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=JbFTkhcJ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B39EE1E166; Sat, 08 Aug 2026 17:48:11 -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.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,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 0A88F1E09E for ; Sat, 08 Aug 2026 17:48:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C9864BA901D for ; Sat, 8 Aug 2026 21:48:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C9864BA901D 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=JbFTkhcJ Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 3F60C4BA79AE for ; Sat, 8 Aug 2026 21:47:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F60C4BA79AE 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 3F60C4BA79AE Authentication-Results: sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786225651; cv=none; b=c7TsSh+lhxRxS/S3iP2+E7mLNV9SfaS86tkzg9w1MMZUW9hM8RZ9jqGMn28JLp6BsVLl/HjRoOwXxi6kgh5+5Hfw0ZN8FYBvj/Jqsg22dJZtsg5X8rfORis/XKGW1fAB60sERf/HZ7juDWlMDwJAR7BxJF7mL55SnsXM0EyDuYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786225651; c=relaxed/simple; bh=ELvTNNzsSt49SZaviXB+ndsSrDtbiO9dKQ0gNGtUEYI=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=L1rxkUQALjoyVICJmmuA9cYjKXnDL/pyIrBx1teeuZ++c8tMp9I6OAWQTT2NVnR+nwSY/nFni23noWC4m8WHjNulLabG4ZLJ8QgARoyeV/TchzZeiV/EDLxXzYQUJhjIZTpctua0tmQ8f1d415oPw9GJ49IfDEncyGjQ1q+ZDqA= 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=JbFTkhcJ reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F60C4BA79AE Received: from eig-obgw-6005b.ext.cloudfilter.net ([10.0.30.162]) by cmsmtp with ESMTPS id siWtw92yYaC0Usot7wF3jm; Sat, 08 Aug 2026 21:47:29 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id sot6ww7ipOYlBsot7wkTW6; Sat, 08 Aug 2026 21:47:29 +0000 X-Authority-Analysis: v=2.4 cv=FLYbx/os c=1 sm=1 tr=0 ts=6a77a3f1 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=ItBw4LHWJt0A:10 a=Qex0FYfmtZU7_Mn-g8MA:9 a=QEXdDO2ut3YA:10 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=C0dBgKFvAmaTSDyI4TAnWF4GZ5xxaJkeRbxIug/iyoE=; b=JbFTkhcJ47qOalPfsnFaCJYl1g dG0uYhXQ8qpvU8oKlyCslF1+38h7qbpWcGGDd9GuRWXR+rBaAuiUAZpiz8eDHdib7TquuaSyDIMy7 SI+aa8jPMsikgQ7cKPNJLFb1W; Received: from 75-166-225-82.hlrn.qwest.net ([75.166.225.82]:34168 helo=[192.168.122.1]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.99.5) (envelope-from ) id 1wsot6-00000001wX6-270M; Sat, 08 Aug 2026 15:47:28 -0600 From: Tom Tromey Date: Sat, 08 Aug 2026 15:47:26 -0600 Subject: [PATCH 2/4] Change evpy_add_attribute to accept gdbpy_borrowed_ref MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260808-python-safety-events-simple-v1-2-132aea40c801@tromey.com> References: <20260808-python-safety-events-simple-v1-0-132aea40c801@tromey.com> In-Reply-To: <20260808-python-safety-events-simple-v1-0-132aea40c801@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 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: 1wsot6-00000001wX6-270M X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-225-82.hlrn.qwest.net ([192.168.122.1]) [75.166.225.82]:34168 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfCcdUvie4dNCNCBJzoFCIKxVxE0e0mpC0l7+cbWR9xdvYgItMa9kBgbpfROXvsTs4rW4Vv9aLxf9LkIvIT1epV1TsV7y0xHgUKO6iOMGwtV8mBax27V+ r47oy2WavNVV9t/xGyzBltEoPy1szCYFQqKYEFUg9dLj5294ncwmuROWmWNDUNyQF1AvSjThdK11fKcaiBhTOB5mXkJqf/uF384= 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 This changes evpy_add_attribute to take gdbpy_borrowed_ref arguments. This allows removing various calls to "get". --- gdb/python/py-bpevent.c | 7 ++----- gdb/python/py-connection.c | 2 +- gdb/python/py-corefile.c | 3 +-- gdb/python/py-event.c | 3 ++- gdb/python/py-event.h | 4 ++-- gdb/python/py-exitedevent.c | 8 +++----- gdb/python/py-inferior.c | 12 +++++------- gdb/python/py-infevents.c | 12 ++++++------ gdb/python/py-newobjfileevent.c | 13 +++++-------- gdb/python/py-progspace.c | 9 +++------ gdb/python/py-signalevent.c | 5 ++--- gdb/python/py-stopevent.c | 2 +- gdb/python/py-threadevent.c | 4 +--- gdb/python/py-tui.c | 2 +- gdb/python/python.c | 2 +- 15 files changed, 36 insertions(+), 52 deletions(-) diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c index ae8e6e1594f..20a7745e4cc 100644 --- a/gdb/python/py-bpevent.c +++ b/gdb/python/py-bpevent.c @@ -32,12 +32,9 @@ create_breakpoint_event_object (const gdbpy_ref<> &dict, if (breakpoint_event_obj == NULL) return NULL; - if (evpy_add_attribute (breakpoint_event_obj.get (), - "breakpoint", - first_bp) < 0) + if (evpy_add_attribute (breakpoint_event_obj, "breakpoint", first_bp) < 0) return NULL; - if (evpy_add_attribute (breakpoint_event_obj.get (), - "breakpoints", + if (evpy_add_attribute (breakpoint_event_obj, "breakpoints", breakpoint_list) < 0) return NULL; diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c index 99bed238b6c..d2085960be4 100644 --- a/gdb/python/py-connection.c +++ b/gdb/python/py-connection.c @@ -143,7 +143,7 @@ emit_connection_event (process_stratum_target *target, return -1; gdbpy_ref<> conn = target_to_connection_object (target); - if (evpy_add_attribute (event_obj.get (), "connection", conn.get ()) < 0) + if (evpy_add_attribute (event_obj, "connection", conn) < 0) return -1; return evpy_emit_event (event_obj, registry); diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c index 542bc05f560..a1dee384edf 100644 --- a/gdb/python/py-corefile.c +++ b/gdb/python/py-corefile.c @@ -342,8 +342,7 @@ emit_corefile_changed_event (inferior *inf) gdbpy_ref inf_obj = inferior_to_inferior_object (inf); if (inf_obj == nullptr - || evpy_add_attribute (event_obj.get (), "inferior", - inf_obj.get ()) < 0) + || evpy_add_attribute (event_obj, "inferior", inf_obj) < 0) return -1; return evpy_emit_event (event_obj, gdb_py_events.corefile_changed); diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c index 6dd6f3bf356..815e815149c 100644 --- a/gdb/python/py-event.c +++ b/gdb/python/py-event.c @@ -45,7 +45,8 @@ create_event_object (PyTypeObject *py_type) function acquires a new reference to ATTR. */ int -evpy_add_attribute (PyObject *event, const char *name, PyObject *attr) +evpy_add_attribute (gdbpy_borrowed_ref<> event, const char *name, + gdbpy_borrowed_ref<> attr) { return PyObject_SetAttrString (event, name, attr); } diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index c8fbbf3add6..2c724c9a084 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -81,7 +81,7 @@ extern int emit_free_objfile_event (struct objfile *objfile); extern int emit_clear_objfiles_event (program_space *pspace); extern void evpy_dealloc (PyObject *self); -extern int evpy_add_attribute (PyObject *event, - const char *name, PyObject *attr); +extern int evpy_add_attribute (gdbpy_borrowed_ref<> event, + const char *name, gdbpy_borrowed_ref<> attr); #endif /* GDB_PYTHON_PY_EVENT_H */ diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c index 866adb7ff8b..83ccebb9127 100644 --- a/gdb/python/py-exitedevent.c +++ b/gdb/python/py-exitedevent.c @@ -33,15 +33,13 @@ create_exited_event_object (const LONGEST *exit_code, struct inferior *inf) if (exit_code_obj == NULL) return NULL; - if (evpy_add_attribute (exited_event.get (), "exit_code", - exit_code_obj.get ()) < 0) + if (evpy_add_attribute (exited_event, "exit_code", exit_code_obj) < 0) return NULL; } gdbpy_ref inf_obj = inferior_to_inferior_object (inf); - if (inf_obj == NULL || evpy_add_attribute (exited_event.get (), - "inferior", - (PyObject *) inf_obj.get ()) < 0) + if (inf_obj == nullptr + || evpy_add_attribute (exited_event, "inferior", inf_obj) < 0) return NULL; return exited_event; diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 5f0019b7b86..ab3a95da1bf 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -255,8 +255,7 @@ python_new_inferior (struct inferior *inf) gdbpy_ref<> event = create_event_object (&new_inferior_event_object_type); if (event == NULL - || evpy_add_attribute (event.get (), "inferior", - (PyObject *) inf_obj.get ()) < 0 + || evpy_add_attribute (event, "inferior", inf_obj) < 0 || evpy_emit_event (event, gdb_py_events.new_inferior) < 0) gdbpy_print_stack (); } @@ -283,8 +282,7 @@ python_inferior_deleted (struct inferior *inf) gdbpy_ref<> event = create_event_object (&inferior_deleted_event_object_type); if (event == NULL - || evpy_add_attribute (event.get (), "inferior", - (PyObject *) inf_obj.get ()) < 0 + || evpy_add_attribute (event, "inferior", inf_obj) < 0 || evpy_emit_event (event, gdb_py_events.inferior_deleted) < 0) gdbpy_print_stack (); } @@ -1037,9 +1035,9 @@ python_context_changed (user_selected_what selection) gdbpy_ref<> event = create_event_object (&selected_context_event_object_type); if (event == nullptr - || evpy_add_attribute (event.get (), "inferior", inf_obj.get ()) < 0 - || evpy_add_attribute (event.get (), "thread", thr_obj.get ()) < 0 - || evpy_add_attribute (event.get (), "frame", frame_obj.get ()) < 0 + || evpy_add_attribute (event, "inferior", inf_obj) < 0 + || evpy_add_attribute (event, "thread", thr_obj) < 0 + || evpy_add_attribute (event, "frame", frame_obj) < 0 || evpy_emit_event (event, gdb_py_events.selected_context) < 0) gdbpy_print_stack (); } diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c index db77f4593d6..b472c809197 100644 --- a/gdb/python/py-infevents.c +++ b/gdb/python/py-infevents.c @@ -44,14 +44,14 @@ create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid, if (ptid_obj == NULL) return NULL; - if (evpy_add_attribute (event.get (), "ptid", ptid_obj.get ()) < 0) + if (evpy_add_attribute (event, "ptid", ptid_obj) < 0) return NULL; gdbpy_ref<> addr_obj = gdb_py_object_from_ulongest (addr); if (addr_obj == NULL) return NULL; - if (evpy_add_attribute (event.get (), "address", addr_obj.get ()) < 0) + if (evpy_add_attribute (event, "address", addr_obj) < 0) return NULL; return event; @@ -72,14 +72,14 @@ create_register_changed_event_object (const frame_info_ptr &frame, if (frame_obj == NULL) return NULL; - if (evpy_add_attribute (event.get (), "frame", frame_obj.get ()) < 0) + if (evpy_add_attribute (event, "frame", frame_obj) < 0) return NULL; gdbpy_ref<> regnum_obj = gdb_py_object_from_longest (regnum); if (regnum_obj == NULL) return NULL; - if (evpy_add_attribute (event.get (), "regnum", regnum_obj.get ()) < 0) + if (evpy_add_attribute (event, "regnum", regnum_obj) < 0) return NULL; return event; @@ -100,14 +100,14 @@ create_memory_changed_event_object (CORE_ADDR addr, ssize_t len) if (addr_obj == NULL) return NULL; - if (evpy_add_attribute (event.get (), "address", addr_obj.get ()) < 0) + if (evpy_add_attribute (event, "address", addr_obj) < 0) return NULL; gdbpy_ref<> len_obj = gdb_py_object_from_longest (len); if (len_obj == NULL) return NULL; - if (evpy_add_attribute (event.get (), "length", len_obj.get ()) < 0) + if (evpy_add_attribute (event, "length", len_obj) < 0) return NULL; return event; diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c index e72e9ae67e3..cac49b2a39c 100644 --- a/gdb/python/py-newobjfileevent.c +++ b/gdb/python/py-newobjfileevent.c @@ -28,9 +28,8 @@ create_new_objfile_event_object (struct objfile *objfile) return NULL; gdbpy_ref<> py_objfile = objfile_to_objfile_object (objfile); - if (py_objfile == NULL || evpy_add_attribute (objfile_event.get (), - "new_objfile", - py_objfile.get ()) < 0) + if (py_objfile == nullptr + || evpy_add_attribute (objfile_event, "new_objfile", py_objfile) < 0) return NULL; return objfile_event; @@ -65,8 +64,7 @@ create_free_objfile_event_object (struct objfile *objfile) gdbpy_ref<> py_objfile = objfile_to_objfile_object (objfile); if (py_objfile == nullptr - || evpy_add_attribute (objfile_event.get (), "objfile", - py_objfile.get ()) < 0) + || evpy_add_attribute (objfile_event, "objfile", py_objfile) < 0) return nullptr; return objfile_event; @@ -100,9 +98,8 @@ create_clear_objfiles_event_object (program_space *pspace) return NULL; gdbpy_ref<> py_progspace = pspace_to_pspace_object (pspace); - if (py_progspace == NULL || evpy_add_attribute (objfile_event.get (), - "progspace", - py_progspace.get ()) < 0) + if (py_progspace == nullptr + || evpy_add_attribute (objfile_event, "progspace", py_progspace) < 0) return NULL; return objfile_event; diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 31ea3ad8fc8..a88535bdca9 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -638,14 +638,12 @@ emit_executable_changed_event (eventregistry_object *registry, gdbpy_ref<> py_pspace = pspace_to_pspace_object (pspace); if (py_pspace == nullptr - || evpy_add_attribute (event_obj.get (), "progspace", - py_pspace.get ()) < 0) + || evpy_add_attribute (event_obj, "progspace", py_pspace) < 0) return -1; gdbpy_ref<> py_reload_p (PyBool_FromLong (reload_p ? 1 : 0)); if (py_reload_p == nullptr - || evpy_add_attribute (event_obj.get (), "reload", - py_reload_p.get ()) < 0) + || evpy_add_attribute (event_obj, "reload", py_reload_p) < 0) return -1; return evpy_emit_event (event_obj, registry); @@ -706,8 +704,7 @@ gdbpy_program_space_event (program_space *pspace, bool adding_p) gdbpy_ref<> event = create_event_object (event_type); if (event == nullptr - || evpy_add_attribute (event.get (), "progspace", - pspace_obj.get ()) < 0 + || evpy_add_attribute (event, "progspace", pspace_obj) < 0 || evpy_emit_event (event, registry) < 0) gdbpy_print_stack (); } diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c index dc8639bb4d8..3be6ab31c6f 100644 --- a/gdb/python/py-signalevent.c +++ b/gdb/python/py-signalevent.c @@ -34,9 +34,8 @@ create_signal_event_object (const gdbpy_ref<> &dict, gdbpy_ref<> signal_name_obj (PyUnicode_FromString (signal_name)); if (signal_name_obj == NULL) return NULL; - if (evpy_add_attribute (signal_event_obj.get (), - "stop_signal", - signal_name_obj.get ()) < 0) + if (evpy_add_attribute (signal_event_obj, "stop_signal", + signal_name_obj) < 0) return NULL; return signal_event_obj; diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c index 77db754140c..3f07f8a29fb 100644 --- a/gdb/python/py-stopevent.c +++ b/gdb/python/py-stopevent.c @@ -32,7 +32,7 @@ create_stop_event_object (PyTypeObject *py_type, const gdbpy_ref<> &dict) if (result == nullptr) return nullptr; - if (evpy_add_attribute (result.get (), "details", dict.get ()) < 0) + if (evpy_add_attribute (result, "details", dict) < 0) return nullptr; return result; diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c index d2998d92304..9b0a963d0ba 100644 --- a/gdb/python/py-threadevent.c +++ b/gdb/python/py-threadevent.c @@ -45,9 +45,7 @@ create_thread_event_object (PyTypeObject *py_type, PyObject *thread) if (thread_event_obj == NULL) return NULL; - if (evpy_add_attribute (thread_event_obj.get (), - "inferior_thread", - thread) < 0) + if (evpy_add_attribute (thread_event_obj, "inferior_thread", thread) < 0) return NULL; return thread_event_obj; diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c index 0046c66d570..625de3bf87b 100644 --- a/gdb/python/py-tui.c +++ b/gdb/python/py-tui.c @@ -605,7 +605,7 @@ gdbpy_tui_enabled (bool state) } gdbpy_ref<> code (PyBool_FromLong (state)); - if (evpy_add_attribute (event_obj.get (), "enabled", code.get ()) < 0 + if (evpy_add_attribute (event_obj, "enabled", code) < 0 || evpy_emit_event (event_obj, gdb_py_events.tui_enabled) < 0) gdbpy_print_stack (); } diff --git a/gdb/python/python.c b/gdb/python/python.c index 5312cdbdb01..83923a2059c 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2500,7 +2500,7 @@ emit_exiting_event (int exit_code) return -1; gdbpy_ref<> code = gdb_py_object_from_longest (exit_code); - if (evpy_add_attribute (event_obj.get (), "exit_code", code.get ()) < 0) + if (evpy_add_attribute (event_obj, "exit_code", code) < 0) return -1; return evpy_emit_event (event_obj, gdb_py_events.gdb_exiting); -- 2.49.0