diff options
| author | Simon Marchi <simon.marchi@efficios.com> | 2026-03-16 11:23:19 -0400 |
|---|---|---|
| committer | Simon Marchi <simon.marchi@efficios.com> | 2026-03-16 13:24:00 -0400 |
| commit | b73d92e2c547f29caece9ea0de904d874a6fffab (patch) | |
| tree | 4af89bcd433165cb81cda731a36e5a3fca4afa98 /gdb/python | |
| parent | 07caff21f90c2f0c9b7b0e79b00b774be668594c (diff) | |
| download | binutils-b73d92e2c547f29caece9ea0de904d874a6fffab.tar.gz binutils-b73d92e2c547f29caece9ea0de904d874a6fffab.tar.bz2 binutils-b73d92e2c547f29caece9ea0de904d874a6fffab.zip | |
gdb, gdbserver, gdbsupport: replace many uses of strcmp with streq
Replace all occurrences of:
strcmp (...) == 0
strcmp (...) != 0
!strcmp (...)
0 == strcmp (...)
strcmp (...) directly used as a boolean predicate
with the equivalent expression using streq.
This is for consistency (we already use streq as some places in the
testsuite) but also for clarity. I think that streq is clearer on the
intent than strcmp. It's also a bit shorter.
Change-Id: Ibbf5261b1872c240bc0c982c147f6a5477275a91
Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/python')
| -rw-r--r-- | gdb/python/py-breakpoint.c | 2 | ||||
| -rw-r--r-- | gdb/python/py-lazy-string.c | 2 | ||||
| -rw-r--r-- | gdb/python/py-micmd.c | 5 | ||||
| -rw-r--r-- | gdb/python/py-param.c | 6 | ||||
| -rw-r--r-- | gdb/python/py-prettyprint.c | 6 | ||||
| -rw-r--r-- | gdb/python/py-style.c | 11 | ||||
| -rw-r--r-- | gdb/python/python.c | 2 |
7 files changed, 16 insertions, 18 deletions
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index c5d3d7e2d7e..03388812ff8 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -1410,7 +1410,7 @@ local_setattro (PyObject *self, PyObject *name, PyObject *v) /* If the attribute trying to be set is the "stop" method, but we already have a condition set in the CLI or other extension language, disallow this operation. */ - if (strcmp (attr.get (), stop_func) == 0) + if (streq (attr.get (), stop_func)) { const struct extension_language_defn *extlang = NULL; diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index 26998064206..fe191451e54 100644 --- a/gdb/python/py-lazy-string.c +++ b/gdb/python/py-lazy-string.c @@ -231,7 +231,7 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length, str_obj->address = address; str_obj->length = length; - if (encoding == NULL || !strcmp (encoding, "")) + if (encoding == NULL || streq (encoding, "")) str_obj->encoding = NULL; else str_obj->encoding = xstrdup (encoding); diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c index 0c820751c56..ab06e197d84 100644 --- a/gdb/python/py-micmd.c +++ b/gdb/python/py-micmd.c @@ -144,8 +144,7 @@ struct mi_command_py : public mi_command than changing the value of mi_command::m_name (which is not accessible from here) to point to the name owned by the new object, swap the names of the two objects, since we know they are identical strings. */ - gdb_assert (strcmp (new_pyobj->mi_command_name, - m_pyobj->mi_command_name) == 0); + gdb_assert (streq (new_pyobj->mi_command_name, m_pyobj->mi_command_name)); std::swap (new_pyobj->mi_command_name, m_pyobj->mi_command_name); /* Take a reference to the new object, drop the reference to the current @@ -385,7 +384,7 @@ micmdpy_init (PyObject *self, PyObject *args, PyObject *kwargs) So, for now at least, we don't allow this. This doesn't seem like an excessive restriction. */ - if (strcmp (cmd->mi_command_name, name) != 0) + if (!streq (cmd->mi_command_name, name)) { PyErr_SetString (PyExc_ValueError, diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index 8765b1b383d..bc028f1746c 100644 --- a/gdb/python/py-param.c +++ b/gdb/python/py-param.c @@ -242,7 +242,7 @@ set_parameter_value (parmpy_object *self, PyObject *value) if (str == NULL) return -1; for (i = 0; self->enumeration[i]; ++i) - if (! strcmp (self->enumeration[i], str.get ())) + if (streq (self->enumeration[i], str.get ())) break; if (! self->enumeration[i]) { @@ -328,8 +328,8 @@ set_parameter_value (parmpy_object *self, PyObject *value) buffer += ", "; buffer = buffer + "'" + l->literal + "'"; if (allowed == TRIBOOL_UNKNOWN - && ((value == Py_None && !strcmp ("unlimited", l->literal)) - || (s != nullptr && !strcmp (s, l->literal)))) + && ((value == Py_None && streq ("unlimited", l->literal)) + || (s != nullptr && streq (s, l->literal)))) { val = l->use; allowed = TRIBOOL_TRUE; diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 3dcb4fba1e4..0cf0cde881c 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -323,7 +323,7 @@ print_string_repr (PyObject *printer, const char *hint, length = PyBytes_Size (string.get ()); type = builtin_type (gdbarch)->builtin_char; - if (hint && !strcmp (hint, "string")) + if (hint && streq (hint, "string")) language->printstr (stream, type, (gdb_byte *) output, length, NULL, 0, options); else @@ -370,8 +370,8 @@ print_children (PyObject *printer, const char *hint, /* If we are printing a map or an array, we want some special formatting. */ - is_map = hint && ! strcmp (hint, "map"); - is_array = hint && ! strcmp (hint, "array"); + is_map = hint && streq (hint, "map"); + is_array = hint && streq (hint, "array"); gdbpy_ref<> children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst, NULL)); diff --git a/gdb/python/py-style.c b/gdb/python/py-style.c index aa6eccaadbe..d149d90aaa9 100644 --- a/gdb/python/py-style.c +++ b/gdb/python/py-style.c @@ -135,28 +135,27 @@ stylepy_style_from_name (const char *name, bool *has_intensity_ptr = nullptr, if (!sub->var.has_value ()) continue; - if (strcmp (sub->name, "foreground") == 0) + if (streq (sub->name, "foreground")) { const ui_file_style::color &color = sub->var->get<ui_file_style::color> (); style.set_fg (color); has_fg = true; } - else if (strcmp (sub->name, "background") == 0) + else if (streq (sub->name, "background")) { const ui_file_style::color &color = sub->var->get<ui_file_style::color> (); style.set_bg (color); has_bg = true; } - else if (strcmp (sub->name, "intensity") == 0 - && sub->var->type () == var_enum) + else if (streq (sub->name, "intensity") && sub->var->type () == var_enum) { const char *intensity_str = sub->var->get<const char *> (); ui_file_style::intensity intensity = ui_file_style::NORMAL; - if (strcmp (intensity_str, "bold") == 0) + if (streq (intensity_str, "bold")) intensity = ui_file_style::BOLD; - else if (strcmp (intensity_str, "dim") == 0) + else if (streq (intensity_str, "dim")) intensity = ui_file_style::DIM; style.set_intensity (intensity); has_intensity = true; diff --git a/gdb/python/python.c b/gdb/python/python.c index 5474b8d644f..6e13ab5bb3f 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -552,7 +552,7 @@ gdbpy_parameter_value (const setting &var) l++) if (value == l->use) { - if (strcmp (l->literal, "unlimited") == 0) + if (streq (l->literal, "unlimited")) { /* Compatibility hack for API brokenness. */ if (var.type () == var_pinteger |
