From patchwork Tue May 29 15:10:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27538 Received: (qmail 65877 invoked by alias); 29 May 2018 15:10:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 65862 invoked by uid 89); 29 May 2018 15:10:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Deep X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.161) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 May 2018 15:10:12 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 830662C308 for ; Tue, 29 May 2018 10:10:10 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id NgGIflKLCbXuJNgGIf1quD; Tue, 29 May 2018 10:10:10 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:59326 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fNgGI-0009Tq-40; Tue, 29 May 2018 10:10:10 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Remove a VEC from type.c Date: Tue, 29 May 2018 09:10:02 -0600 Message-Id: <20180529151002.5700-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fNgGI-0009Tq-40 X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:59326 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes a VEC from type.c, by using std::vector. While doing this I also took the opportunity to change types_deeply_equal to return bool. This caught some weird code in typy_richcompare, now fixed. And, since I was changing types_deeply_equal, it seemed like a good idea to also change types_equal, so this patch includes that as well. Tested by the buildbot. ChangeLog 2018-05-29 Tom Tromey * python/py-type.c (typy_richcompare): Update. * guile/scm-type.c (tyscm_equal_p_type_smob): Update. * gdbtypes.h (types_deeply_equal): Return bool. (types_equal): Likewise. * gdbtypes.c (type_equality_entry_d): Remove typedef. Don't declare VEC. (check_types_equal): Change worklist to std::vector. Return bool. (struct type_equality_entry): Add constructor. (compare_maybe_null_strings): Return bool. (check_types_worklist): Return bool. Change worklist to std::vector. (types_deeply_equal): Use std::vector. (types_equal): Return bool. --- gdb/ChangeLog | 17 +++++++ gdb/gdbtypes.c | 137 ++++++++++++++++++++++++--------------------------- gdb/gdbtypes.h | 4 +- gdb/guile/scm-type.c | 2 +- gdb/python/py-type.c | 4 +- 5 files changed, 87 insertions(+), 77 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 4f77a5214e3..2be0d2e97d9 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3551,10 +3551,10 @@ integer_types_same_name_p (const char *first, const char *second) return 1; } -/* Compares type A to type B returns 1 if the represent the same type - 0 otherwise. */ +/* Compares type A to type B returns true if the represent the same + type, false otherwise. */ -int +bool types_equal (struct type *a, struct type *b) { /* Identical type pointers. */ @@ -3562,7 +3562,7 @@ types_equal (struct type *a, struct type *b) and a. The reason is that builtin types are different from the same ones constructed from the object. */ if (a == b) - return 1; + return true; /* Resolve typedefs */ if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF) @@ -3573,7 +3573,7 @@ types_equal (struct type *a, struct type *b) /* If after resolving typedefs a and b are not of the same type code then they are not equal. */ if (TYPE_CODE (a) != TYPE_CODE (b)) - return 0; + return false; /* If a and b are both pointers types or both reference types then they are equal of the same type iff the objects they refer to are @@ -3590,11 +3590,11 @@ types_equal (struct type *a, struct type *b) if (TYPE_NAME (a) && TYPE_NAME (b) && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0) - return 1; + return true; /* Check if identical after resolving typedefs. */ if (a == b) - return 1; + return true; /* Two function types are equal if their argument and return types are equal. */ @@ -3603,60 +3603,64 @@ types_equal (struct type *a, struct type *b) int i; if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b)) - return 0; + return false; if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b))) - return 0; + return false; for (i = 0; i < TYPE_NFIELDS (a); ++i) if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i))) - return 0; + return false; - return 1; + return true; } - return 0; + return false; } /* Deep comparison of types. */ /* An entry in the type-equality bcache. */ -typedef struct type_equality_entry +struct type_equality_entry { - struct type *type1, *type2; -} type_equality_entry_d; + type_equality_entry (struct type *t1, struct type *t2) + : type1 (t1), + type2 (t2) + { + } -DEF_VEC_O (type_equality_entry_d); + struct type *type1, *type2; +}; -/* A helper function to compare two strings. Returns 1 if they are - the same, 0 otherwise. Handles NULLs properly. */ +/* A helper function to compare two strings. Returns true if they are + the same, false otherwise. Handles NULLs properly. */ -static int +static bool compare_maybe_null_strings (const char *s, const char *t) { if (s == NULL && t != NULL) - return 0; + return false; else if (s != NULL && t == NULL) - return 0; + return false; else if (s == NULL && t== NULL) - return 1; + return true; return strcmp (s, t) == 0; } /* A helper function for check_types_worklist that checks two types for - "deep" equality. Returns non-zero if the types are considered the - same, zero otherwise. */ + "deep" equality. Returns true if the types are considered the + same, false otherwise. */ -static int +static bool check_types_equal (struct type *type1, struct type *type2, - VEC (type_equality_entry_d) **worklist) + std::vector *worklist) { type1 = check_typedef (type1); type2 = check_typedef (type2); if (type1 == type2) - return 1; + return true; if (TYPE_CODE (type1) != TYPE_CODE (type2) || TYPE_LENGTH (type1) != TYPE_LENGTH (type2) @@ -3667,18 +3671,18 @@ check_types_equal (struct type *type1, struct type *type2, || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2) || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2) || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2)) - return 0; + return false; if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1), TYPE_TAG_NAME (type2))) - return 0; + return false; if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2))) - return 0; + return false; if (TYPE_CODE (type1) == TYPE_CODE_RANGE) { if (*TYPE_RANGE_DATA (type1) != *TYPE_RANGE_DATA (type2)) - return 0; + return false; } else { @@ -3688,34 +3692,33 @@ check_types_equal (struct type *type1, struct type *type2, { const struct field *field1 = &TYPE_FIELD (type1, i); const struct field *field2 = &TYPE_FIELD (type2, i); - struct type_equality_entry entry; if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2) || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2) || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2)) - return 0; + return false; if (!compare_maybe_null_strings (FIELD_NAME (*field1), FIELD_NAME (*field2))) - return 0; + return false; switch (FIELD_LOC_KIND (*field1)) { case FIELD_LOC_KIND_BITPOS: if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2)) - return 0; + return false; break; case FIELD_LOC_KIND_ENUMVAL: if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2)) - return 0; + return false; break; case FIELD_LOC_KIND_PHYSADDR: if (FIELD_STATIC_PHYSADDR (*field1) != FIELD_STATIC_PHYSADDR (*field2)) - return 0; + return false; break; case FIELD_LOC_KIND_PHYSNAME: if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1), FIELD_STATIC_PHYSNAME (*field2))) - return 0; + return false; break; case FIELD_LOC_KIND_DWARF_BLOCK: { @@ -3726,7 +3729,7 @@ check_types_equal (struct type *type1, struct type *type2, if (block1->per_cu != block2->per_cu || block1->size != block2->size || memcmp (block1->data, block2->data, block1->size) != 0) - return 0; + return false; } break; default: @@ -3735,43 +3738,37 @@ check_types_equal (struct type *type1, struct type *type2, FIELD_LOC_KIND (*field1)); } - entry.type1 = FIELD_TYPE (*field1); - entry.type2 = FIELD_TYPE (*field2); - VEC_safe_push (type_equality_entry_d, *worklist, &entry); + worklist->emplace_back (FIELD_TYPE (*field1), FIELD_TYPE (*field2)); } } if (TYPE_TARGET_TYPE (type1) != NULL) { - struct type_equality_entry entry; - if (TYPE_TARGET_TYPE (type2) == NULL) - return 0; + return false; - entry.type1 = TYPE_TARGET_TYPE (type1); - entry.type2 = TYPE_TARGET_TYPE (type2); - VEC_safe_push (type_equality_entry_d, *worklist, &entry); + worklist->emplace_back (TYPE_TARGET_TYPE (type1), + TYPE_TARGET_TYPE (type2)); } else if (TYPE_TARGET_TYPE (type2) != NULL) - return 0; + return false; - return 1; + return true; } -/* Check types on a worklist for equality. Returns zero if any pair - is not equal, non-zero if they are all considered equal. */ +/* Check types on a worklist for equality. Returns false if any pair + is not equal, true if they are all considered equal. */ -static int -check_types_worklist (VEC (type_equality_entry_d) **worklist, +static bool +check_types_worklist (std::vector *worklist, struct bcache *cache) { - while (!VEC_empty (type_equality_entry_d, *worklist)) + while (!worklist->empty ()) { - struct type_equality_entry entry; int added; - entry = *VEC_last (type_equality_entry_d, *worklist); - VEC_pop (type_equality_entry_d, *worklist); + struct type_equality_entry entry = std::move (worklist->back ()); + worklist->pop_back (); /* If the type pair has already been visited, we know it is ok. */ @@ -3779,36 +3776,33 @@ check_types_worklist (VEC (type_equality_entry_d) **worklist, if (!added) continue; - if (check_types_equal (entry.type1, entry.type2, worklist) == 0) - return 0; + if (!check_types_equal (entry.type1, entry.type2, worklist)) + return false; } - return 1; + return true; } -/* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a - "deep comparison". Otherwise return zero. */ +/* Return true if types TYPE1 and TYPE2 are equal, as determined by a + "deep comparison". Otherwise return false. */ -int +bool types_deeply_equal (struct type *type1, struct type *type2) { struct gdb_exception except = exception_none; - int result = 0; + bool result = false; struct bcache *cache; - VEC (type_equality_entry_d) *worklist = NULL; - struct type_equality_entry entry; + std::vector worklist; gdb_assert (type1 != NULL && type2 != NULL); /* Early exit for the simple case. */ if (type1 == type2) - return 1; + return true; cache = bcache_xmalloc (NULL, NULL); - entry.type1 = type1; - entry.type2 = type2; - VEC_safe_push (type_equality_entry_d, worklist, &entry); + worklist.emplace_back (type1, type2); /* check_types_worklist calls several nested helper functions, some of which can raise a GDB exception, so we just check and rethrow @@ -3825,7 +3819,6 @@ types_deeply_equal (struct type *type1, struct type *type2) END_CATCH bcache_xfree (cache); - VEC_free (type_equality_entry_d, worklist); /* Rethrow if there was a problem. */ if (except.reason < 0) diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 5f614e573a8..2a1ed609d18 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2092,9 +2092,9 @@ extern struct type *copy_type_recursive (struct objfile *objfile, extern struct type *copy_type (const struct type *type); -extern int types_equal (struct type *, struct type *); +extern bool types_equal (struct type *, struct type *); -extern int types_deeply_equal (struct type *, struct type *); +extern bool types_deeply_equal (struct type *, struct type *); extern int type_not_allocated (const struct type *type); diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c index ce67695b76a..f2e7be3e450 100644 --- a/gdb/guile/scm-type.c +++ b/gdb/guile/scm-type.c @@ -224,7 +224,7 @@ tyscm_equal_p_type_smob (SCM type1_scm, SCM type2_scm) { type_smob *type1_smob, *type2_smob; struct type *type1, *type2; - int result = 0; + bool result = false; SCM_ASSERT_TYPE (tyscm_is_type (type1_scm), type1_scm, SCM_ARG1, FUNC_NAME, type_smob_name); diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index cbdcd21156c..80055b05e05 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1008,7 +1008,7 @@ typy_str (PyObject *self) static PyObject * typy_richcompare (PyObject *self, PyObject *other, int op) { - int result = Py_NE; + bool result = false; struct type *type1 = type_object_to_type (self); struct type *type2 = type_object_to_type (other); @@ -1021,7 +1021,7 @@ typy_richcompare (PyObject *self, PyObject *other, int op) } if (type1 == type2) - result = Py_EQ; + result = true; else { TRY