mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-19 09:14:14 +08:00
Use htab_t in sim-options.c
This changes sim-options.c to use the libiberty hash table, rather than its own custom hash table. sim/common/ChangeLog 2021-04-25 Tom Tromey <tom@tromey.com> * sim-options.c (compare_strings): New function. (ARG_HASH_SIZE, ARG_HASH): Remove. (dup_arg_p): Use htab_t. (sim_parse_args): Remove assert.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2021-04-25 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* sim-options.c (compare_strings): New function.
|
||||||
|
(ARG_HASH_SIZE, ARG_HASH): Remove.
|
||||||
|
(dup_arg_p): Use htab_t.
|
||||||
|
(sim_parse_args): Remove assert.
|
||||||
|
|
||||||
2021-04-24 Mike Frysinger <vapier@gentoo.org>
|
2021-04-24 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
* dv-cfi.c (attach_cfi_regs): Change %u to PRIiTC.
|
* dv-cfi.c (attach_cfi_regs): Change %u to PRIiTC.
|
||||||
|
@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|||||||
#include "sim-io.h"
|
#include "sim-io.h"
|
||||||
#include "sim-assert.h"
|
#include "sim-assert.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
#include "hashtab.h"
|
||||||
|
|
||||||
#include "bfd.h"
|
#include "bfd.h"
|
||||||
|
|
||||||
@ -413,37 +414,36 @@ standard_install (SIM_DESC sd)
|
|||||||
return SIM_RC_OK;
|
return SIM_RC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Equality function for arguments. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
compare_strings (const void *a, const void *b)
|
||||||
|
{
|
||||||
|
return strcmp (a, b) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return non-zero if arg is a duplicate argument.
|
/* Return non-zero if arg is a duplicate argument.
|
||||||
If ARG is NULL, initialize. */
|
If ARG is NULL, initialize. */
|
||||||
|
|
||||||
#define ARG_HASH_SIZE 256
|
|
||||||
#define ARG_HASH(a) ((256 * (unsigned char) a[0] + (unsigned char) a[1]) % ARG_HASH_SIZE)
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dup_arg_p (const char *arg)
|
dup_arg_p (const char *arg)
|
||||||
{
|
{
|
||||||
int hash;
|
static htab_t arg_table = NULL;
|
||||||
static const char **arg_table = NULL;
|
void **slot;
|
||||||
|
|
||||||
if (arg == NULL)
|
if (arg == NULL)
|
||||||
{
|
{
|
||||||
if (arg_table == NULL)
|
if (arg_table == NULL)
|
||||||
arg_table = (const char **) xmalloc (ARG_HASH_SIZE * sizeof (char *));
|
arg_table = htab_create_alloc (10, htab_hash_string,
|
||||||
memset (arg_table, 0, ARG_HASH_SIZE * sizeof (char *));
|
compare_strings, NULL,
|
||||||
|
xcalloc, free);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = ARG_HASH (arg);
|
slot = htab_find_slot (arg_table, arg, INSERT);
|
||||||
while (arg_table[hash] != NULL)
|
if (*slot != NULL)
|
||||||
{
|
|
||||||
if (strcmp (arg, arg_table[hash]) == 0)
|
|
||||||
return 1;
|
return 1;
|
||||||
/* We assume there won't be more than ARG_HASH_SIZE arguments so we
|
*slot = (void *) arg;
|
||||||
don't check if the table is full. */
|
|
||||||
if (++hash == ARG_HASH_SIZE)
|
|
||||||
hash = 0;
|
|
||||||
}
|
|
||||||
arg_table[hash] = arg;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,9 +478,6 @@ sim_parse_args (SIM_DESC sd, char * const *argv)
|
|||||||
for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
|
for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
|
||||||
++num_opts;
|
++num_opts;
|
||||||
|
|
||||||
/* We build a hash table of all options, so make sure they all fit. */
|
|
||||||
SIM_ASSERT (num_opts <= ARG_HASH_SIZE);
|
|
||||||
|
|
||||||
/* Initialize duplicate argument checker. */
|
/* Initialize duplicate argument checker. */
|
||||||
(void) dup_arg_p (NULL);
|
(void) dup_arg_p (NULL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user