Message ID | CAFOnWkmN-uBB8iDjMaLpe=0SxWecFXxvvgfG2-FJn3j2XbBZJA@mail.gmail.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 13823 invoked by alias); 29 Jun 2016 10:14:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 13804 invoked by uid 89); 29 Jun 2016 10:14:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=U*manish, D*mozilla.com, sk:manish@, manish@mozilla.com X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 29 Jun 2016 10:14:04 +0000 Received: by mail-wm0-f49.google.com with SMTP id v199so173910117wmv.0 for <gdb-patches@sourceware.org>; Wed, 29 Jun 2016 03:14:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=YO9VUDe9xPgbzHSR3hk6RxBpLhISU8ykQxwWdTZF5i4=; b=SA+hA5ONr6OzBfPdin7gIzeYqPDnctj1RQc60klQ7RMiUBzjKUvUMRb4flogzfj77z gq+B8RIG0DED98oFxjFnqqpqD93dL3HrNPjpaKctlsGXD1x/uBi32aZtrrs0f7QErlq4 dVm2zS65OJkUWP5X+i4M96LrbkJ3XZ0z0f6kcpERPGTVj0zY4HZYOtqSm+L4c7URGAbM tm5dWj0EwVGJMgB648yPjpOavDNgDwnXsJcBuR3RhHBmGaXOLAucYM+XMHAAh5RT/VuU e+D3pC7NlG6AQTqUsqUDpaLkVL2bP2g3SgfmET7E2bRNUmi9G/UzCGgJPQSi38Hxozhw lMmA== X-Gm-Message-State: ALyK8tLjKqYz3CeW1avfCTdKu8S6T8WQ1D52vUbdW0YMjjXvrK5byz1XUwva+rSRFWEZbB5N2jIrUuaokw6+jGeh X-Received: by 10.194.82.161 with SMTP id j1mr8371646wjy.65.1467195241709; Wed, 29 Jun 2016 03:14:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.36.215 with HTTP; Wed, 29 Jun 2016 03:13:58 -0700 (PDT) From: Manish Goregaokar <manish@mozilla.com> Date: Wed, 29 Jun 2016 15:43:58 +0530 Message-ID: <CAFOnWkmN-uBB8iDjMaLpe=0SxWecFXxvvgfG2-FJn3j2XbBZJA@mail.gmail.com> Subject: [PATCH] Use strtok_r instead of strsep in rust_get_disr_info To: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com> Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes |
Commit Message
Manish Goregaokar
June 29, 2016, 10:13 a.m. UTC
strsep doesn't exist on windows 2016-06-29 Manish Goregaokar <manish@mozilla.com> gdb/ChangeLog: * rust-lang.c (rust_get_disr_info): Use strtok_r instead of strsep --- gdb/rust-lang.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) LONGEST value; @@ -138,6 +138,8 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, cleanup = make_cleanup (xfree, name); tail = name + strlen (RUST_ENUM_PREFIX); + token = strtok_r (tail, "$", &last); + /* The location of the value that doubles as a discriminant is stored in the name of the field, as RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname> @@ -145,7 +147,7 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, traversed in order to find the field (which may be several fields deep) and the variantname is the name of the variant of the case when the field is zero. */ - while ((token = strsep (&tail, "$")) != NULL) + do { if (sscanf (token, "%lu", &fieldno) != 1) { @@ -159,10 +161,8 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, embedded_offset += TYPE_FIELD_BITPOS (member_type, fieldno) / 8; member_type = TYPE_FIELD_TYPE (member_type, fieldno); - } + } while ((token = strtok_r (NULL, "$", &last)) != NULL); - if (token >= name + strlen (TYPE_FIELD_NAME (type, 0))) - error (_("Invalid form for %s"), RUST_ENUM_PREFIX); value = unpack_long (member_type, valaddr + embedded_offset); if (value == 0)
Comments
(stepping in since this fixes a build breakage.) On 06/29/2016 11:13 AM, Manish Goregaokar wrote: > strsep doesn't exist on windows "Windows", uppercase. > > 2016-06-29 Manish Goregaokar <manish@mozilla.com> > > gdb/ChangeLog: > * rust-lang.c (rust_get_disr_info): Use strtok_r instead of strsep Period at end of sentences. Likewise on the commit log, while at it. > --- > gdb/rust-lang.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c > index 23ddd5a..961fdca 100644 > --- a/gdb/rust-lang.c > +++ b/gdb/rust-lang.c > @@ -121,7 +121,7 @@ rust_get_disr_info (struct type *type, const > gdb_byte *valaddr, > if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX, > strlen (RUST_ENUM_PREFIX)) == 0) > { > - char *name, *tail, *token; > + char *tail, *token, *name, *last = NULL; (I don't think you need to initialize this. If you get a warning about it, it's likely revealing a bug.) > unsigned long fieldno; > struct type *member_type; > LONGEST value; > @@ -138,6 +138,8 @@ rust_get_disr_info (struct type *type, const > gdb_byte *valaddr, > cleanup = make_cleanup (xfree, name); > tail = name + strlen (RUST_ENUM_PREFIX); > > + token = strtok_r (tail, "$", &last); > + > /* The location of the value that doubles as a discriminant is > stored in the name of the field, as > RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname> > @@ -145,7 +147,7 @@ rust_get_disr_info (struct type *type, const > gdb_byte *valaddr, > traversed in order to find the field (which may be several > fields deep) > and the variantname is the name of the variant of the case when the > field is zero. */ > - while ((token = strsep (&tail, "$")) != NULL) > + do > { > if (sscanf (token, "%lu", &fieldno) != 1) We'll now reach here even if token is NULL the first time. > { > @@ -159,10 +161,8 @@ rust_get_disr_info (struct type *type, const > gdb_byte *valaddr, > > embedded_offset += TYPE_FIELD_BITPOS (member_type, fieldno) / 8; > member_type = TYPE_FIELD_TYPE (member_type, fieldno); > - } > + } while ((token = strtok_r (NULL, "$", &last)) != NULL); IMO, this calls for a "for" loop instead of a do/while. Like: - while ((token = strsep (&tail, "$")) != NULL) + for (token = strtok_r (tail, "$", &saveptr); + token != NULL; + token = strtok_r (NULL, "$", &saveptr)) { Thanks, Pedro Alves
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 23ddd5a..961fdca 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -121,7 +121,7 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX, strlen (RUST_ENUM_PREFIX)) == 0) { - char *name, *tail, *token; + char *tail, *token, *name, *last = NULL; unsigned long fieldno; struct type *member_type;