Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [RFA 2/2] C++-ify break-catch-throw
Date: Mon, 05 Jun 2017 10:33:00 -0000	[thread overview]
Message-ID: <01e777c7-a287-8dfe-dd21-370690ed6629@redhat.com> (raw)
In-Reply-To: <ea509791-c718-a22e-28ed-439c6d5b6e08@redhat.com>

On 06/05/2017 11:21 AM, Pedro Alves wrote:
> On 06/04/2017 11:53 PM, Tom Tromey wrote:
>> @@ -452,17 +450,14 @@ catch_exception_command_1 (enum exception_event_kind ex_event,
>>  			   char *arg_entry,
>>  			   int tempflag, int from_tty)
>>  {
>> -  char *except_rx;
>>    const char *cond_string = NULL;
>> -  struct cleanup *cleanup;
>>    const char *arg = arg_entry;
>>  
>>    if (!arg)
>>      arg = "";
>>    arg = skip_spaces_const (arg);
>>  
>> -  except_rx = extract_exception_regexp (&arg);
>> -  cleanup = make_cleanup (xfree, except_rx);
>> +  std::string except_rx = extract_exception_regexp (&arg);
>>  
>>    cond_string = ep_parse_optional_if_clause (&arg);
>>  
>> @@ -474,10 +469,8 @@ catch_exception_command_1 (enum exception_event_kind ex_event,
>>        && ex_event != EX_EVENT_RETHROW)
>>      error (_("Unsupported or unknown exception event; cannot catch it"));
>>  
>> -  handle_gnu_v3_exceptions (tempflag, except_rx, cond_string,
>> +  handle_gnu_v3_exceptions (tempflag, std::move (except_rx), cond_string,
>>  			    ex_event, from_tty);
>> -
>> -  discard_cleanups (cleanup);
>>  }
> 
> Something looks suspicious to me -- compile_rx_or_error returns with
> an installed cleanup that calls regfree, and handle_gnu_v3_exceptions
> leaves it installed too.

Maybe the cleanest would be to add a wrapper around regex_t,
and replace compile_rx_or_error with a ctor that throws,
like:

class gdb_regex
{
public:
  // replaces old compile_rx_or_error
  gdb_regex (const char *rx, const char *message)
  {
    gdb_assert (rx != NULL);

    int code = regcomp (&m_pattern, rx, REG_NOSUB);
    if (code != 0)
      {
        gdb::unique_xmalloc_ptr<char> err
          = get_regcomp_error (code, &m_pattern);

        error (("%s: %s"), message, err.get ());
      }
  }
  ~gdb_regex ()
  {
    regfree (&m_pattern);
  }

  // add convenience methods as needed.

private:
  regex_t m_pattern;
};

and use it throughout.

Thanks,
Pedro Alves


  reply	other threads:[~2017-06-05 10:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-04 22:54 [RFA 0/2] C++-ify some breakpoint subclasses a bit more Tom Tromey
2017-06-04 22:54 ` [RFA 1/2] C++-ify break-catch-sig Tom Tromey
2017-06-05  8:43   ` Simon Marchi
2017-06-05 13:13     ` Tom Tromey
2017-06-05 13:53     ` Tom Tromey
2017-06-04 22:54 ` [RFA 2/2] C++-ify break-catch-throw Tom Tromey
2017-06-05  8:54   ` Simon Marchi
2017-06-05 19:10     ` Tom Tromey
2017-06-05 10:21   ` Pedro Alves
2017-06-05 10:33     ` Pedro Alves [this message]
2017-06-05 10:36       ` Pedro Alves
2017-06-05 12:29         ` Pedro Alves
2017-06-05 12:32           ` Pedro Alves
2017-06-05 19:27           ` Tom Tromey
2017-06-06 16:22             ` Pedro Alves
2017-06-07 12:38               ` Tom Tromey
2017-06-07 13:40                 ` [pushed] Introduce compiled_regex, eliminate make_regfree_cleanup (Re: [RFA 2/2] C++-ify break-catch-throw) Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01e777c7-a287-8dfe-dd21-370690ed6629@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox