From patchwork Sun Dec 31 20:25:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 83061 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 682C63858286 for ; Sun, 31 Dec 2023 20:26:44 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id C8A2A3858C2D for ; Sun, 31 Dec 2023 20:25:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8A2A3858C2D 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 C8A2A3858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704054343; cv=none; b=TbPFK8d3blcanLlAc821XYBDGZHlyfY51HWOLybl059FNePWqaq5P3sC+i6q+U2AzmsYJGJm+FFABe+7SVzwS+70r8t+DGZJBNm+RjJvqhq2QnsDORlCTqg+nCxmWeCBiZVwgTGqnXGdrqVoONpOcKNjpuU4fkQI2ZPI2QgndnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704054343; c=relaxed/simple; bh=P96JdGjGrgF3iZetiuoWM7BkF90kisLj0eFtEOOxZ8k=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=cqoRGfdVyifWrc/KhPCgp3bHyNj9d6XBkJaT/rO8NPK9khqPly89D1DgrJloEEybintTsSBF2POgpvS2zB6RRQK3cIANPrvFmZ8XHZdj8lgTunhlrE+ARzBe2aK8NI53n2b66CAVj14QL/zlkacTTdJp+TKpTXMXmxCkvgNrY5o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6010a.ext.cloudfilter.net ([10.0.30.248]) by cmsmtp with ESMTPS id JyEOrM3ABgpyEK2NQrpb0W; Sun, 31 Dec 2023 20:25:40 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id K2NPrT8uL8vT0K2NQrEycr; Sun, 31 Dec 2023 20:25:40 +0000 X-Authority-Analysis: v=2.4 cv=ffi+dmcF c=1 sm=1 tr=0 ts=6591ce44 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=e2cXIFwxEfEA:10 a=Qbun_eYptAEA:10 a=bcTQ-yR6QqYIScYaAiMA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc: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=rFi1jyf/2DgauDvTAiNZSgxUF5+nvady57fuNulHtKw=; b=ALLhCt3duQu2NMDCvIq63bfSs7 nFVFW+ZJz+TJH/oPGHeunlHDV5XGyjfVoIzOP/mNPkwVoBRPjw4jGD9Zkji/E5s4YBN4NQTPo7Xcv APmgDE8r2cguLQ4ZhbWr49O+2; Received: from 71-211-161-25.hlrn.qwest.net ([71.211.161.25]:45228 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rK2NP-002PSB-1v for gdb-patches@sourceware.org; Sun, 31 Dec 2023 13:25:39 -0700 From: Tom Tromey Date: Sun, 31 Dec 2023 13:25:39 -0700 Subject: [PATCH 2/6] Use vector in remote-fileio.c MIME-Version: 1.0 Message-Id: <20231231-remote-fileio-v1-2-249cc6c440d9@tromey.com> References: <20231231-remote-fileio-v1-0-249cc6c440d9@tromey.com> In-Reply-To: <20231231-remote-fileio-v1-0-249cc6c440d9@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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: 71.211.161.25 X-Source-L: No X-Exim-ID: 1rK2NP-002PSB-1v X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-161-25.hlrn.qwest.net ([192.168.0.21]) [71.211.161.25]:45228 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfEyGA75eYLAEx7NvC61Atr5C5KMLMEJ4r7KS+rt7x6BRPzQcSUkekBm+0/3GixDqR/rKhhu+Xl5p4K5NB1Xsps+JsH6ill6SIZR8L97AnIQ2jmJ9aOQq OV9twpcbtmKFvfxNZrcaWupNcTxpZwkVIEyHDw0NzjIspMaeOVM+U3aI1VW3345NHfzJ1ZhVGig/22l3qygbStQGzl25H41LkMc= X-Spam-Status: No, score=-3022.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org This changes remote_fio_data to be an object holding a vector. This simplifies the code somewhat. --- gdb/remote-fileio.c | 51 +++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index 367edb54f74..4891b0c5b92 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -37,9 +37,9 @@ #endif #include -static struct { - int *fd_map; - int fd_map_size; +static struct +{ + std::vector fd_map; } remote_fio_data; #define FIO_FD_INVALID -1 @@ -51,16 +51,13 @@ static int remote_fio_system_call_allowed = 0; static int remote_fileio_init_fd_map (void) { - int i; - - if (!remote_fio_data.fd_map) + if (remote_fio_data.fd_map.empty ()) { - remote_fio_data.fd_map = XNEWVEC (int, 10); - remote_fio_data.fd_map_size = 10; + remote_fio_data.fd_map.resize (10); remote_fio_data.fd_map[0] = FIO_FD_CONSOLE_IN; remote_fio_data.fd_map[1] = FIO_FD_CONSOLE_OUT; remote_fio_data.fd_map[2] = FIO_FD_CONSOLE_OUT; - for (i = 3; i < 10; ++i) + for (int i = 3; i < 10; ++i) remote_fio_data.fd_map[i] = FIO_FD_INVALID; } return 3; @@ -69,25 +66,20 @@ remote_fileio_init_fd_map (void) static int remote_fileio_resize_fd_map (void) { - int i = remote_fio_data.fd_map_size; - - if (!remote_fio_data.fd_map) + if (remote_fio_data.fd_map.empty ()) return remote_fileio_init_fd_map (); - remote_fio_data.fd_map_size += 10; - remote_fio_data.fd_map = - (int *) xrealloc (remote_fio_data.fd_map, - remote_fio_data.fd_map_size * sizeof (int)); - for (; i < remote_fio_data.fd_map_size; i++) + + int i = remote_fio_data.fd_map.size (); + remote_fio_data.fd_map.resize (i + 10); + for (; i < remote_fio_data.fd_map.size (); i++) remote_fio_data.fd_map[i] = FIO_FD_INVALID; - return remote_fio_data.fd_map_size - 10; + return remote_fio_data.fd_map.size () - 10; } static int remote_fileio_next_free_fd (void) { - int i; - - for (i = 0; i < remote_fio_data.fd_map_size; ++i) + for (int i = 0; i < remote_fio_data.fd_map.size (); ++i) if (remote_fio_data.fd_map[i] == FIO_FD_INVALID) return i; return remote_fileio_resize_fd_map (); @@ -106,7 +98,7 @@ static int remote_fileio_map_fd (int target_fd) { remote_fileio_init_fd_map (); - if (target_fd < 0 || target_fd >= remote_fio_data.fd_map_size) + if (target_fd < 0 || target_fd >= remote_fio_data.fd_map.size ()) return FIO_FD_INVALID; return remote_fio_data.fd_map[target_fd]; } @@ -115,7 +107,7 @@ static void remote_fileio_close_target_fd (int target_fd) { remote_fileio_init_fd_map (); - if (target_fd >= 0 && target_fd < remote_fio_data.fd_map_size) + if (target_fd >= 0 && target_fd < remote_fio_data.fd_map.size ()) remote_fio_data.fd_map[target_fd] = FIO_FD_INVALID; } @@ -1147,21 +1139,12 @@ do_remote_fileio_request (remote_target *remote, char *buf) void remote_fileio_reset (void) { - int ix; - - for (ix = 0; ix != remote_fio_data.fd_map_size; ix++) + for (int fd : remote_fio_data.fd_map) { - int fd = remote_fio_data.fd_map[ix]; - if (fd >= 0) close (fd); } - if (remote_fio_data.fd_map) - { - xfree (remote_fio_data.fd_map); - remote_fio_data.fd_map = NULL; - remote_fio_data.fd_map_size = 0; - } + remote_fio_data.fd_map.clear (); } /* Handle a file I/O request. BUF points to the packet containing the