diff options
author | Tom Tromey <tom@tromey.com> | 2018-05-29 00:29:23 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-05-29 11:44:12 -0600 |
commit | 894882e344735ace5231f179484086f7697d27cc (patch) | |
tree | 87bc3c9797d3c9f3eb47053e85cc6a63b298ca62 /gdb | |
parent | 10b2ded43caa3298cded1df8b620caaaee3f9209 (diff) | |
download | gdb-894882e344735ace5231f179484086f7697d27cc.zip gdb-894882e344735ace5231f179484086f7697d27cc.tar.gz gdb-894882e344735ace5231f179484086f7697d27cc.tar.bz2 |
Remove a VEC from type.c
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 <tom@tromey.com>
* 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.
(compare_maybe_null_strings): Simplify.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 18 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 139 | ||||
-rw-r--r-- | gdb/gdbtypes.h | 4 | ||||
-rw-r--r-- | gdb/guile/scm-type.c | 2 | ||||
-rw-r--r-- | gdb/python/py-type.c | 4 |
5 files changed, 87 insertions, 80 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 221aa2f..cca51b4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,23 @@ 2018-05-29 Tom Tromey <tom@tromey.com> + * 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. + (compare_maybe_null_strings): Simplify. + +2018-05-29 Tom Tromey <tom@tromey.com> + * record-btrace.c (tp_t): Remove typedef. Don't declare VEC. 2018-05-29 Tom Tromey <tom@tromey.com> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 4f77a52..3d75c21 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 they 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,60 @@ 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; - else if (s != NULL && t == NULL) - return 0; - else if (s == NULL && t== NULL) - return 1; + if (s == NULL || t == NULL) + return s == t; 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<type_equality_entry> *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 +3667,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 +3688,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 +3725,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 +3734,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<type_equality_entry> *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 +3772,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<type_equality_entry> 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 +3815,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 5f614e5..2a1ed60 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 ce67695..f2e7be3 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 cbdcd21..80055b0 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 |