From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126806 invoked by alias); 19 Oct 2016 01:13:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 126040 invoked by uid 89); 19 Oct 2016 01:12:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Oct 2016 01:12:44 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6F5328A49 for ; Wed, 19 Oct 2016 01:12:43 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9J1CJjv019701 for ; Tue, 18 Oct 2016 21:12:43 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 26/31] Use ui_file_as_string in gdb/rust-lang.c Date: Wed, 19 Oct 2016 01:13:00 -0000 Message-Id: <1476839539-8374-27-git-send-email-palves@redhat.com> In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com> References: <1476839539-8374-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-10/txt/msg00533.txt.bz2 gdb/ChangeLog: yyyy-mm-yy Pedro Alves Tom Tromey * rust-lang.c (struct disr_info) : Now a std::string. (rust_get_disr_info): Use ui_file_as_string and adjust to use std::string. (rust_val_print): Adjust to use std::string. --- gdb/rust-lang.c | 57 ++++++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 82cd3f9..54a16cc 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -70,8 +70,8 @@ rust_crate_for_block (const struct block *block) struct disr_info { - /* Name of field. Must be freed by caller. */ - char *name; + /* Name of field. */ + std::string name; /* Field number in union. Negative on error. For an encoded enum, the "hidden" member will always be field 1, and the "real" member will always be field 0. */ @@ -172,14 +172,13 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, if (value == 0) { ret.field_no = RUST_ENCODED_ENUM_HIDDEN; - ret.name = concat (TYPE_NAME (type), "::", token, (char *) NULL); + ret.name = std::string (TYPE_NAME (type)) + "::" + token; } else { ret.field_no = RUST_ENCODED_ENUM_REAL; - ret.name = concat (TYPE_NAME (type), "::", - rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type, 0))), - (char *) NULL); + ret.name = (std::string (TYPE_NAME (type)) + "::" + + rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type, 0)))); } do_cleanups (cleanup); @@ -208,8 +207,8 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, address, temp_file, 0, val, &opts); - ret.name = ui_file_xstrdup (temp_file, NULL); - name_segment = rust_last_path_segment (ret.name); + ret.name = ui_file_as_string (temp_file); + name_segment = rust_last_path_segment (ret.name.c_str ()); if (name_segment != NULL) { for (i = 0; i < TYPE_NFIELDS (type); ++i) @@ -233,12 +232,11 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, } } - if (ret.field_no == -1 && ret.name != NULL) + if (ret.field_no == -1 && !ret.name.empty ()) { /* Somehow the discriminant wasn't found. */ - make_cleanup (xfree, ret.name); error (_("Could not find variant of %s with discriminant %s"), - TYPE_TAG_NAME (type), ret.name); + TYPE_TAG_NAME (type), ret.name.c_str ()); } do_cleanups (cleanup); @@ -553,19 +551,17 @@ rust_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, struct type *variant_type; struct disr_info disr; struct value_print_options opts; - struct cleanup *cleanup; opts = *options; opts.deref_ref = 0; disr = rust_get_disr_info (type, valaddr, embedded_offset, address, val); - cleanup = make_cleanup (xfree, disr.name); if (disr.is_encoded && disr.field_no == RUST_ENCODED_ENUM_HIDDEN) { - fprintf_filtered (stream, "%s", disr.name); - goto cleanup; + fprintf_filtered (stream, "%s", disr.name.c_str ()); + break; } first_field = 1; @@ -581,19 +577,19 @@ rust_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, { /* In case of a non-nullary variant, we output 'Foo(x,y,z)'. */ if (is_tuple) - fprintf_filtered (stream, "%s(", disr.name); + fprintf_filtered (stream, "%s(", disr.name.c_str ()); else { /* struct variant. */ - fprintf_filtered (stream, "%s{", disr.name); + fprintf_filtered (stream, "%s{", disr.name.c_str ()); } } else { /* In case of a nullary variant like 'None', just output the name. */ - fprintf_filtered (stream, "%s", disr.name); - goto cleanup; + fprintf_filtered (stream, "%s", disr.name.c_str ()); + break; } for (j = start; j < TYPE_NFIELDS (variant_type); j++) @@ -620,9 +616,6 @@ rust_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, fputs_filtered (")", stream); else fputs_filtered ("}", stream); - - cleanup: - do_cleanups (cleanup); } break; @@ -1628,14 +1621,10 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp, type = value_type (lhs); if (TYPE_CODE (type) == TYPE_CODE_UNION) { - struct cleanup *cleanup; - disr = rust_get_disr_info (type, value_contents (lhs), value_embedded_offset (lhs), value_address (lhs), lhs); - cleanup = make_cleanup (xfree, disr.name); - if (disr.is_encoded && disr.field_no == RUST_ENCODED_ENUM_HIDDEN) { variant_type = NULL; @@ -1654,17 +1643,16 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp, error(_("Cannot access field %d of variant %s, \ there are only %d fields"), disr.is_encoded ? field_number : field_number - 1, - disr.name, + disr.name.c_str (), disr.is_encoded ? nfields : nfields - 1); if (!(disr.is_encoded ? rust_tuple_struct_type_p (variant_type) : rust_tuple_variant_type_p (variant_type))) - error(_("Variant %s is not a tuple variant"), disr.name); + error(_("Variant %s is not a tuple variant"), disr.name.c_str ()); result = value_primitive_field (lhs, 0, field_number, variant_type); - do_cleanups (cleanup); } else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) { @@ -1706,7 +1694,6 @@ tuple structs, and tuple-like enum variants")); { int i, start; struct disr_info disr; - struct cleanup* cleanup; struct type* variant_type; char* field_name; @@ -1716,11 +1703,9 @@ tuple structs, and tuple-like enum variants")); value_embedded_offset (lhs), value_address (lhs), lhs); - cleanup = make_cleanup (xfree, disr.name); - if (disr.is_encoded && disr.field_no == RUST_ENCODED_ENUM_HIDDEN) error(_("Could not find field %s of struct variant %s"), - field_name, disr.name); + field_name, disr.name.c_str ()); variant_type = TYPE_FIELD_TYPE (type, disr.field_no); @@ -1728,7 +1713,7 @@ tuple structs, and tuple-like enum variants")); || rust_tuple_variant_type_p (variant_type)) error(_("Attempting to access named field %s of tuple variant %s, \ which has only anonymous fields"), - field_name, disr.name); + field_name, disr.name.c_str ()); start = disr.is_encoded ? 0 : 1; for (i = start; i < TYPE_NFIELDS (variant_type); i++) @@ -1743,9 +1728,7 @@ which has only anonymous fields"), if (i == TYPE_NFIELDS (variant_type)) /* We didn't find it. */ error(_("Could not find field %s of struct variant %s"), - field_name, disr.name); - - do_cleanups (cleanup); + field_name, disr.name.c_str ()); } else { -- 2.5.5