summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/atom.c21
-rw-r--r--src/atom.h3
-rw-r--r--src/context-priv.c8
-rw-r--r--src/utils.h7
-rw-r--r--src/xkbcomp/parser.y4
-rw-r--r--test/atom.c8
6 files changed, 12 insertions, 39 deletions
diff --git a/src/atom.c b/src/atom.c
index 044f566..0f9d54e 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -183,14 +183,8 @@ atom_lookup(struct atom_table *table, const char *string, size_t len)
return *atomp;
}
-/*
- * If steal is true, we do not strdup @string; therefore it must be
- * dynamically allocated, NUL-terminated, not be free'd by the caller
- * and not be used afterwards. Use to avoid some redundant allocations.
- */
xkb_atom_t
-atom_intern(struct atom_table *table, const char *string, size_t len,
- bool steal)
+atom_intern(struct atom_table *table, const char *string, size_t len)
{
xkb_atom_t *atomp;
struct atom_node node;
@@ -200,19 +194,12 @@ atom_intern(struct atom_table *table, const char *string, size_t len,
return XKB_ATOM_NONE;
if (find_atom_pointer(table, string, len, &atomp, &fingerprint)) {
- if (steal)
- free(UNCONSTIFY(string));
return *atomp;
}
- if (steal) {
- node.string = UNCONSTIFY(string);
- }
- else {
- node.string = strndup(string, len);
- if (!node.string)
- return XKB_ATOM_NONE;
- }
+ node.string = strndup(string, len);
+ if (!node.string)
+ return XKB_ATOM_NONE;
node.left = node.right = XKB_ATOM_NONE;
node.fingerprint = fingerprint;
diff --git a/src/atom.h b/src/atom.h
index 1bf8e49..f936911 100644
--- a/src/atom.h
+++ b/src/atom.h
@@ -40,8 +40,7 @@ xkb_atom_t
atom_lookup(struct atom_table *table, const char *string, size_t len);
xkb_atom_t
-atom_intern(struct atom_table *table, const char *string, size_t len,
- bool steal);
+atom_intern(struct atom_table *table, const char *string, size_t len);
const char *
atom_text(struct atom_table *table, xkb_atom_t atom);
diff --git a/src/context-priv.c b/src/context-priv.c
index c934201..e3ba32d 100644
--- a/src/context-priv.c
+++ b/src/context-priv.c
@@ -58,13 +58,7 @@ xkb_atom_lookup(struct xkb_context *ctx, const char *string)
xkb_atom_t
xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len)
{
- return atom_intern(ctx->atom_table, string, len, false);
-}
-
-xkb_atom_t
-xkb_atom_steal(struct xkb_context *ctx, char *string)
-{
- return atom_intern(ctx->atom_table, string, strlen(string), true);
+ return atom_intern(ctx->atom_table, string, len);
}
const char *
diff --git a/src/utils.h b/src/utils.h
index d823e74..ebf3601 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -32,13 +32,6 @@
#include "darray.h"
-/*
- * We sometimes malloc strings and then expose them as const char*'s. This
- * macro is used when we free these strings in order to avoid -Wcast-qual
- * errors.
- */
-#define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr))
-
#define STATIC_ASSERT(expr, message) do { \
switch (0) { case 0: case (expr): ; } \
} while (0)
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 296ce19..f33a850 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -747,11 +747,11 @@ Integer : INTEGER { $$ = $1; }
KeyCode : INTEGER { $$ = $1; }
;
-Ident : IDENT { $$ = xkb_atom_steal(param->ctx, $1); }
+Ident : IDENT { $$ = xkb_atom_intern(param->ctx, $1, strlen($1)); free($1); }
| DEFAULT { $$ = xkb_atom_intern_literal(param->ctx, "default"); }
;
-String : STRING { $$ = xkb_atom_steal(param->ctx, $1); }
+String : STRING { $$ = xkb_atom_intern(param->ctx, $1, strlen($1)); free($1); }
;
OptMapName : MapName { $$ = $1; }
diff --git a/test/atom.c b/test/atom.c
index bcb369a..1d9ab85 100644
--- a/test/atom.c
+++ b/test/atom.c
@@ -27,7 +27,7 @@
#include "atom.h"
#define INTERN_LITERAL(table, literal) \
- atom_intern(table, literal, sizeof(literal) - 1, false)
+ atom_intern(table, literal, sizeof(literal) - 1)
#define LOOKUP_LITERAL(table, literal) \
atom_lookup(table, literal, sizeof(literal) - 1)
@@ -105,7 +105,7 @@ test_random_strings(void)
continue;
}
- arr[i].atom = atom_intern(table, arr[i].string, arr[i].len, false);
+ arr[i].atom = atom_intern(table, arr[i].string, arr[i].len);
if (arr[i].atom == XKB_ATOM_NONE) {
fprintf(stderr, "failed to intern! len: %lu, string: %.*s\n",
arr[i].len, (int) arr[i].len, arr[i].string);
@@ -161,7 +161,7 @@ main(void)
assert(atom1 == LOOKUP_LITERAL(table, "hello"));
assert(streq(atom_text(table, atom1), "hello"));
- atom2 = atom_intern(table, "hello", 3, false);
+ atom2 = atom_intern(table, "hello", 3);
assert(atom2 != XKB_ATOM_NONE);
assert(atom1 != atom2);
assert(streq(atom_text(table, atom2), "hel"));
@@ -169,7 +169,7 @@ main(void)
assert(LOOKUP_LITERAL(table, "hell") == XKB_ATOM_NONE);
assert(LOOKUP_LITERAL(table, "hello") == atom1);
- atom3 = atom_intern(table, "", 0, false);
+ atom3 = atom_intern(table, "", 0);
assert(atom3 != XKB_ATOM_NONE);
assert(LOOKUP_LITERAL(table, "") == atom3);