summaryrefslogtreecommitdiff
path: root/src/apk_atom.h
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2020-05-19 11:39:21 +0300
committerTimo Teräs <timo.teras@iki.fi>2020-05-19 12:02:56 +0300
commitd0edeec8fb8fa5abee8b3065cea5e4882d0c51c4 (patch)
tree10dbc6d72c9cef13a26cb539df43e92e4bf78d74 /src/apk_atom.h
parent12fdf6fc219321d22825042ae08efd322acc0310 (diff)
downloadapk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.gz
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.bz2
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.xz
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.zip
make the atom functions not use global state
This greatly helps with memory management on applications that may want to daemonize and open/close database several times. Also the lifetime and "owner" of memory for all data is now explicitly bound to owning struct apk_database, which might be helpful when writing language bindings. As side effect, the interned "atoms" are unique only within what apk_database, so comparing packages from different apk_database may not work as expected. Fixes #10697
Diffstat (limited to 'src/apk_atom.h')
-rw-r--r--src/apk_atom.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/apk_atom.h b/src/apk_atom.h
new file mode 100644
index 0000000..1b6ad6c
--- /dev/null
+++ b/src/apk_atom.h
@@ -0,0 +1,33 @@
+/* apk_atom.h - Alpine Package Keeper (APK)
+ *
+ * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
+ * Copyright (C) 2008-2020 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ */
+
+#ifndef APK_ATOM_H
+#define APK_ATOM_H
+
+#include "apk_hash.h"
+#include "apk_blob.h"
+
+extern apk_blob_t apk_atom_null;
+
+struct apk_atom_pool {
+ struct apk_hash hash;
+};
+
+void apk_atom_init(struct apk_atom_pool *);
+void apk_atom_free(struct apk_atom_pool *);
+apk_blob_t *apk_atom_get(struct apk_atom_pool *atoms, apk_blob_t blob, int duplicate);
+
+static inline apk_blob_t *apk_atomize(struct apk_atom_pool *atoms, apk_blob_t blob) {
+ return apk_atom_get(atoms, blob, 0);
+}
+static inline apk_blob_t *apk_atomize_dup(struct apk_atom_pool *atoms, apk_blob_t blob) {
+ return apk_atom_get(atoms, blob, 1);
+}
+
+#endif