}
xkb_atom_t
-xkb_atom_intern(struct xkb_context *ctx, const char *string)
+xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len)
{
- return atom_intern(ctx->atom_table, string, strlen(string), false);
+ return atom_intern(ctx->atom_table, string, len, false);
}
xkb_atom_t
xkb_atom_lookup(struct xkb_context *ctx, const char *string);
xkb_atom_t
-xkb_atom_intern(struct xkb_context *ctx, const char *string);
+xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len);
+
+#define xkb_atom_intern_literal(ctx, literal) \
+ xkb_atom_intern((ctx), (literal), sizeof(literal) - 1)
/**
- * If @string is dynamically allocated, free'd immediately after
- * being interned, and not used afterwards, use this function
+ * If @string is dynamically allocated, NUL-terminated, free'd immediately
+ * after being interned, and not used afterwards, use this function
* instead of xkb_atom_intern to avoid some unnecessary allocations.
* The caller should not use or free the passed in string afterwards.
*/
* The order is important!
*/
darray_appends_t(keymap->mods, struct xkb_mod,
- { .name = xkb_atom_intern(ctx, "Shift"), .type = MOD_REAL },
- { .name = xkb_atom_intern(ctx, "Lock"), .type = MOD_REAL },
- { .name = xkb_atom_intern(ctx, "Control"), .type = MOD_REAL },
- { .name = xkb_atom_intern(ctx, "Mod1"), .type = MOD_REAL },
- { .name = xkb_atom_intern(ctx, "Mod2"), .type = MOD_REAL },
- { .name = xkb_atom_intern(ctx, "Mod3"), .type = MOD_REAL },
- { .name = xkb_atom_intern(ctx, "Mod4"), .type = MOD_REAL },
- { .name = xkb_atom_intern(ctx, "Mod5"), .type = MOD_REAL });
+ { .name = xkb_atom_intern_literal(ctx, "Shift"), .type = MOD_REAL },
+ { .name = xkb_atom_intern_literal(ctx, "Lock"), .type = MOD_REAL },
+ { .name = xkb_atom_intern_literal(ctx, "Control"), .type = MOD_REAL },
+ { .name = xkb_atom_intern_literal(ctx, "Mod1"), .type = MOD_REAL },
+ { .name = xkb_atom_intern_literal(ctx, "Mod2"), .type = MOD_REAL },
+ { .name = xkb_atom_intern_literal(ctx, "Mod3"), .type = MOD_REAL },
+ { .name = xkb_atom_intern_literal(ctx, "Mod4"), .type = MOD_REAL },
+ { .name = xkb_atom_intern_literal(ctx, "Mod5"), .type = MOD_REAL });
return true;
}
;
Element : ACTION_TOK
- { $$ = xkb_atom_intern(param->ctx, "action"); }
+ { $$ = xkb_atom_intern_literal(param->ctx, "action"); }
| INTERPRET
- { $$ = xkb_atom_intern(param->ctx, "interpret"); }
+ { $$ = xkb_atom_intern_literal(param->ctx, "interpret"); }
| TYPE
- { $$ = xkb_atom_intern(param->ctx, "type"); }
+ { $$ = xkb_atom_intern_literal(param->ctx, "type"); }
| KEY
- { $$ = xkb_atom_intern(param->ctx, "key"); }
+ { $$ = xkb_atom_intern_literal(param->ctx, "key"); }
| GROUP
- { $$ = xkb_atom_intern(param->ctx, "group"); }
+ { $$ = xkb_atom_intern_literal(param->ctx, "group"); }
| MODIFIER_MAP
- {$$ = xkb_atom_intern(param->ctx, "modifier_map");}
+ {$$ = xkb_atom_intern_literal(param->ctx, "modifier_map");}
| INDICATOR
- { $$ = xkb_atom_intern(param->ctx, "indicator"); }
+ { $$ = xkb_atom_intern_literal(param->ctx, "indicator"); }
| SHAPE
{ $$ = XKB_ATOM_NONE; }
| ROW
;
Ident : IDENT { $$ = xkb_atom_steal(param->ctx, $1); }
- | DEFAULT { $$ = xkb_atom_intern(param->ctx, "default"); }
+ | DEFAULT { $$ = xkb_atom_intern_literal(param->ctx, "default"); }
;
String : STRING { $$ = xkb_atom_steal(param->ctx, $1); }
return scanner_error(yylloc, s, "empty key name literal");
if (!buf_append(s, '\0') || !chr(s, '>'))
return scanner_error(yylloc, s, "unterminated key name literal");
- yylval->sval = xkb_atom_intern(s->ctx, s->buf);
+ yylval->sval = xkb_atom_intern(s->ctx, s->buf, s->buf_pos - 1);
return KEYNAME;
}
{
memset(keyi, 0, sizeof(*keyi));
keyi->merge = MERGE_OVERRIDE;
- keyi->name = xkb_atom_intern(ctx, "*");
+ keyi->name = xkb_atom_intern_literal(ctx, "*");
keyi->out_of_range_group_action = RANGE_WRAP;
}
darray_item(groupi->levels, level).u.syms[0])
if (width == 1 || width <= 0)
- return xkb_atom_intern(ctx, "ONE_LEVEL");
+ return xkb_atom_intern_literal(ctx, "ONE_LEVEL");
sym0 = GET_SYM(0);
sym1 = GET_SYM(1);
if (width == 2) {
if (xkb_keysym_is_lower(sym0) && xkb_keysym_is_upper(sym1))
- return xkb_atom_intern(ctx, "ALPHABETIC");
+ return xkb_atom_intern_literal(ctx, "ALPHABETIC");
if (xkb_keysym_is_keypad(sym0) || xkb_keysym_is_keypad(sym1))
- return xkb_atom_intern(ctx, "KEYPAD");
+ return xkb_atom_intern_literal(ctx, "KEYPAD");
- return xkb_atom_intern(ctx, "TWO_LEVEL");
+ return xkb_atom_intern_literal(ctx, "TWO_LEVEL");
}
if (width <= 4) {
sym3 = (width == 4 ? GET_SYM(3) : XKB_KEY_NoSymbol);
if (xkb_keysym_is_lower(sym2) && xkb_keysym_is_upper(sym3))
- return xkb_atom_intern(ctx, "FOUR_LEVEL_ALPHABETIC");
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_ALPHABETIC");
- return xkb_atom_intern(ctx, "FOUR_LEVEL_SEMIALPHABETIC");
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_SEMIALPHABETIC");
}
if (xkb_keysym_is_keypad(sym0) || xkb_keysym_is_keypad(sym1))
- return xkb_atom_intern(ctx, "FOUR_LEVEL_KEYPAD");
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_KEYPAD");
- return xkb_atom_intern(ctx, "FOUR_LEVEL");
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL");
}
return XKB_ATOM_NONE;
type->num_levels = 1;
type->entries = NULL;
type->num_entries = 0;
- type->name = xkb_atom_intern(keymap->ctx, "default");
+ type->name = xkb_atom_intern_literal(keymap->ctx, "default");
type->level_names = NULL;
return true;