[DTrace-devel] [PATCH 09/17] htab: move htab handling to libcommon
Kris Van Hees
kris.van.hees at oracle.com
Sat Jun 7 06:15:01 UTC 2025
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Nick Alcock <nick.alcock at oracle.com>
---
libcommon/Build | 3 ++-
{libdtrace => libcommon}/dt_htab.c | 19 +++++++++----------
{libdtrace => libcommon}/dt_htab.h | 8 +++-----
libdtrace/Build | 1 -
libdtrace/dt_consume.c | 4 ++--
libdtrace/dt_kernel_module.c | 4 ++--
libdtrace/dt_module.c | 2 +-
libdtrace/dt_open.c | 10 +++++-----
libdtrace/dt_probe.c | 22 +++++++++++-----------
libdtrace/dt_provider.c | 4 ++--
libdtrace/dt_symtab.c | 2 +-
11 files changed, 38 insertions(+), 41 deletions(-)
rename {libdtrace => libcommon}/dt_htab.c (95%)
rename {libdtrace => libcommon}/dt_htab.h (91%)
diff --git a/libcommon/Build b/libcommon/Build
index f64545ed..6237351f 100644
--- a/libcommon/Build
+++ b/libcommon/Build
@@ -9,7 +9,8 @@ LIBS += libcommon
libcommon_TARGET = libcommon
libcommon_DIR := $(current-dir)
libcommon_CPPFLAGS := -Ilibcommon -Ilibproc -U_FORTIFY_SOURCE
-libcommon_SOURCES = usdt_parser.c usdt_parser_dof.c usdt_parser_host.c dt_list.c
+libcommon_SOURCES = dt_htab.c dt_list.c \
+ usdt_parser.c usdt_parser_dof.c usdt_parser_host.c
libcommon_NOCFLAGS := -D_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -D_FORTIFY_SOURCE=2 -D_FORTIFY_SOURCE=3 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=1 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=2 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3
libcommon_NOCPPFLAGS := -D_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -D_FORTIFY_SOURCE=2 -D_FORTIFY_SOURCE=3 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=1 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=2 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3
libcommon_LIBSOURCES = libcommon
diff --git a/libdtrace/dt_htab.c b/libcommon/dt_htab.c
similarity index 95%
rename from libdtrace/dt_htab.c
rename to libcommon/dt_htab.c
index 478c728a..43782202 100644
--- a/libdtrace/dt_htab.c
+++ b/libcommon/dt_htab.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -28,8 +28,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
-
-#include "dt_impl.h"
+#include <dt_htab.h>
typedef struct dt_hbucket dt_hbucket_t;
struct dt_hbucket {
@@ -66,9 +65,9 @@ struct dt_htab_next {
/*
* Create a new (empty) hashtable.
*/
-dt_htab_t *dt_htab_create(dtrace_hdl_t *dtp, dt_htab_ops_t *ops)
+dt_htab_t *dt_htab_create(dt_htab_ops_t *ops)
{
- dt_htab_t *htab = dt_alloc(dtp, sizeof(dt_htab_t));
+ dt_htab_t *htab = malloc(sizeof(dt_htab_t));
if (!htab)
return NULL;
@@ -79,9 +78,9 @@ dt_htab_t *dt_htab_create(dtrace_hdl_t *dtp, dt_htab_ops_t *ops)
htab->nentries = 0;
htab->ops = ops;
- htab->tab = dt_calloc(dtp, htab->size, sizeof(dt_hbucket_t *));
+ htab->tab = calloc(htab->size, sizeof(dt_hbucket_t *));
if (!htab->tab) {
- dt_free(dtp, htab);
+ free(htab);
return NULL;
}
@@ -91,7 +90,7 @@ dt_htab_t *dt_htab_create(dtrace_hdl_t *dtp, dt_htab_ops_t *ops)
/*
* Destroy a hashtable, deleting all its entries first.
*/
-void dt_htab_destroy(dtrace_hdl_t *dtp, dt_htab_t *htab)
+void dt_htab_destroy(dt_htab_t *htab)
{
size_t i;
@@ -112,8 +111,8 @@ void dt_htab_destroy(dtrace_hdl_t *dtp, dt_htab_t *htab)
};
}
- dt_free(dtp, htab->tab);
- dt_free(dtp, htab);
+ free(htab->tab);
+ free(htab);
}
/*
diff --git a/libdtrace/dt_htab.h b/libcommon/dt_htab.h
similarity index 91%
rename from libdtrace/dt_htab.h
rename to libcommon/dt_htab.h
index d39ae65e..906c91fd 100644
--- a/libdtrace/dt_htab.h
+++ b/libcommon/dt_htab.h
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -12,8 +12,6 @@
extern "C" {
#endif
-struct dtrace_hdl;
-
typedef uint32_t (*htab_hval_fn)(const void *);
typedef int (*htab_cmp_fn)(const void *, const void *);
typedef void *(*htab_add_fn)(void *, void *);
@@ -93,8 +91,8 @@ typedef struct dt_hentry {
typedef struct dt_htab dt_htab_t;
typedef struct dt_htab_next dt_htab_next_t;
-extern dt_htab_t *dt_htab_create(struct dtrace_hdl *dtp, dt_htab_ops_t *ops);
-extern void dt_htab_destroy(struct dtrace_hdl *dtp, dt_htab_t *htab);
+extern dt_htab_t *dt_htab_create(dt_htab_ops_t *ops);
+extern void dt_htab_destroy(dt_htab_t *htab);
extern int dt_htab_insert(dt_htab_t *htab, void *entry);
extern void *dt_htab_lookup(const dt_htab_t *htab, const void *entry);
typedef int dt_htab_ecmp_fn(const void *entry, void *arg);
diff --git a/libdtrace/Build b/libdtrace/Build
index 7e6e8a38..219ff9b3 100644
--- a/libdtrace/Build
+++ b/libdtrace/Build
@@ -28,7 +28,6 @@ libdtrace-build_SOURCES = dt_aggregate.c \
dt_errtags.c \
dt_grammar.c \
dt_handle.c \
- dt_htab.c \
dt_ident.c \
dt_lex.c \
dt_link.c \
diff --git a/libdtrace/dt_consume.c b/libdtrace/dt_consume.c
index 9088a90d..b0bf73d1 100644
--- a/libdtrace/dt_consume.c
+++ b/libdtrace/dt_consume.c
@@ -3011,7 +3011,7 @@ dt_consume_proc_exits(dtrace_hdl_t *dtp)
int
dt_consume_init(dtrace_hdl_t *dtp)
{
- dtp->dt_spec_bufs = dt_htab_create(dtp, &dt_spec_buf_htab_ops);
+ dtp->dt_spec_bufs = dt_htab_create(&dt_spec_buf_htab_ops);
if (!dtp->dt_spec_bufs)
return dt_set_errno(dtp, EDT_NOMEM);
@@ -3028,7 +3028,7 @@ dt_consume_fini(dtrace_hdl_t *dtp)
dt_free(dtp, dtsd);
}
- dt_htab_destroy(dtp, dtp->dt_spec_bufs);
+ dt_htab_destroy(dtp->dt_spec_bufs);
}
dtrace_workstatus_t
diff --git a/libdtrace/dt_kernel_module.c b/libdtrace/dt_kernel_module.c
index e21ecc51..baeabeab 100644
--- a/libdtrace/dt_kernel_module.c
+++ b/libdtrace/dt_kernel_module.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -75,7 +75,7 @@ dt_kern_path_create(dtrace_hdl_t *dtp, char *name, char *path)
dt_kern_path_t tmpl;
if (!dtp->dt_kernpaths) {
- dtp->dt_kernpaths = dt_htab_create(dtp, &kernpath_htab_ops);
+ dtp->dt_kernpaths = dt_htab_create(&kernpath_htab_ops);
if (!dtp->dt_kernpaths)
return NULL; /* caller must handle allocation failure */
diff --git a/libdtrace/dt_module.c b/libdtrace/dt_module.c
index d45947d7..b3c8e247 100644
--- a/libdtrace/dt_module.c
+++ b/libdtrace/dt_module.c
@@ -138,7 +138,7 @@ dt_module_create(dtrace_hdl_t *dtp, const char *name)
dt_module_t *dmp;
if (!dtp->dt_mods) {
- dtp->dt_mods = dt_htab_create(dtp, &dt_module_htab_ops);
+ dtp->dt_mods = dt_htab_create(&dt_module_htab_ops);
if (!dtp->dt_mods)
return NULL;
}
diff --git a/libdtrace/dt_open.c b/libdtrace/dt_open.c
index 0bda3504..01c36a76 100644
--- a/libdtrace/dt_open.c
+++ b/libdtrace/dt_open.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -1270,10 +1270,10 @@ dtrace_close(dtrace_hdl_t *dtp)
dt_idhash_destroy(dtp->dt_bpfsyms);
- dt_htab_destroy(dtp, dtp->dt_kernsyms);
+ dt_htab_destroy(dtp->dt_kernsyms);
dtp->dt_kernsyms = NULL;
- dt_htab_destroy(dtp, dtp->dt_mods);
- dt_htab_destroy(dtp, dtp->dt_kernpaths);
+ dt_htab_destroy(dtp->dt_mods);
+ dt_htab_destroy(dtp->dt_kernpaths);
if (dtp->dt_shared_btf != NULL)
dt_btf_destroy(dtp, dtp->dt_shared_btf);
@@ -1303,7 +1303,7 @@ dtrace_close(dtrace_hdl_t *dtp)
dt_dof_fini(dtp);
dt_probe_fini(dtp);
- dt_htab_destroy(dtp, dtp->dt_provs);
+ dt_htab_destroy(dtp->dt_provs);
for (i = 1; i < dtp->dt_cpp_argc; i++)
free(dtp->dt_cpp_argv[i]);
diff --git a/libdtrace/dt_probe.c b/libdtrace/dt_probe.c
index ccaa3081..28a1133f 100644
--- a/libdtrace/dt_probe.c
+++ b/libdtrace/dt_probe.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -1278,11 +1278,11 @@ dt_probe_dependent_iter(dtrace_hdl_t *dtp, const dt_probe_t *prp,
void
dt_probe_init(dtrace_hdl_t *dtp)
{
- dtp->dt_byprv = dt_htab_create(dtp, &prv_htab_ops);
- dtp->dt_bymod = dt_htab_create(dtp, &mod_htab_ops);
- dtp->dt_byfun = dt_htab_create(dtp, &fun_htab_ops);
- dtp->dt_byprb = dt_htab_create(dtp, &prb_htab_ops);
- dtp->dt_byfqn = dt_htab_create(dtp, &fqn_htab_ops);
+ dtp->dt_byprv = dt_htab_create(&prv_htab_ops);
+ dtp->dt_bymod = dt_htab_create(&mod_htab_ops);
+ dtp->dt_byfun = dt_htab_create(&fun_htab_ops);
+ dtp->dt_byprb = dt_htab_create(&prb_htab_ops);
+ dtp->dt_byfqn = dt_htab_create(&fqn_htab_ops);
dtp->dt_probes = NULL;
dtp->dt_probes_sz = 0;
@@ -1315,11 +1315,11 @@ dt_probe_fini(dtrace_hdl_t *dtp)
dt_probe_destroy(prp);
}
- dt_htab_destroy(dtp, dtp->dt_byprv);
- dt_htab_destroy(dtp, dtp->dt_bymod);
- dt_htab_destroy(dtp, dtp->dt_byfun);
- dt_htab_destroy(dtp, dtp->dt_byprb);
- dt_htab_destroy(dtp, dtp->dt_byfqn);
+ dt_htab_destroy(dtp->dt_byprv);
+ dt_htab_destroy(dtp->dt_bymod);
+ dt_htab_destroy(dtp->dt_byfun);
+ dt_htab_destroy(dtp->dt_byprb);
+ dt_htab_destroy(dtp->dt_byfqn);
dtp->dt_byprv = NULL;
dtp->dt_bymod = NULL;
dtp->dt_byfun = NULL;
diff --git a/libdtrace/dt_provider.c b/libdtrace/dt_provider.c
index 06f0b039..0c459aba 100644
--- a/libdtrace/dt_provider.c
+++ b/libdtrace/dt_provider.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -90,7 +90,7 @@ static dt_provider_t *
dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp)
{
if (!dtp->dt_provs) {
- dtp->dt_provs = dt_htab_create(dtp, &dt_provider_htab_ops);
+ dtp->dt_provs = dt_htab_create(&dt_provider_htab_ops);
if (dtp->dt_provs == NULL)
return NULL;
}
diff --git a/libdtrace/dt_symtab.c b/libdtrace/dt_symtab.c
index 3819c21d..62c458f3 100644
--- a/libdtrace/dt_symtab.c
+++ b/libdtrace/dt_symtab.c
@@ -167,7 +167,7 @@ dt_symtab_create(dtrace_hdl_t *dtp)
dt_symtab_t *symtab;
if (!dtp->dt_kernsyms) {
- dtp->dt_kernsyms = dt_htab_create(dtp, &dt_symtab_htab_ops);
+ dtp->dt_kernsyms = dt_htab_create(&dt_symtab_htab_ops);
if (!dtp->dt_kernsyms)
return NULL;
--
2.45.2
More information about the DTrace-devel
mailing list