&& match_section (sec, match));
}
-static void
-free_section_idx (void *ent)
-{
- string_tuple_t *tuple = ent;
- free ((char *) tuple->value);
-}
-
/* Go look in section lists kept per group for SEC_NAME with
properties given by MATCH. If info for the group named by
MATCH->GROUP_NAME has been initialised, set GROUP_IDX. */
static asection *
group_section_find (const struct elf_section_match *match,
const char *sec_name,
- unsigned int **group_idx)
+ unsigned int *group_idx)
{
if (!groups.indexes)
{
groups.num_group = 0;
groups.head = NULL;
groups.indexes = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
- free_section_idx, notes_calloc, NULL);
- *group_idx = NULL;
+ NULL, notes_calloc, NULL);
+ *group_idx = ~0u;
return NULL;
}
- *group_idx = str_hash_find (groups.indexes, match->group_name);
- if (*group_idx == NULL)
+ *group_idx = str_hash_find_int (groups.indexes, match->group_name);
+ if (*group_idx == ~0u)
return NULL;
asection *s;
- for (s = groups.head[**group_idx]; s != NULL; s = elf_next_in_group (s))
+ for (s = groups.head[*group_idx]; s != NULL; s = elf_next_in_group (s))
if ((s->name == sec_name
|| strcmp (s->name, sec_name) == 0)
&& match_section (s, match))
static void
group_section_insert (const struct elf_section_match *match,
asection *sec,
- unsigned int **group_idx)
+ unsigned int *group_idx)
{
- if (*group_idx != NULL)
+ if (*group_idx != ~0u)
{
- elf_next_in_group (sec) = groups.head[**group_idx];
- groups.head[**group_idx] = sec;
+ elf_next_in_group (sec) = groups.head[*group_idx];
+ groups.head[*group_idx] = sec;
return;
}
groups.num_group += 1;
/* We keep the index into groups.head rather than the entry address
- because groups.head may be realloc'd, and because str_hash values
- are a void* we make a copy of the index. Strictly speaking there
- is no guarantee that void* can represent any int value, so doing
- without the indirection by casting an int or even uintptr_t may
- for example lose lsbs of the value. */
- unsigned int *idx_ptr = XNEW (unsigned int);
- *idx_ptr = i;
- str_hash_insert (groups.indexes, match->group_name, idx_ptr, 0);
+ because groups.head may be realloc'd. */
+ str_hash_insert_int (groups.indexes, match->group_name, i, 0);
}
/* Handle the .section pseudo-op. This code supports two different
obj_elf_section_change_hook ();
- unsigned int *group_idx = NULL;
+ unsigned int group_idx = ~0u;
if (match_p->group_name)
old_sec = group_section_find (match_p, name, &group_idx);
else
& SEC_ASSEMBLER_SHF_MASK);
match.flags = bfd_section_flags (sec) & SEC_ASSEMBLER_SECTION_ID;
- unsigned int *group_idx;
+ unsigned int group_idx;
if (!group_section_find (&match, sec->name, &group_idx))
group_section_insert (&match, sec, &group_idx);
}
for (i = 0; i < ARRAY_SIZE (avr_no_sreg); ++i)
{
gas_assert (str_hash_find (avr_hash, avr_no_sreg[i]));
- str_hash_insert (avr_no_sreg_hash, avr_no_sreg[i],
- (void *) 4 /* dummy */, 0);
+ str_hash_insert_int (avr_no_sreg_hash, avr_no_sreg[i], 0 /* dummy */, 0);
}
avr_gccisr_opcode = (struct avr_opcodes_s*) str_hash_find (avr_hash,
/* SREG: Look up instructions that don't clobber SREG. */
if (!avr_isr.need_sreg
- && !str_hash_find (avr_no_sreg_hash, opcode->name))
+ && str_hash_find_int (avr_no_sreg_hash, opcode->name) < 0)
{
avr_isr.need_sreg = 1;
}
/* Init ilp32/lp64 registers names. */
if (!r_htab)
- r_htab = str_htab_create (), str_hash_insert (r_htab, "", 0, 0);
+ r_htab = str_htab_create ();
if (!r_deprecated_htab)
- r_deprecated_htab = str_htab_create (),
- str_hash_insert (r_deprecated_htab, "", 0, 0);
+ r_deprecated_htab = str_htab_create ();
/* Init cfi registers alias. */
if (!cfi_r_htab)
- cfi_r_htab = str_htab_create (), str_hash_insert (cfi_r_htab, "", 0, 0);
+ cfi_r_htab = str_htab_create ();
r_abi_names = loongarch_r_normal_name;
for (i = 0; i < ARRAY_SIZE (loongarch_r_normal_name); i++)
{
- str_hash_insert (r_htab, loongarch_r_normal_name[i],
- (void *) (i + 1), 0);
- str_hash_insert (cfi_r_htab, loongarch_r_normal_name[i],
- (void *) (i + 1), 0);
+ str_hash_insert_int (r_htab, loongarch_r_normal_name[i], i, 0);
+ str_hash_insert_int (cfi_r_htab, loongarch_r_normal_name[i], i, 0);
}
/* Init ilp32/lp64 registers alias. */
r_abi_names = loongarch_r_alias;
for (i = 0; i < ARRAY_SIZE (loongarch_r_alias); i++)
{
- str_hash_insert (r_htab, loongarch_r_alias[i],
- (void *) (i + 1), 0);
- str_hash_insert (cfi_r_htab, loongarch_r_alias[i],
- (void *) (i + 1), 0);
+ str_hash_insert_int (r_htab, loongarch_r_alias[i], i, 0);
+ str_hash_insert_int (cfi_r_htab, loongarch_r_alias[i], i, 0);
}
for (i = 0; i < ARRAY_SIZE (loongarch_r_alias_1); i++)
- str_hash_insert (r_htab, loongarch_r_alias_1[i], (void *) (i + 1), 0);
+ str_hash_insert_int (r_htab, loongarch_r_alias_1[i], i, 0);
for (i = 0; i < ARRAY_SIZE (loongarch_r_alias_deprecated); i++)
- str_hash_insert (r_deprecated_htab, loongarch_r_alias_deprecated[i],
- (void *) (i + 1), 0);
+ str_hash_insert_int (r_deprecated_htab, loongarch_r_alias_deprecated[i],
+ i, 0);
/* The .cfi directive supports register aliases without the "$" prefix. */
for (i = 0; i < ARRAY_SIZE (loongarch_r_cfi_name); i++)
{
- str_hash_insert (cfi_r_htab, loongarch_r_cfi_name[i],
- (void *)(i + 1), 0);
- str_hash_insert (cfi_r_htab, loongarch_r_cfi_name_alias[i],
- (void *)(i + 1), 0);
+ str_hash_insert_int (cfi_r_htab, loongarch_r_cfi_name[i], i, 0);
+ str_hash_insert_int (cfi_r_htab, loongarch_r_cfi_name_alias[i], i, 0);
}
if (!cr_htab)
- cr_htab = str_htab_create (), str_hash_insert (cr_htab, "", 0, 0);
+ cr_htab = str_htab_create ();
for (i = 0; i < ARRAY_SIZE (loongarch_cr_normal_name); i++)
- str_hash_insert (cr_htab, loongarch_cr_normal_name[i], (void *) (i + 1), 0);
+ str_hash_insert_int (cr_htab, loongarch_cr_normal_name[i], i, 0);
/* Init single/double float registers names. */
if (LARCH_opts.ase_sf || LARCH_opts.ase_df)
{
if (!f_htab)
- f_htab = str_htab_create (), str_hash_insert (f_htab, "", 0, 0);
+ f_htab = str_htab_create ();
if (!f_deprecated_htab)
- f_deprecated_htab = str_htab_create (),
- str_hash_insert (f_deprecated_htab, "", 0, 0);
+ f_deprecated_htab = str_htab_create ();
if (!cfi_f_htab)
- cfi_f_htab = str_htab_create (), str_hash_insert (cfi_f_htab, "", 0, 0);
+ cfi_f_htab = str_htab_create ();
f_abi_names = loongarch_f_normal_name;
for (i = 0; i < ARRAY_SIZE (loongarch_f_normal_name); i++)
{
- str_hash_insert (f_htab, loongarch_f_normal_name[i],
- (void *) (i + 1), 0);
- str_hash_insert (cfi_f_htab, loongarch_f_normal_name[i],
- (void *) (i + 1), 0);
+ str_hash_insert_int (f_htab, loongarch_f_normal_name[i], i, 0);
+ str_hash_insert_int (cfi_f_htab, loongarch_f_normal_name[i], i, 0);
}
/* Init float-ilp32/lp64 registers alias. */
f_abi_names = loongarch_f_alias;
for (i = 0; i < ARRAY_SIZE (loongarch_f_alias); i++)
{
- str_hash_insert (f_htab, loongarch_f_alias[i],
- (void *) (i + 1), 0);
- str_hash_insert (cfi_f_htab, loongarch_f_alias[i],
- (void *) (i + 1), 0);
+ str_hash_insert_int (f_htab, loongarch_f_alias[i], i, 0);
+ str_hash_insert_int (cfi_f_htab, loongarch_f_alias[i], i, 0);
}
for (i = 0; i < ARRAY_SIZE (loongarch_f_alias_deprecated); i++)
- str_hash_insert (f_deprecated_htab, loongarch_f_alias_deprecated[i],
- (void *) (i + 1), 0);
+ str_hash_insert_int (f_deprecated_htab, loongarch_f_alias_deprecated[i],
+ i, 0);
/* The .cfi directive supports register aliases without the "$" prefix. */
for (i = 0; i < ARRAY_SIZE (loongarch_f_cfi_name); i++)
{
- str_hash_insert (cfi_f_htab, loongarch_f_cfi_name[i],
- (void *)(i + 1), 0);
- str_hash_insert (cfi_f_htab, loongarch_f_cfi_name_alias[i],
- (void *)(i + 1), 0);
+ str_hash_insert_int (cfi_f_htab, loongarch_f_cfi_name[i], i, 0);
+ str_hash_insert_int (cfi_f_htab, loongarch_f_cfi_name_alias[i], i, 0);
}
if (!fc_htab)
- fc_htab = str_htab_create (), str_hash_insert (fc_htab, "", 0, 0);
+ fc_htab = str_htab_create ();
for (i = 0; i < ARRAY_SIZE (loongarch_fc_normal_name); i++)
- str_hash_insert (fc_htab, loongarch_fc_normal_name[i], (void *) (i + 1),
- 0);
+ str_hash_insert_int (fc_htab, loongarch_fc_normal_name[i], i, 0);
if (!fcn_htab)
- fcn_htab = str_htab_create (), str_hash_insert (fcn_htab, "", 0, 0);
+ fcn_htab = str_htab_create ();
for (i = 0; i < ARRAY_SIZE (loongarch_fc_numeric_name); i++)
- str_hash_insert (fcn_htab, loongarch_fc_numeric_name[i], (void *) (i + 1),
- 0);
+ str_hash_insert_int (fcn_htab, loongarch_fc_numeric_name[i], i, 0);
if (!c_htab)
- c_htab = str_htab_create (), str_hash_insert (c_htab, "", 0, 0);
+ c_htab = str_htab_create ();
for (i = 0; i < ARRAY_SIZE (loongarch_c_normal_name); i++)
- str_hash_insert (c_htab, loongarch_c_normal_name[i], (void *) (i + 1),
- 0);
+ str_hash_insert_int (c_htab, loongarch_c_normal_name[i], i, 0);
}
if (LARCH_opts.ase_lsx)
{
if (!v_htab)
- v_htab = str_htab_create (), str_hash_insert (v_htab, "", 0, 0);
+ v_htab = str_htab_create ();
for (i = 0; i < ARRAY_SIZE (loongarch_v_normal_name); i++)
- str_hash_insert (v_htab, loongarch_v_normal_name[i], (void *) (i + 1),
- 0);
+ str_hash_insert_int (v_htab, loongarch_v_normal_name[i], i, 0);
}
/* Init lasx registers names. */
if (LARCH_opts.ase_lasx)
{
if (!x_htab)
- x_htab = str_htab_create (), str_hash_insert (x_htab, "", 0, 0);
+ x_htab = str_htab_create ();
for (i = 0; i < ARRAY_SIZE (loongarch_x_normal_name); i++)
- str_hash_insert (x_htab, loongarch_x_normal_name[i], (void *) (i + 1),
- 0);
+ str_hash_insert_int (x_htab, loongarch_x_normal_name[i], i, 0);
}
}
}
break;
case 'r':
- imm = (intptr_t) str_hash_find (r_htab, arg);
- ip->match_now = 0 < imm;
- ret = imm - 1;
+ imm = str_hash_find_int (r_htab, arg);
+ ip->match_now = 0 <= imm;
+ ret = imm;
if (ip->match_now)
break;
/* Handle potential usage of deprecated register aliases. */
- imm = (intptr_t) str_hash_find (r_deprecated_htab, arg);
- ip->match_now = 0 < imm;
- ret = imm - 1;
+ imm = str_hash_find_int (r_deprecated_htab, arg);
+ ip->match_now = 0 <= imm;
+ ret = imm;
/* !ip->expand_from_macro: avoiding duplicate output warnings,
only the first macro output warning. */
if (ip->match_now && !ip->expand_from_macro)
switch (esc_ch2)
{
case 'c':
- imm = (intptr_t) str_hash_find (fc_htab, arg);
- if (0 >= imm)
- {
- imm = (intptr_t) str_hash_find (fcn_htab, arg);
- }
+ imm = str_hash_find_int (fc_htab, arg);
+ if (0 > imm)
+ imm = str_hash_find_int (fcn_htab, arg);
break;
default:
- imm = (intptr_t) str_hash_find (f_htab, arg);
+ imm = str_hash_find_int (f_htab, arg);
}
- ip->match_now = 0 < imm;
- ret = imm - 1;
+ ip->match_now = 0 <= imm;
+ ret = imm;
if (ip->match_now && !ip->expand_from_macro)
break;
/* Handle potential usage of deprecated register aliases. */
- imm = (intptr_t) str_hash_find (f_deprecated_htab, arg);
- ip->match_now = 0 < imm;
- ret = imm - 1;
+ imm = str_hash_find_int (f_deprecated_htab, arg);
+ ip->match_now = 0 <= imm;
+ ret = imm;
if (ip->match_now)
as_warn (_("register alias %s is deprecated, use %s instead"),
arg, f_abi_names[ret]);
switch (esc_ch2)
{
case 'r':
- imm = (intptr_t) str_hash_find (cr_htab, arg);
+ imm = str_hash_find_int (cr_htab, arg);
break;
default:
- imm = (intptr_t) str_hash_find (c_htab, arg);
+ imm = str_hash_find_int (c_htab, arg);
}
- ip->match_now = 0 < imm;
- ret = imm - 1;
+ ip->match_now = 0 <= imm;
+ ret = imm;
break;
case 'v':
- imm = (intptr_t) str_hash_find (v_htab, arg);
- ip->match_now = 0 < imm;
- ret = imm - 1;
+ imm = str_hash_find_int (v_htab, arg);
+ ip->match_now = 0 <= imm;
+ ret = imm;
break;
case 'x':
- imm = (intptr_t) str_hash_find (x_htab, arg);
- ip->match_now = 0 < imm;
- ret = imm - 1;
+ imm = str_hash_find_int (x_htab, arg);
+ ip->match_now = 0 <= imm;
+ ret = imm;
break;
case '\0':
ip->all_match = ip->match_now;
int reg;
/* Look up in the general purpose register table. */
- if ((reg = (intptr_t) str_hash_find (cfi_r_htab, regname)) > 0)
- return reg - 1;
+ if ((reg = str_hash_find_int (cfi_r_htab, regname)) >= 0)
+ return reg;
/* Look up in the floating point register table. */
- if ((reg = (intptr_t) str_hash_find (cfi_f_htab, regname)) > 0)
- return reg + 31;
+ if ((reg = str_hash_find_int (cfi_f_htab, regname)) >= 0)
+ return reg + 32;
as_bad (_("unknown register `%s`"), regname);
return -1;
nds32_elf_append_relax_relocs_traverse (void **slot, void *arg ATTRIBUTE_UNUSED)
{
string_tuple_t *tuple = *((string_tuple_t **) slot);
- nds32_elf_append_relax_relocs (tuple->key, tuple->value);
+ nds32_elf_append_relax_relocs (tuple->key, (void *) tuple->value);
return 1;
}
static htab_t csr_extra_hash = NULL;
#define ENCODE_REG_HASH(cls, n) \
- ((void *)(uintptr_t)((n) * RCLASS_MAX + (cls) + 1))
-#define DECODE_REG_CLASS(hash) (((uintptr_t)(hash) - 1) % RCLASS_MAX)
-#define DECODE_REG_NUM(hash) (((uintptr_t)(hash) - 1) / RCLASS_MAX)
+ ((n) * RCLASS_MAX + (cls) + 1)
+#define DECODE_REG_CLASS(hash) (((hash) - 1) % RCLASS_MAX)
+#define DECODE_REG_NUM(hash) (((hash) - 1) / RCLASS_MAX)
static void
hash_reg_name (enum reg_class class, const char *name, unsigned n)
{
- void *hash = ENCODE_REG_HASH (class, n);
- if (str_hash_insert (reg_names_hash, name, hash, 0) != NULL)
+ uintptr_t hash = ENCODE_REG_HASH (class, n);
+ if (str_hash_insert_int (reg_names_hash, name, hash, 0) != NULL)
as_fatal (_("internal: duplicate %s"), name);
}
static unsigned int
reg_lookup_internal (const char *s, enum reg_class class)
{
- void *r;
+ uintptr_t r;
if (class == RCLASS_CSR)
return reg_csr_lookup_internal (s);
- r = str_hash_find (reg_names_hash, s);
- if (r == NULL || DECODE_REG_CLASS (r) != class)
+ r = str_hash_find_int (reg_names_hash, s);
+ if (r == (uintptr_t) -1 || DECODE_REG_CLASS (r) != class)
return -1;
if (riscv_subset_supports (&riscv_rps_as, "e")
/* Initialize special operator hash table. */
special_operator_hash = str_htab_create ();
#define INSERT_SPECIAL_OP(name) \
- str_hash_insert (special_operator_hash, #name, (void *) O_##name, 0)
+ str_hash_insert_int (special_operator_hash, #name, O_##name, 0)
INSERT_SPECIAL_OP (hw0);
INSERT_SPECIAL_OP (hw1);
INSERT_SPECIAL_OP (hw1_last);
INSERT_SPECIAL_OP (hw2_last);
/* hw3_last is a convenience alias for the equivalent hw3. */
- str_hash_insert (special_operator_hash, "hw3_last", (void *) O_hw3, 0);
+ str_hash_insert_int (special_operator_hash, "hw3_last", O_hw3, 0);
INSERT_SPECIAL_OP (hw0_got);
INSERT_SPECIAL_OP (hw0_last_got);
INSERT_SPECIAL_OP (hw1_last_got);
{
char buf[64];
- str_hash_insert (main_reg_hash, tilegx_register_names[i],
- (void *) (long) (i | CANONICAL_REG_NAME_FLAG), 0);
+ str_hash_insert_int (main_reg_hash, tilegx_register_names[i],
+ i | CANONICAL_REG_NAME_FLAG, 0);
/* See if we should insert a noncanonical alias, like r63. */
sprintf (buf, "r%d", i);
if (strcmp (buf, tilegx_register_names[i]) != 0)
- str_hash_insert (main_reg_hash, xstrdup (buf),
- (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG), 0);
+ str_hash_insert_int (main_reg_hash, xstrdup (buf),
+ i | NONCANONICAL_REG_NAME_FLAG, 0);
}
}
else
{
/* Look up the operator in our table. */
- void* val = str_hash_find (special_operator_hash, name);
- if (val == 0)
+ int opint = str_hash_find_int (special_operator_hash, name);
+ if (opint < 0)
return 0;
- op = (operatorT)(long)val;
+ op = opint;
}
/* Restore old '(' and skip it. */
static void
parse_reg_expression (expressionS* expression)
{
- char *regname;
- char terminating_char;
- void *pval;
- int regno_and_flags;
- int regno;
-
/* Zero everything to make sure we don't miss any flags. */
memset (expression, 0, sizeof *expression);
- terminating_char = get_symbol_name (®name);
+ char *regname;
+ char terminating_char = get_symbol_name (®name);
- pval = str_hash_find (main_reg_hash, regname);
- if (pval == NULL)
+ int regno_and_flags = str_hash_find_int (main_reg_hash, regname);
+ if (regno_and_flags < 0)
as_bad (_("Expected register, got '%s'."), regname);
- regno_and_flags = (int)(size_t)pval;
- regno = EXTRACT_REGNO(regno_and_flags);
+ int regno = EXTRACT_REGNO(regno_and_flags);
if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG)
&& require_canonical_reg_names)
/* Initialize special operator hash table. */
special_operator_hash = str_htab_create ();
#define INSERT_SPECIAL_OP(name) \
- str_hash_insert (special_operator_hash, #name, (void *) O_##name, 0)
+ str_hash_insert_int (special_operator_hash, #name, O_##name, 0)
INSERT_SPECIAL_OP(lo16);
INSERT_SPECIAL_OP(hi16);
{
char buf[64];
- str_hash_insert (main_reg_hash, tilepro_register_names[i],
- (void *) (long) (i | CANONICAL_REG_NAME_FLAG), 0);
+ str_hash_insert_int (main_reg_hash, tilepro_register_names[i],
+ i | CANONICAL_REG_NAME_FLAG, 0);
/* See if we should insert a noncanonical alias, like r63. */
sprintf (buf, "r%d", i);
if (strcmp (buf, tilepro_register_names[i]) != 0)
- str_hash_insert (main_reg_hash, xstrdup (buf),
- (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG), 0);
+ str_hash_insert_int (main_reg_hash, xstrdup (buf),
+ i | NONCANONICAL_REG_NAME_FLAG, 0);
}
/* Insert obsolete backwards-compatibility register names. */
- str_hash_insert (main_reg_hash, "io0",
- (void *) (long) (TREG_IDN0 | CANONICAL_REG_NAME_FLAG), 0);
- str_hash_insert (main_reg_hash, "io1",
- (void *) (long) (TREG_IDN1 | CANONICAL_REG_NAME_FLAG), 0);
- str_hash_insert (main_reg_hash, "us0",
- (void *) (long) (TREG_UDN0 | CANONICAL_REG_NAME_FLAG), 0);
- str_hash_insert (main_reg_hash, "us1",
- (void *) (long) (TREG_UDN1 | CANONICAL_REG_NAME_FLAG), 0);
- str_hash_insert (main_reg_hash, "us2",
- (void *) (long) (TREG_UDN2 | CANONICAL_REG_NAME_FLAG), 0);
- str_hash_insert (main_reg_hash, "us3",
- (void *) (long) (TREG_UDN3 | CANONICAL_REG_NAME_FLAG), 0);
+ str_hash_insert_int (main_reg_hash, "io0",
+ TREG_IDN0 | CANONICAL_REG_NAME_FLAG, 0);
+ str_hash_insert_int (main_reg_hash, "io1",
+ TREG_IDN1 | CANONICAL_REG_NAME_FLAG, 0);
+ str_hash_insert_int (main_reg_hash, "us0",
+ TREG_UDN0 | CANONICAL_REG_NAME_FLAG, 0);
+ str_hash_insert_int (main_reg_hash, "us1",
+ TREG_UDN1 | CANONICAL_REG_NAME_FLAG, 0);
+ str_hash_insert_int (main_reg_hash, "us2",
+ TREG_UDN2 | CANONICAL_REG_NAME_FLAG, 0);
+ str_hash_insert_int (main_reg_hash, "us3",
+ TREG_UDN3 | CANONICAL_REG_NAME_FLAG, 0);
}
else
{
/* Look up the operator in our table. */
- void *val = str_hash_find (special_operator_hash, name);
- if (val == 0)
+ int opint = str_hash_find_int (special_operator_hash, name);
+ if (opint < 0)
return 0;
- op = (operatorT)(long)val;
+ op = opint;
}
/* Restore old '(' and skip it. */
char *regname;
char terminating_char = get_symbol_name (®name);
- void* pval = str_hash_find (main_reg_hash, regname);
-
- if (pval == NULL)
+ int regno_and_flags = str_hash_find_int (main_reg_hash, regname);
+ if (regno_and_flags < 0)
as_bad (_("Expected register, got '%s'."), regname);
- int regno_and_flags = (int)(size_t)pval;
int regno = EXTRACT_REGNO(regno_and_flags);
if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG)
struct string_tuple
{
const char *key;
- const void *value;
+ intptr_t value;
};
typedef struct string_tuple string_tuple_t;
/* Inline string hash table functions. */
static inline string_tuple_t *
-string_tuple_alloc (htab_t table, const char *key, const void *value)
+string_tuple_alloc (htab_t table, const char *key, intptr_t value)
{
string_tuple_t *tuple = table->alloc_f (1, sizeof (*tuple));
tuple->key = key;
static inline void *
str_hash_find (htab_t table, const char *key)
{
- string_tuple_t needle = { key, NULL };
+ string_tuple_t needle = { key, 0 };
string_tuple_t *tuple = htab_find (table, &needle);
return tuple != NULL ? (void *) tuple->value : NULL;
}
+static inline intptr_t
+str_hash_find_int (htab_t table, const char *key)
+{
+ string_tuple_t needle = { key, 0 };
+ string_tuple_t *tuple = htab_find (table, &needle);
+ return tuple != NULL ? tuple->value : -1;
+}
+
static inline void *
str_hash_find_n (htab_t table, const char *key, size_t n)
{
char *tmp = XNEWVEC (char, n + 1);
memcpy (tmp, key, n);
tmp[n] = '\0';
- string_tuple_t needle = { tmp, NULL };
+ string_tuple_t needle = { tmp, 0 };
string_tuple_t *tuple = htab_find (table, &needle);
free (tmp);
return tuple != NULL ? (void *) tuple->value : NULL;
static inline void
str_hash_delete (htab_t table, const char *key)
{
- string_tuple_t needle = { key, NULL };
+ string_tuple_t needle = { key, 0 };
htab_remove_elt (table, &needle);
}
static inline void **
-str_hash_insert (htab_t table, const char *key, const void *value, int replace)
+str_hash_insert_int (htab_t table, const char *key, intptr_t value, int replace)
{
string_tuple_t *elt = string_tuple_alloc (table, key, value);
void **slot = htab_insert (table, elt, replace);
return slot;
}
+static inline void **
+str_hash_insert (htab_t table, const char *key, const void *value, int replace)
+{
+ return str_hash_insert_int (table, key, (intptr_t) value, replace);
+}
+
static inline htab_t
str_htab_create (void)
{