From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id nEJXO2m0/Wl92yIAWB0awg (envelope-from ) for ; Fri, 08 May 2026 06:01:14 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Npjj+bw1; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D3E5A1E0BA; Fri, 08 May 2026 06:01: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=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 8F8801E093 for ; Fri, 08 May 2026 06:01:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1A334BA2E2A for ; Fri, 8 May 2026 10:01:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1A334BA2E2A Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Npjj+bw1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 4263E4BA2E32 for ; Fri, 8 May 2026 10:00:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4263E4BA2E32 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4263E4BA2E32 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778234434; cv=none; b=etbO9tANHWhhqPf1Uc2V7GxjrnJgCRPIIOO0EL9Rfwn1PsM0i8v/UFjRMksM1RprnP0FkNH+pRIAJhcIjoeBfNGYTVjwNQV0oRrhvSQnktOQAQy3CvL7/wT0qWiJbCpCt+dOFHLfpuI9rxKI6hEQjL28CW94J4R1eDtlhkwdZ7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778234434; c=relaxed/simple; bh=cjIHw8zHYuUGt1433N6kiSqt8+9iD4569LpfTnkKvmY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=g9J5IZdqIdwu9z4TENNZf99DNxWWMjedX9p1Hw2r51Lvob+2nRtEErAXnAFdQdLllNg4Us0o7JUciIpaR/WZk2sPBSworb+WFU7J9wfT8Q4OcHtnRZW6qxo0Rb1y8DZ/BDfD02dHpxlsxaKCU0/xNprKUKqnEvEQOyGd2YdRVrM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Npjj+bw1 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4263E4BA2E32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778234433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=B/6vlWTXVZmUSy9QBCuqvx67W7XaBH7G8lwm4IzsKu0=; b=Npjj+bw15CNLY/l58/yuLiJhz4KEPwW5SubHrMebu4SwQjHMDPqUSJ/Xxw1r6HScZTJS8H 2TrEmhT0Pk8a4dq72pryRERjaDpRtrrDaFP1tGkFKdMtiuhSmljtT4UZzCuqR1GCYGfS8M JIg9Xj4KBPQfmIHCwwPLA7MZdn/DrEA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-157-NDWiBSoKMqe6z3v311yoRQ-1; Fri, 08 May 2026 06:00:32 -0400 X-MC-Unique: NDWiBSoKMqe6z3v311yoRQ-1 X-Mimecast-MFC-AGG-ID: NDWiBSoKMqe6z3v311yoRQ_1778234431 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-44d79da8cf7so1692728f8f.2 for ; Fri, 08 May 2026 03:00:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778234431; x=1778839231; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=B/6vlWTXVZmUSy9QBCuqvx67W7XaBH7G8lwm4IzsKu0=; b=Ei5bLJ9kxSxbYGRlDlazHzaXW7l8zX8XJixV/hQfumN1kfuMHdrZZC1Cw0FFHXLGn6 wFpo9ugPY9LU2lEj+UStC7AsGN/3ijLJNuzTjah/E2gBkGYPRBJytrtFa69nuLnbNUL1 7F1jMYd/OQBzD404Du6tFuWhvaZ00c0g29uLzUV0UjldMUiPyURl/HX89VW0wS4hatzb JLN7r0wRHXL2/pRqudB0Zo43HA0E6p5tJbEV1RvAcnOmf7GhlffSK/VBSS0c0q41tKRu 2f0WQQaiLTjYbVdcOUj6gAxkWX7HTas/DMnBE4UeN3yeIDJDHAn/rWPFoeg/dKKUn87q guvA== X-Forwarded-Encrypted: i=1; AFNElJ8iaAbUdRINehqeV0+GY1p3pWR/dySn1oBSJNFtRYd2rQXWBmPphN5gUHxP5wRlkzHKnd6e/UfYq/DbRw==@sourceware.org X-Gm-Message-State: AOJu0YxJrfBE/XMsXoPwuIkXqjwPzmvPa5v42nHlPYwJtHy6hfbELdVQ cqq6BJqsZPZa6vFVVx22wDQqvq/nLr7hlw3WpYY7rMejTb+YLTlQ0lm1BO3HbAdw0TS/yeKbX1z NR6TdhqAkUsbUetpNyx5nkSat4kMvMc6LjqmhFl/ams9NBseUkJ2gaXMYx1t2iEE= X-Gm-Gg: Acq92OFdl4mfj8lfnSH0DcbRlNlMIzsVH2xV1ScjuSsDinqW84D59Ej+GZlwxVoaxgZ nOWOUmWwGI4erK63AikEDlFxfS24vQHTGHDsqQSMbQ45m9CVx5l2zplm9YTIUNgQZC+hY0Dr7fD JLuLVQTgFH0bQW6ptxIPe0zyX1K4NKOMP8fMa+NyypZk7ARaN/FRA15WC0+qitMn1l+ZzjXXEkG 7QsMzsI/KeZq/tIGkAhcDsV3qJ+JmkqpTDIZ8mmBAt+yt/2T5ICeamYh7SbQmMAlnAWHUDGuaqb p/d4lc+9yivzI5tIJ50V6od19uWsUYzX3rUspFCtSFYNdkUMc9htlwl2pLo3E4haR0vqBh1TwUu 3b2/35IdAnzyMCn/9 X-Received: by 2002:a05:6000:4029:b0:43d:a37f:8d5c with SMTP id ffacd0b85a97d-4515b524744mr18418480f8f.17.1778234430899; Fri, 08 May 2026 03:00:30 -0700 (PDT) X-Received: by 2002:a05:6000:4029:b0:43d:a37f:8d5c with SMTP id ffacd0b85a97d-4515b524744mr18418387f8f.17.1778234430321; Fri, 08 May 2026 03:00:30 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4549130549bsm3359438f8f.18.2026.05.08.03.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 03:00:29 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH 1/2] Allow move of compiled_regex In-Reply-To: <20260424-print-var-and-cleanup-v1-1-7b6a2861ccb5@adacore.com> References: <20260424-print-var-and-cleanup-v1-0-7b6a2861ccb5@adacore.com> <20260424-print-var-and-cleanup-v1-1-7b6a2861ccb5@adacore.com> Date: Fri, 08 May 2026 11:00:28 +0100 Message-ID: <87ik8ydxvn.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xRPJZ9Q4F96yGWmeKNm22um2BNHtabsGDGcQIzckpMk_1778234431 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Tom Tromey writes: > This patch makes it possible to move a compiled_regex. > --- > gdbsupport/gdb_regex.cc | 13 +++++++++++-- > gdbsupport/gdb_regex.h | 30 +++++++++++++++++++++++++++++- > 2 files changed, 40 insertions(+), 3 deletions(-) > > diff --git a/gdbsupport/gdb_regex.cc b/gdbsupport/gdb_regex.cc > index 111e5ff24a8..6774aa4c805 100644 > --- a/gdbsupport/gdb_regex.cc > +++ b/gdbsupport/gdb_regex.cc > @@ -33,17 +33,25 @@ compiled_regex::compiled_regex (const char *regex, int cflags, > regerror (code, &m_pattern, err.data (), length); > error (("%s: %s"), message, err.data ()); > } > + > + m_valid = true; > } > > -compiled_regex::~compiled_regex () > +void > +compiled_regex::clear () > { > - regfree (&m_pattern); > + if (m_valid) > + { > + regfree (&m_pattern); > + m_valid = false; > + } > } > > int > compiled_regex::exec (const char *string, size_t nmatch, > regmatch_t pmatch[], int eflags) const > { > + gdb_assert (m_valid); > return regexec (&m_pattern, string, nmatch, pmatch, eflags); > } > > @@ -52,5 +60,6 @@ compiled_regex::search (const char *string, > int length, int start, int range, > struct re_registers *regs) > { > + gdb_assert (m_valid); > return re_search (&m_pattern, string, length, start, range, regs); > } > diff --git a/gdbsupport/gdb_regex.h b/gdbsupport/gdb_regex.h > index 63fd9c32119..f7d3190839f 100644 > --- a/gdbsupport/gdb_regex.h > +++ b/gdbsupport/gdb_regex.h > @@ -35,10 +35,32 @@ class compiled_regex I think the comment above the compiled_regex class needs to be updated. It currently says: /* A compiled regex. This is mainly a wrapper around regex_t. The the constructor throws on regcomp error and the destructor is responsible for calling regfree. The former means that it's not possible to create an instance of compiled_regex that isn't compiled, hence the name. */ [ NOTE: There's a pre-existing typo: "The the constructor throws ...". ] The sentence: "The former means that it's not possible to create an instance of compiled_regex that isn't compiled, hence the name." is now out of date I think. Previously, if I did: compiled_regex re ( ... args ...); then RE was either (a) valid, or (b) an exception was thrown. However, this is no longer the case: compiled_regex re ( ... args ...); compiled_regex re2 (std::move (re)); /* Now RE is in a non-compiled state. */ So the comment needs to be updated to indicate that a compiled_regexp is no longer always compiled. With a suitable comment in place: Approved-By: Andrew Burgess Thanks, Andrew > const char *message) > ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (4); > > - ~compiled_regex (); > + ~compiled_regex () > + { > + clear (); > + } > > DISABLE_COPY_AND_ASSIGN (compiled_regex); > > + compiled_regex (compiled_regex &&other) > + : m_valid (other.m_valid), > + m_pattern (other.m_pattern) > + { > + other.m_valid = false; > + } > + > + compiled_regex &operator= (compiled_regex &&other) > + { > + if (&other != this) > + { > + clear (); > + m_valid = other.m_valid; > + m_pattern = other.m_pattern; > + other.m_valid = false; > + } > + return *this; > + } > + > /* Wrapper around ::regexec. */ > int exec (const char *string, > size_t nmatch, regmatch_t pmatch[], > @@ -50,6 +72,12 @@ class compiled_regex > int range, struct re_registers *regs); > > private: > + /* Free the compiled pattern, if necessary. */ > + void clear (); > + > + /* True if the compiled pattern is valid. */ > + bool m_valid = false; > + > /* The compiled pattern. */ > regex_t m_pattern; > }; > > -- > 2.53.0