#define BT_IF_DEV_MODE(txt)
#endif
-/*
- * Yield `ref`'s value while setting `ref` to NULL.
- *
- * This can be used to give a strong reference to a callee:
- *
- * add_foo_to_list(list, BT_MOVE_REF(foo));
- *
- * or in a simple assignment:
- *
- * my_struct->foo = BT_MOVE_REF(foo);
- *
- * When moving a reference in a function call, the reference is given to the
- * callee even if that function call fails, so make sure the called function
- * is written accordingly.
- */
-
-#define BT_MOVE_REF(ref) \
- ({ \
- __typeof__(ref) _ref = ref; \
- ref = NULL; \
- _ref; \
- })
-
/* Wrapper for g_array_index that adds bound checking. */
#define bt_g_array_index(a, t, i) \
g_array_index((a), t, ({ BT_ASSERT_DBG((i) < (a)->len); (i); }))
+++ /dev/null
-/*
- * SPDX-License-Identifier: MIT
- *
- * Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Static-sized priority heap containing pointers. Based on CLRS,
- * chapter 6.
- */
-
-#include "common/macros.h"
-#include "common/assert.h"
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "common/prio-heap.h"
-
-#ifdef DEBUG_HEAP
-void check_heap(const struct ptr_heap *heap)
-{
- size_t i;
-
- if (!heap->len)
- return;
-
- for (i = 1; i < heap->len; i++)
- BT_ASSERT_DBG(!heap->gt(heap->ptrs[i], heap->ptrs[0]));
-}
-#endif
-
-static
-size_t parent(size_t i)
-{
- return (i - 1) >> 1;
-}
-
-static
-size_t left(size_t i)
-{
- return (i << 1) + 1;
-}
-
-static
-size_t right(size_t i)
-{
- return (i << 1) + 2;
-}
-
-/*
- * Copy of heap->ptrs pointer is invalid after heap_grow.
- */
-static
-int heap_grow(struct ptr_heap *heap, size_t new_len)
-{
- void **new_ptrs;
-
- if (G_LIKELY(heap->alloc_len >= new_len))
- return 0;
-
- heap->alloc_len = bt_max_t(size_t, new_len, heap->alloc_len << 1);
- new_ptrs = calloc(heap->alloc_len, sizeof(void *));
- if (G_UNLIKELY(!new_ptrs))
- return -ENOMEM;
- if (G_LIKELY(heap->ptrs))
- memcpy(new_ptrs, heap->ptrs, heap->len * sizeof(void *));
- free(heap->ptrs);
- heap->ptrs = new_ptrs;
- return 0;
-}
-
-static
-int heap_set_len(struct ptr_heap *heap, size_t new_len)
-{
- int ret;
-
- ret = heap_grow(heap, new_len);
- if (G_UNLIKELY(ret))
- return ret;
- heap->len = new_len;
- return 0;
-}
-
-int bt_heap_init(struct ptr_heap *heap, size_t alloc_len,
- int gt(void *a, void *b))
-{
- heap->ptrs = NULL;
- heap->len = 0;
- heap->alloc_len = 0;
- heap->gt = gt;
- /*
- * Minimum size allocated is 1 entry to ensure memory allocation
- * never fails within bt_heap_replace_max.
- */
- return heap_grow(heap, bt_max_t(size_t, 1, alloc_len));
-}
-
-void bt_heap_free(struct ptr_heap *heap)
-{
- free(heap->ptrs);
-}
-
-static void heapify(struct ptr_heap *heap, size_t i)
-{
- void **ptrs = heap->ptrs;
- size_t l, r, largest;
-
- for (;;) {
- void *tmp;
-
- l = left(i);
- r = right(i);
- if (l < heap->len && heap->gt(ptrs[l], ptrs[i]))
- largest = l;
- else
- largest = i;
- if (r < heap->len && heap->gt(ptrs[r], ptrs[largest]))
- largest = r;
- if (G_UNLIKELY(largest == i))
- break;
- tmp = ptrs[i];
- ptrs[i] = ptrs[largest];
- ptrs[largest] = tmp;
- i = largest;
- }
- check_heap(heap);
-}
-
-void *bt_heap_replace_max(struct ptr_heap *heap, void *p)
-{
- void *res;
-
- if (G_UNLIKELY(!heap->len)) {
- (void) heap_set_len(heap, 1);
- heap->ptrs[0] = p;
- check_heap(heap);
- return NULL;
- }
-
- /* Replace the current max and heapify */
- res = heap->ptrs[0];
- heap->ptrs[0] = p;
- heapify(heap, 0);
- return res;
-}
-
-int bt_heap_insert(struct ptr_heap *heap, void *p)
-{
- void **ptrs;
- size_t pos;
- int ret;
-
- ret = heap_set_len(heap, heap->len + 1);
- if (G_UNLIKELY(ret))
- return ret;
- ptrs = heap->ptrs;
- pos = heap->len - 1;
- while (pos > 0 && heap->gt(p, ptrs[parent(pos)])) {
- /* Move parent down until we find the right spot */
- ptrs[pos] = ptrs[parent(pos)];
- pos = parent(pos);
- }
- ptrs[pos] = p;
- check_heap(heap);
- return 0;
-}
-
-void *bt_heap_remove(struct ptr_heap *heap)
-{
- switch (heap->len) {
- case 0:
- return NULL;
- case 1:
- (void) heap_set_len(heap, 0);
- return heap->ptrs[0];
- }
- /* Shrink, replace the current max by previous last entry and heapify */
- heap_set_len(heap, heap->len - 1);
- /* len changed. previous last entry is at heap->len */
- return bt_heap_replace_max(heap, heap->ptrs[heap->len]);
-}
-
-void *bt_heap_cherrypick(struct ptr_heap *heap, void *p)
-{
- size_t pos, len = heap->len;
-
- for (pos = 0; pos < len; pos++)
- if (G_UNLIKELY(heap->ptrs[pos] == p))
- goto found;
- return NULL;
-found:
- if (G_UNLIKELY(heap->len == 1)) {
- (void) heap_set_len(heap, 0);
- check_heap(heap);
- return heap->ptrs[0];
- }
- /* Replace p with previous last entry and heapify. */
- heap_set_len(heap, heap->len - 1);
- /* len changed. previous last entry is at heap->len */
- heap->ptrs[pos] = heap->ptrs[heap->len];
- heapify(heap, pos);
- return p;
-}
-
-int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src)
-{
- int ret;
-
- ret = bt_heap_init(dst, src->alloc_len, src->gt);
- if (ret < 0)
- goto end;
-
- ret = heap_set_len(dst, src->len);
- if (ret < 0)
- goto end;
-
- memcpy(dst->ptrs, src->ptrs, src->len * sizeof(void *));
-
-end:
- return ret;
-}
+++ /dev/null
-/*
- * SPDX-License-Identifier: MIT
- *
- * Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Static-sized priority heap containing pointers. Based on CLRS,
- * chapter 6.
- */
-
-#ifndef BABELTRACE_COMMON_PRIO_HEAP_H
-#define BABELTRACE_COMMON_PRIO_HEAP_H
-
-#include <unistd.h>
-#include "common/macros.h"
-
-struct ptr_heap {
- size_t len, alloc_len;
- void **ptrs;
- int (*gt)(void *a, void *b);
-};
-
-#ifdef DEBUG_HEAP
-void check_heap(const struct ptr_heap *heap);
-#else
-static inline
-void check_heap(const struct ptr_heap *heap __attribute__((unused)))
-{
-}
-#endif
-
-/**
- * bt_heap_maximum - return the largest element in the heap
- * @heap: the heap to be operated on
- *
- * Returns the largest element in the heap, without performing any modification
- * to the heap structure. Returns NULL if the heap is empty.
- */
-static inline void *bt_heap_maximum(const struct ptr_heap *heap)
-{
- check_heap(heap);
- return G_LIKELY(heap->len) ? heap->ptrs[0] : NULL;
-}
-
-/**
- * bt_heap_init - initialize the heap
- * @heap: the heap to initialize
- * @alloc_len: number of elements initially allocated
- * @gt: function to compare the elements
- *
- * Returns -ENOMEM if out of memory.
- */
-extern int bt_heap_init(struct ptr_heap *heap,
- size_t alloc_len,
- int gt(void *a, void *b));
-
-/**
- * bt_heap_free - free the heap
- * @heap: the heap to free
- */
-extern void bt_heap_free(struct ptr_heap *heap);
-
-/**
- * bt_heap_insert - insert an element into the heap
- * @heap: the heap to be operated on
- * @p: the element to add
- *
- * Insert an element into the heap.
- *
- * Returns -ENOMEM if out of memory.
- */
-extern int bt_heap_insert(struct ptr_heap *heap, void *p);
-
-/**
- * bt_heap_remove - remove the largest element from the heap
- * @heap: the heap to be operated on
- *
- * Returns the largest element in the heap. It removes this element from the
- * heap. Returns NULL if the heap is empty.
- */
-extern void *bt_heap_remove(struct ptr_heap *heap);
-
-/**
- * bt_heap_cherrypick - remove a given element from the heap
- * @heap: the heap to be operated on
- * @p: the element
- *
- * Remove the given element from the heap. Return the element if present, else
- * return NULL. This algorithm has a complexity of O(n), which is higher than
- * O(log(n)) provided by the rest of this API.
- */
-extern void *bt_heap_cherrypick(struct ptr_heap *heap, void *p);
-
-/**
- * bt_heap_replace_max - replace the the largest element from the heap
- * @heap: the heap to be operated on
- * @p: the pointer to be inserted as topmost element replacement
- *
- * Returns the largest element in the heap. It removes this element from the
- * heap. The heap is rebalanced only once after the insertion. Returns NULL if
- * the heap is empty.
- *
- * This is the equivalent of calling bt_heap_remove() and then bt_heap_insert(), but
- * it only rebalances the heap once. It never allocates memory.
- */
-extern void *bt_heap_replace_max(struct ptr_heap *heap, void *p);
-
-/**
- * bt_heap_copy - copy a heap
- * @dst: the destination heap (must be allocated)
- * @src: the source heap
- *
- * Returns -ENOMEM if out of memory.
- */
-extern int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src);
-
-#endif /* BABELTRACE_COMMON_PRIO_HEAP_H */
template <typename T>
using EnableIfIsWiseEnum =
- typename std::enable_if<wise_enum::is_wise_enum<T>::value, const char *>::type;
+ typename std::enable_if<wise_enum::is_wise_enum<T>::value, wise_enum::string_type>::type;
} /* namespace internal */
return _mLevel;
}
- /*
- * Current logging level converted to a `bt_log_level` value.
- *
- * For legacy code.
- */
- bt_log_level cLevel() const noexcept
- {
- return static_cast<bt_log_level>(_mLevel);
- }
-
/*
* Whether or not this logger would log at the level `level`.
*/
*/
template <Level LevelV, bool AppendCauseV, typename... ArgTs>
void log(const char * const fileName, const char * const funcName, const unsigned int lineNo,
- const char * const fmt, ArgTs&&...args) const
+ fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
{
- this->_log<_StdLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, {}, "", fmt,
- std::forward<ArgTs>(args)...);
+ this->_log<_StdLogWriter, LevelV, AppendCauseV>(
+ fileName, funcName, lineNo, {}, "", std::move(fmt), std::forward<ArgTs>(args)...);
}
/*
*/
template <bool AppendCauseV, typename ExcT, typename... ArgTs>
[[noreturn]] void logErrorAndThrow(const char * const fileName, const char * const funcName,
- const unsigned int lineNo, const char * const fmt,
+ const unsigned int lineNo, fmt::format_string<ArgTs...> fmt,
ArgTs&&...args) const
{
- this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, fmt,
+ this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, std::move(fmt),
std::forward<ArgTs>(args)...);
throw ExcT {};
}
*/
template <bool AppendCauseV, typename... ArgTs>
[[noreturn]] void logErrorAndRethrow(const char * const fileName, const char * const funcName,
- const unsigned int lineNo, const char * const fmt,
- ArgTs&&...args) const
+ const unsigned int lineNo,
+ fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
{
- this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, fmt,
+ this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, std::move(fmt),
std::forward<ArgTs>(args)...);
throw;
}
*/
template <Level LevelV, bool AppendCauseV, typename... ArgTs>
void logErrno(const char * const fileName, const char * const funcName,
- const unsigned int lineNo, const char * const initMsg, const char * const fmt,
- ArgTs&&...args) const
+ const unsigned int lineNo, const char * const initMsg,
+ fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
{
- this->_log<_InitMsgLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, {},
- this->_errnoIntroStr(initMsg).c_str(),
- fmt, std::forward<ArgTs>(args)...);
+ this->_log<_InitMsgLogWriter, LevelV, AppendCauseV>(
+ fileName, funcName, lineNo, {}, this->_errnoIntroStr(initMsg).c_str(), std::move(fmt),
+ std::forward<ArgTs>(args)...);
}
/*
template <bool AppendCauseV, typename ExcT, typename... ArgTs>
[[noreturn]] void logErrorErrnoAndThrow(const char * const fileName,
const char * const funcName, const unsigned int lineNo,
- const char * const initMsg, const char * const fmt,
- ArgTs&&...args) const
+ const char * const initMsg,
+ fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
{
- this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg, fmt,
- std::forward<ArgTs>(args)...);
+ this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg,
+ std::move(fmt), std::forward<ArgTs>(args)...);
throw ExcT {};
}
* Like logErrno() with the `Level::Error` level, but also rethrows.
*/
template <bool AppendCauseV, typename... ArgTs>
- [[noreturn]] void logErrorErrnoAndRethrow(const char * const fileName,
- const char * const funcName,
- const unsigned int lineNo, const char * const initMsg,
- const char * const fmt, ArgTs&&...args) const
+ [[noreturn]] void
+ logErrorErrnoAndRethrow(const char * const fileName, const char * const funcName,
+ const unsigned int lineNo, const char * const initMsg,
+ fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
{
- this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg, fmt,
- std::forward<ArgTs>(args)...);
+ this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg,
+ std::move(fmt), std::forward<ArgTs>(args)...);
throw;
}
*/
template <Level LevelV, typename... ArgTs>
void logMem(const char * const fileName, const char * const funcName, const unsigned int lineNo,
- const MemData memData, const char * const fmt, ArgTs&&...args) const
+ const MemData memData, fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
{
- this->_log<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, "", fmt,
- std::forward<ArgTs>(args)...);
+ this->_log<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, "",
+ std::move(fmt), std::forward<ArgTs>(args)...);
}
private:
*/
template <typename LogWriterT, Level LevelV, bool AppendCauseV, typename... ArgTs>
void _log(const char * const fileName, const char * const funcName, const unsigned int lineNo,
- const MemData memData, const char * const initMsg, const char * const fmt,
+ const MemData memData, const char * const initMsg, fmt::format_string<ArgTs...> fmt,
ArgTs&&...args) const
{
const auto wouldLog = this->wouldLog(LevelV);
* append a null character).
*/
_mBuf.clear();
- BT_ASSERT(fmt);
- fmt::format_to(std::back_inserter(_mBuf), fmt, std::forward<ArgTs>(args)...);
+ fmt::format_to(std::back_inserter(_mBuf), std::move(fmt), std::forward<ArgTs>(args)...);
_mBuf.push_back('\0');
}
#endif // span_FEATURE( BYTE_SPAN )
-#if span_HAVE( STRUCT_BINDING )
+#if !span_USES_STD_SPAN && span_HAVE( STRUCT_BINDING )
#if span_CPP14_OR_GREATER
# include <tuple>
} // end namespace std
-#endif // span_HAVE( STRUCT_BINDING )
+#endif // !span_USES_STD_SPAN && span_HAVE( STRUCT_BINDING )
#if ! span_USES_STD_SPAN
span_RESTORE_WARNINGS()
{
char tmp_prefix[TMP_PREFIX_LEN];
- if (trace->name.value) {
- BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value));
+ if (trace->name) {
+ BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name));
}
if (!extended) {
BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id));
- if (stream_class->name.value) {
+ if (stream_class->name) {
BUF_APPEND(", %sname=\"%s\"",
- PRFIELD(stream_class->name.value));
+ PRFIELD(stream_class->name));
}
if (!extended) {
BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id));
- if (event_class->name.value) {
+ if (event_class->name) {
BUF_APPEND(", %sname=\"%s\"",
- PRFIELD(event_class->name.value));
+ PRFIELD(event_class->name));
}
if (!extended) {
(int) event_class->log_level.value)));
}
- if (event_class->emf_uri.value) {
+ if (event_class->emf_uri) {
BUF_APPEND(", %semf-uri=\"%s\"",
- PRFIELD(event_class->emf_uri.value));
+ PRFIELD(event_class->emf_uri));
}
BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id));
- if (stream->name.value) {
- BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name.value));
+ if (stream->name) {
+ BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name));
}
if (!extended) {
{
char tmp_prefix[TMP_PREFIX_LEN];
- if (clock_class->name.value) {
- BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name.value));
+ if (clock_class->name) {
+ BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name));
}
BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency));
return;
}
- if (clock_class->description.value) {
+ if (clock_class->description) {
BUF_APPEND(", %spartial-descr=\"%.32s\"",
- PRFIELD(clock_class->description.value));
+ PRFIELD(clock_class->description));
}
if (clock_class->uuid.value) {
BT_LIB_LOGD("Destroying clock class: %!+K", clock_class);
BT_OBJECT_PUT_REF_AND_RESET(clock_class->user_attributes);
- if (clock_class->name.str) {
- g_string_free(clock_class->name.str, TRUE);
- clock_class->name.str = NULL;
- clock_class->name.value = NULL;
- }
-
- if (clock_class->description.str) {
- g_string_free(clock_class->description.str, TRUE);
- clock_class->description.str = NULL;
- clock_class->description.value = NULL;
- }
-
+ g_free(clock_class->name);
+ g_free(clock_class->description);
bt_object_pool_finalize(&clock_class->cs_pool);
g_free(clock_class);
}
goto error;
}
- clock_class->name.str = g_string_new(NULL);
- if (!clock_class->name.str) {
- BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
- goto error;
- }
-
- clock_class->description.str = g_string_new(NULL);
- if (!clock_class->description.str) {
- BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
- goto error;
- }
-
clock_class->frequency = UINT64_C(1000000000);
clock_class->origin_is_unix_epoch = BT_TRUE;
set_base_offset(clock_class);
const char *bt_clock_class_get_name(const struct bt_clock_class *clock_class)
{
BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(clock_class);
- return clock_class->name.value;
+ return clock_class->name;
}
BT_EXPORT
BT_ASSERT_PRE_CLK_CLS_NON_NULL(clock_class);
BT_ASSERT_PRE_NAME_NON_NULL(name);
BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class);
- g_string_assign(clock_class->name.str, name);
- clock_class->name.value = clock_class->name.str->str;
+ g_free(clock_class->name);
+ clock_class->name = g_strdup(name);
BT_LIB_LOGD("Set clock class's name: %!+K", clock_class);
return BT_FUNC_STATUS_OK;
}
const struct bt_clock_class *clock_class)
{
BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(clock_class);
- return clock_class->description.value;
+ return clock_class->description;
}
BT_EXPORT
BT_ASSERT_PRE_CLK_CLS_NON_NULL(clock_class);
BT_ASSERT_PRE_DESCR_NON_NULL(descr);
BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class);
- g_string_assign(clock_class->description.str, descr);
- clock_class->description.value = clock_class->description.str->str;
+ g_free(clock_class->description);
+ clock_class->description = g_strdup(descr);
BT_LIB_LOGD("Set clock class's description: %!+K",
clock_class);
return BT_FUNC_STATUS_OK;
/* Owned by this */
struct bt_value *user_attributes;
- struct {
- GString *str;
-
- /* NULL or `str->str` above */
- const char *value;
- } name;
-
- struct {
- GString *str;
-
- /* NULL or `str->str` above */
- const char *value;
- } description;
+ gchar *name;
+ gchar *description;
uint64_t frequency;
uint64_t precision;
BT_LIB_LOGD("Destroying event class: %!+E", event_class);
BT_OBJECT_PUT_REF_AND_RESET(event_class->user_attributes);
- if (event_class->name.str) {
- g_string_free(event_class->name.str, TRUE);
- event_class->name.str = NULL;
- }
-
- if (event_class->emf_uri.str) {
- g_string_free(event_class->emf_uri.str, TRUE);
- event_class->emf_uri.str = NULL;
- }
-
+ g_free(event_class->name);
+ g_free(event_class->emf_uri);
BT_LOGD_STR("Putting context field class.");
BT_OBJECT_PUT_REF_AND_RESET(event_class->specific_context_fc);
BT_LOGD_STR("Putting payload field class.");
event_class->id = id;
bt_property_uint_init(&event_class->log_level,
BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE, 0);
- event_class->name.str = g_string_new(NULL);
- if (!event_class->name.str) {
- BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
- goto error;
- }
-
- event_class->emf_uri.str = g_string_new(NULL);
- if (!event_class->emf_uri.str) {
- BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
- goto error;
- }
ret = bt_object_pool_initialize(&event_class->event_pool,
(bt_object_pool_new_object_func) bt_event_new,
const char *bt_event_class_get_name(const struct bt_event_class *event_class)
{
BT_ASSERT_PRE_DEV_EC_NON_NULL(event_class);
- return event_class->name.value;
+ return event_class->name;
}
BT_EXPORT
BT_ASSERT_PRE_EC_NON_NULL(event_class);
BT_ASSERT_PRE_NAME_NON_NULL(name);
BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class);
- g_string_assign(event_class->name.str, name);
- event_class->name.value = event_class->name.str->str;
+ g_free(event_class->name);
+ event_class->name = g_strdup(name);
BT_LIB_LOGD("Set event class's name: %!+E", event_class);
return BT_FUNC_STATUS_OK;
}
const char *bt_event_class_get_emf_uri(const struct bt_event_class *event_class)
{
BT_ASSERT_PRE_DEV_EC_NON_NULL(event_class);
- return event_class->emf_uri.value;
+ return event_class->emf_uri;
}
BT_EXPORT
BT_ASSERT_PRE_EC_NON_NULL(event_class);
BT_ASSERT_PRE_NON_NULL("emf-uri", emf_uri, "EMF URI");
BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class);
- g_string_assign(event_class->emf_uri.str, emf_uri);
- event_class->emf_uri.value = event_class->emf_uri.str->str;
+ g_free(event_class->emf_uri);
+ event_class->emf_uri = g_strdup(emf_uri);
BT_LIB_LOGD("Set event class's EMF URI: %!+E", event_class);
return BT_FUNC_STATUS_OK;
}
/* Owned by this */
struct bt_value *user_attributes;
- struct {
- GString *str;
-
- /* NULL or `str->str` above */
- const char *value;
- } name;
+ gchar *name;
uint64_t id;
struct bt_property_uint log_level;
- struct {
- GString *str;
-
- /* NULL or `str->str` above */
- const char *value;
- } emf_uri;
+ gchar *emf_uri;
/* Pool of `struct bt_event *` */
struct bt_object_pool event_pool;
stream_class->event_classes = NULL;
}
- if (stream_class->name.str) {
- g_string_free(stream_class->name.str, TRUE);
- stream_class->name.str = NULL;
- stream_class->name.value = NULL;
- }
-
+ g_free(stream_class->name);
BT_LOGD_STR("Putting packet context field class.");
BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc);
BT_LOGD_STR("Putting event common context field class.");
goto error;
}
- stream_class->name.str = g_string_new(NULL);
- if (!stream_class->name.str) {
- BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
- goto error;
- }
-
stream_class->id = id;
stream_class->assigns_automatic_event_class_id = true;
stream_class->assigns_automatic_stream_id = true;
const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class)
{
BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class);
- return stream_class->name.value;
+ return stream_class->name;
}
BT_EXPORT
BT_ASSERT_PRE_SC_NON_NULL(stream_class);
BT_ASSERT_PRE_NAME_NON_NULL(name);
BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
- g_string_assign(stream_class->name.str, name);
- stream_class->name.value = stream_class->name.str->str;
+ g_free(stream_class->name);
+ stream_class->name = g_strdup(name);
BT_LIB_LOGD("Set stream class's name: %!+S", stream_class);
return BT_FUNC_STATUS_OK;
}
/* Owned by this */
struct bt_value *user_attributes;
- struct {
- GString *str;
-
- /* NULL or `str->str` above */
- const char *value;
- } name;
+ gchar *name;
uint64_t id;
bool assigns_automatic_event_class_id;
BT_LIB_LOGD("Destroying stream object: %!+s", stream);
BT_OBJECT_PUT_REF_AND_RESET(stream->user_attributes);
- if (stream->name.str) {
- g_string_free(stream->name.str, TRUE);
- stream->name.str = NULL;
- stream->name.value = NULL;
- }
-
+ g_free(stream->name);
BT_LOGD_STR("Putting stream's class.");
bt_object_put_ref(stream->class);
bt_object_pool_finalize(&stream->packet_pool);
goto error;
}
- stream->name.str = g_string_new(NULL);
- if (!stream->name.str) {
- BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
- goto error;
- }
-
stream->id = id;
ret = bt_object_pool_initialize(&stream->packet_pool,
(bt_object_pool_new_object_func) bt_packet_new,
const char *bt_stream_get_name(const struct bt_stream *stream)
{
BT_ASSERT_PRE_DEV_STREAM_NON_NULL(stream);
- return stream->name.value;
+ return stream->name;
}
BT_EXPORT
BT_ASSERT_PRE_STREAM_NON_NULL(stream);
BT_ASSERT_PRE_NAME_NON_NULL(name);
BT_ASSERT_PRE_DEV_STREAM_HOT(stream);
- g_string_assign(stream->name.str, name);
- stream->name.value = stream->name.str->str;
+ g_free(stream->name);
+ stream->name = g_strdup(name);
BT_LIB_LOGD("Set stream's name: %!+s", stream);
return BT_FUNC_STATUS_OK;
}
/* Owned by this */
struct bt_stream_class *class;
- struct {
- GString *str;
-
- /* NULL or `str->str` above */
- const char *value;
- } name;
+ gchar *name;
uint64_t id;
}
}
- if (trace->name.str) {
- g_string_free(trace->name.str, TRUE);
- trace->name.str = NULL;
- trace->name.value = NULL;
- }
+ g_free(trace->name);
if (trace->environment) {
BT_LOGD_STR("Destroying environment attributes.");
goto error;
}
- trace->name.str = g_string_new(NULL);
- if (!trace->name.str) {
- BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
- goto error;
- }
-
trace->environment = bt_attributes_create();
if (!trace->environment) {
BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty attributes object.");
const char *bt_trace_get_name(const struct bt_trace *trace)
{
BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace);
- return trace->name.value;
+ return trace->name;
}
BT_EXPORT
BT_ASSERT_PRE_TRACE_NON_NULL(trace);
BT_ASSERT_PRE_NAME_NON_NULL(name);
BT_ASSERT_PRE_DEV_TRACE_HOT(trace);
- g_string_assign(trace->name.str, name);
- trace->name.value = trace->name.str->str;
+ g_free(trace->name);
+ trace->name = g_strdup(name);
BT_LIB_LOGD("Set trace's name: %!+t", trace);
return BT_FUNC_STATUS_OK;
}
/* Owned by this */
struct bt_trace_class *class;
- struct {
- GString *str;
-
- /* NULL or `str->str` above */
- const char *value;
- } name;
+ gchar *name;
struct {
bt_uuid_t uuid;
ctf_metadata_decoder_up decoder = ctf_metadata_decoder_create(&decoder_cfg);
if (!decoder) {
BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(
- logger, bt2::Error, "Cannot create metadata decoder: path=\"{}}\".", path);
+ logger, bt2::Error, "Cannot create metadata decoder: path=\"{}\".", path);
}
rewind(metadataFp.get());
test_pass() {
local -r mp_path=$1
local -r output_dir=$(mktemp -d)
+ local -r py_cmd=(
+ "$BT_TESTS_PYTHON_BIN" "$data_dir/data_from_mp.py"
+ "$mp_path" "$output_dir"
+ )
- run_python "$BT_TESTS_PYTHON_BIN" "$data_dir/data_from_mp.py" "$mp_path" "$output_dir"
+ if ! bt_run_in_py_env "${py_cmd[@]}"; then
+ fail "Failed to run \`${py_cmd[*]}\`"
+ return 1
+ fi
local -r res_path=$(mktemp)
-
- bt_cli "$res_path" /dev/null --plugin-path="$data_dir" \
+ local -r cli_cmd=(
+ "$res_path" /dev/null --plugin-path="$data_dir"
-c sink.test-text.single "$output_dir/trace"
+ )
+
+ if ! bt_cli "${cli_cmd[@]}"; then
+ fail "Failed to run \`bt_cli ${cli_cmd[*]}\`"
+ return 1
+ fi
+
bt_diff "$res_path" "$output_dir/expect"
ok $? "$mp_path"
rm -rf "$output_dir" "$res_path"
local -r expected_file=$1
local -r actual_file=$2
+ if [[ ! -e $expected_file ]]; then
+ echo "ERROR: expected file \`$expected_file\` doesn't exist" >&2
+ return 1
+ fi
+
+ if [[ ! -e $actual_file ]]; then
+ echo "ERROR: actual file \`$actual_file\` doesn't exist" >&2
+ return 1
+ fi
+
diff -u <(bt_remove_cr_inline "$expected_file") <(bt_remove_cr_inline "$actual_file") 1>&2
}