Move dynamic-type to libcommon
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 22 Apr 2021 16:18:57 +0000 (12:18 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 23 Apr 2021 19:45:34 +0000 (15:45 -0400)
It is used by both liblttng-ust and liblttng-ust-ctl and contains no
shared state.

Change-Id: I51fc7a616d5e426a9286d873da29ffa661859f46
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/common/Makefile.am
src/common/dynamic-type.c [new file with mode: 0644]
src/lib/lttng-ust/Makefile.am
src/lib/lttng-ust/lttng-ust-dynamic-type.c [deleted file]

index ce427655fc82dc003cc3daed3ce33a7a22f0ed97..b5f8473bc97a452b0aa113d9e19d3cb49da81b58 100644 (file)
@@ -12,7 +12,6 @@ noinst_HEADERS = \
        bitmap.h \
        clock.h \
        creds.h \
-       dynamic-type.h \
        err-ptr.h \
        events.h \
        hash.h \
@@ -137,6 +136,8 @@ libsnprintf_la_SOURCES = \
 
 # Common library
 libcommon_la_SOURCES = \
+       dynamic-type.c \
+       dynamic-type.h \
        elf.c \
        elf.h \
        events.c \
diff --git a/src/common/dynamic-type.c b/src/common/dynamic-type.c
new file mode 100644 (file)
index 0000000..9350265
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * UST dynamic type implementation.
+ */
+
+#define _LGPL_SOURCE
+#include <stdio.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <inttypes.h>
+
+#include "common/macros.h"
+#include "common/dynamic-type.h"
+
+#define lttng_ust_field_enum_value(_string, _value)                                    \
+       LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_enum_entry, {               \
+               .struct_size = sizeof(struct lttng_ust_enum_entry),             \
+               .start = {                                              \
+                       .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
+                       .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
+                               (long long) (_value) : (_value),        \
+               },                                                      \
+               .end = {                                                \
+                       .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
+                       .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
+                               (long long) (_value) : (_value),        \
+               },                                                      \
+               .string = (_string),                                    \
+       }),
+
+static const struct lttng_ust_enum_entry *dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
+       [LTTNG_UST_DYNAMIC_TYPE_NONE] = lttng_ust_field_enum_value("_none", 0)
+       [LTTNG_UST_DYNAMIC_TYPE_S8] = lttng_ust_field_enum_value("_int8", 1)
+       [LTTNG_UST_DYNAMIC_TYPE_S16] = lttng_ust_field_enum_value("_int16", 2)
+       [LTTNG_UST_DYNAMIC_TYPE_S32] = lttng_ust_field_enum_value("_int32", 3)
+       [LTTNG_UST_DYNAMIC_TYPE_S64] = lttng_ust_field_enum_value("_int64", 4)
+       [LTTNG_UST_DYNAMIC_TYPE_U8] = lttng_ust_field_enum_value("_uint8", 5)
+       [LTTNG_UST_DYNAMIC_TYPE_U16] = lttng_ust_field_enum_value("_uint16", 6)
+       [LTTNG_UST_DYNAMIC_TYPE_U32] = lttng_ust_field_enum_value("_uint32", 7)
+       [LTTNG_UST_DYNAMIC_TYPE_U64] = lttng_ust_field_enum_value("_uint64", 8)
+       [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = lttng_ust_field_enum_value("_float", 9)
+       [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = lttng_ust_field_enum_value("_double", 10)
+       [LTTNG_UST_DYNAMIC_TYPE_STRING] = lttng_ust_field_enum_value("_string", 11)
+};
+
+static struct lttng_ust_enum_desc dt_enum_desc = {
+       .name = "dynamic_type_enum",
+       .entries = dt_enum,
+       .nr_entries = LTTNG_ARRAY_SIZE(dt_enum),
+};
+
+static const struct lttng_ust_event_field *dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
+       [LTTNG_UST_DYNAMIC_TYPE_NONE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "none",
+               .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_struct, {
+                       .parent = {
+                               .type = lttng_ust_type_struct,
+                       },
+                       .struct_size = sizeof(struct lttng_ust_type_struct),
+                       .nr_fields = 0, /* empty struct */
+                       .alignment = 0,
+               }),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_S8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "int8",
+               .type = lttng_ust_type_integer_define(int8_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_S16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "int16",
+               .type = lttng_ust_type_integer_define(int16_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_S32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "int32",
+               .type = lttng_ust_type_integer_define(int32_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_S64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "int64",
+               .type = lttng_ust_type_integer_define(int64_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_U8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "uint8",
+               .type = lttng_ust_type_integer_define(uint8_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_U16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "uint16",
+               .type = lttng_ust_type_integer_define(uint16_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_U32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "uint32",
+               .type = lttng_ust_type_integer_define(uint32_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_U64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "uint64",
+               .type = lttng_ust_type_integer_define(uint64_t, LTTNG_UST_BYTE_ORDER, 10),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "float",
+               .type = lttng_ust_type_float_define(float),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "double",
+               .type = lttng_ust_type_float_define(double),
+               .nowrite = 0,
+       }),
+       [LTTNG_UST_DYNAMIC_TYPE_STRING] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
+               .struct_size = sizeof(struct lttng_ust_event_field),
+               .name = "string",
+               .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_string, {
+                       .parent = {
+                               .type = lttng_ust_type_string,
+                       },
+                       .struct_size = sizeof(struct lttng_ust_type_string),
+                       .encoding = lttng_ust_string_encoding_UTF8,
+               }),
+               .nowrite = 0,
+       }),
+};
+
+static const struct lttng_ust_event_field dt_enum_field = {
+       .struct_size = sizeof(struct lttng_ust_event_field),
+       .name = NULL,
+       .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_enum, {
+               .parent = {
+                       .type = lttng_ust_type_enum,
+               },
+               .struct_size = sizeof(struct lttng_ust_type_enum),
+               .desc = &dt_enum_desc,
+               .container_type = lttng_ust_type_integer_define(char, LTTNG_UST_BYTE_ORDER, 10),
+       }),
+       .nowrite = 0,
+};
+
+const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value)
+{
+       if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0)
+               return NULL;
+       return dt_var_fields[value];
+}
+
+int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field * const **choices)
+{
+       *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
+       *choices = dt_var_fields;
+       return 0;
+}
+
+const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void)
+{
+       return &dt_enum_field;
+}
index 2b22471a0558ff6da2aa598a64ffaee7d3d74fa0..3ef20aa61457477c19f05a2d7e1f2d542a18ef27 100644 (file)
@@ -74,7 +74,6 @@ liblttng_ust_support_la_SOURCES = \
        lttng-tracer.h \
        lttng-tracer-core.h \
        ust-core.c \
-       lttng-ust-dynamic-type.c \
        lttng-rb-clients.h \
        lttng-ring-buffer-client-template.h \
        lttng-ring-buffer-client-discard.c \
diff --git a/src/lib/lttng-ust/lttng-ust-dynamic-type.c b/src/lib/lttng-ust/lttng-ust-dynamic-type.c
deleted file mode 100644 (file)
index 2b3ebd6..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * UST dynamic type implementation.
- */
-
-#define _LGPL_SOURCE
-#include <stdio.h>
-#include <stdint.h>
-#include <stddef.h>
-#include <inttypes.h>
-
-#include "common/macros.h"
-#include "common/dynamic-type.h"
-
-#define lttng_ust_field_enum_value(_string, _value)                                    \
-       LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_enum_entry, {               \
-               .struct_size = sizeof(struct lttng_ust_enum_entry),             \
-               .start = {                                              \
-                       .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
-                       .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
-                               (long long) (_value) : (_value),        \
-               },                                                      \
-               .end = {                                                \
-                       .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
-                       .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
-                               (long long) (_value) : (_value),        \
-               },                                                      \
-               .string = (_string),                                    \
-       }),
-
-static const struct lttng_ust_enum_entry *dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
-       [LTTNG_UST_DYNAMIC_TYPE_NONE] = lttng_ust_field_enum_value("_none", 0)
-       [LTTNG_UST_DYNAMIC_TYPE_S8] = lttng_ust_field_enum_value("_int8", 1)
-       [LTTNG_UST_DYNAMIC_TYPE_S16] = lttng_ust_field_enum_value("_int16", 2)
-       [LTTNG_UST_DYNAMIC_TYPE_S32] = lttng_ust_field_enum_value("_int32", 3)
-       [LTTNG_UST_DYNAMIC_TYPE_S64] = lttng_ust_field_enum_value("_int64", 4)
-       [LTTNG_UST_DYNAMIC_TYPE_U8] = lttng_ust_field_enum_value("_uint8", 5)
-       [LTTNG_UST_DYNAMIC_TYPE_U16] = lttng_ust_field_enum_value("_uint16", 6)
-       [LTTNG_UST_DYNAMIC_TYPE_U32] = lttng_ust_field_enum_value("_uint32", 7)
-       [LTTNG_UST_DYNAMIC_TYPE_U64] = lttng_ust_field_enum_value("_uint64", 8)
-       [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = lttng_ust_field_enum_value("_float", 9)
-       [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = lttng_ust_field_enum_value("_double", 10)
-       [LTTNG_UST_DYNAMIC_TYPE_STRING] = lttng_ust_field_enum_value("_string", 11)
-};
-
-static struct lttng_ust_enum_desc dt_enum_desc = {
-       .name = "dynamic_type_enum",
-       .entries = dt_enum,
-       .nr_entries = LTTNG_ARRAY_SIZE(dt_enum),
-};
-
-const struct lttng_ust_event_field *dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
-       [LTTNG_UST_DYNAMIC_TYPE_NONE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "none",
-               .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_struct, {
-                       .parent = {
-                               .type = lttng_ust_type_struct,
-                       },
-                       .struct_size = sizeof(struct lttng_ust_type_struct),
-                       .nr_fields = 0, /* empty struct */
-                       .alignment = 0,
-               }),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_S8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "int8",
-               .type = lttng_ust_type_integer_define(int8_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_S16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "int16",
-               .type = lttng_ust_type_integer_define(int16_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_S32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "int32",
-               .type = lttng_ust_type_integer_define(int32_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_S64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "int64",
-               .type = lttng_ust_type_integer_define(int64_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_U8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "uint8",
-               .type = lttng_ust_type_integer_define(uint8_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_U16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "uint16",
-               .type = lttng_ust_type_integer_define(uint16_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_U32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "uint32",
-               .type = lttng_ust_type_integer_define(uint32_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_U64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "uint64",
-               .type = lttng_ust_type_integer_define(uint64_t, LTTNG_UST_BYTE_ORDER, 10),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "float",
-               .type = lttng_ust_type_float_define(float),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "double",
-               .type = lttng_ust_type_float_define(double),
-               .nowrite = 0,
-       }),
-       [LTTNG_UST_DYNAMIC_TYPE_STRING] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
-               .struct_size = sizeof(struct lttng_ust_event_field),
-               .name = "string",
-               .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_string, {
-                       .parent = {
-                               .type = lttng_ust_type_string,
-                       },
-                       .struct_size = sizeof(struct lttng_ust_type_string),
-                       .encoding = lttng_ust_string_encoding_UTF8,
-               }),
-               .nowrite = 0,
-       }),
-};
-
-static const struct lttng_ust_event_field dt_enum_field = {
-       .struct_size = sizeof(struct lttng_ust_event_field),
-       .name = NULL,
-       .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_enum, {
-               .parent = {
-                       .type = lttng_ust_type_enum,
-               },
-               .struct_size = sizeof(struct lttng_ust_type_enum),
-               .desc = &dt_enum_desc,
-               .container_type = lttng_ust_type_integer_define(char, LTTNG_UST_BYTE_ORDER, 10),
-       }),
-       .nowrite = 0,
-};
-
-const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value)
-{
-       if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0)
-               return NULL;
-       return dt_var_fields[value];
-}
-
-int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field * const **choices)
-{
-       *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
-       *choices = dt_var_fields;
-       return 0;
-}
-
-const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void)
-{
-       return &dt_enum_field;
-}
This page took 0.029428 seconds and 4 git commands to generate.