Merge pull request #27368 from taosdata/fix/TD-31542-monitorfw

fix/TD-31542-monitorfw
This commit is contained in:
Hongze Cheng 2024-08-23 12:35:56 +08:00 committed by GitHub
commit 91894053ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 76 additions and 81 deletions

View File

@ -16,13 +16,15 @@
#include <assert.h>
#ifndef TAOS_ASSERT_H
#define TAOS_ASSERT_H
#ifndef TAOS_TEST_H
#define TAOS_TEST_H
#ifdef TAOS_ASSERT_ENABLE
#define TAOS_ASSERT(i) assert(i);
#ifdef TAOS_TEST_PARA_ENABLE
#else
#define TAOS_ASSERT(i)
#define TAOS_TEST_PARA(i) \
if (!(i)) return 1;
#define TAOS_TEST_PARA_NULL(i) \
if (!(i)) return NULL;
#endif // TAOS_TEST
#endif // TAOS_ASSERT_H
#endif // TAOS_TEST_H

View File

@ -59,7 +59,7 @@ taos_collector_t *taos_collector_new(const char *name) {
}
int taos_collector_destroy(taos_collector_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 0;
int r = 0;
@ -97,14 +97,14 @@ void taos_collector_free_generic(void *gen) {
}
int taos_collector_set_collect_fn(taos_collector_t *self, taos_collect_fn *fn) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
self->collect_fn = fn;
return 0;
}
int taos_collector_add_metric(taos_collector_t *self, taos_metric_t *metric) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (taos_map_get(self->metrics, metric->name) != NULL) {
TAOS_LOG("metric already found in collector");
@ -114,13 +114,13 @@ int taos_collector_add_metric(taos_collector_t *self, taos_metric_t *metric) {
}
int taos_collector_remove_metric(taos_collector_t *self, const char* key){
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
return taos_map_delete(self->metrics, key);
}
taos_metric_t* taos_collector_get_metric(taos_collector_t *self, char *metric_name){
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
if (self == NULL) return NULL;
return taos_map_get(self->metrics, metric_name);
}

View File

@ -113,7 +113,7 @@ int taos_collector_registry_destroy(taos_collector_registry_t *self) {
}
int taos_collector_registry_register_metric(taos_metric_t *metric) {
TAOS_ASSERT(metric != NULL);
TAOS_TEST_PARA(metric != NULL);
taos_collector_t *default_collector =
(taos_collector_t *)taos_map_get(TAOS_COLLECTOR_REGISTRY_DEFAULT->collectors, "default");
@ -126,7 +126,7 @@ int taos_collector_registry_register_metric(taos_metric_t *metric) {
}
int taos_collector_registry_deregister_metric(const char *key) {
TAOS_ASSERT(metric != NULL);
TAOS_TEST_PARA(key != NULL);
taos_collector_t *default_collector =
(taos_collector_t *)taos_map_get(TAOS_COLLECTOR_REGISTRY_DEFAULT->collectors, "default");
@ -139,7 +139,7 @@ int taos_collector_registry_deregister_metric(const char *key) {
}
taos_metric_t *taos_collector_registry_get_metric(char* metric_name){
TAOS_ASSERT(metric != NULL);
TAOS_TEST_PARA_NULL(metric_name != NULL);
taos_collector_t *default_collector =
(taos_collector_t *)taos_map_get(TAOS_COLLECTOR_REGISTRY_DEFAULT->collectors, "default");
@ -161,7 +161,7 @@ taos_metric_t *taos_collector_registry_must_register_metric(taos_metric_t *metri
}
int taos_collector_registry_register_collector(taos_collector_registry_t *self, taos_collector_t *collector) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;

View File

@ -33,7 +33,7 @@ taos_counter_t *taos_counter_new(const char *name, const char *help, size_t labe
}
int taos_counter_destroy(taos_counter_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 0;
int r = 0;
r = taos_metric_destroy(self);
@ -42,7 +42,7 @@ int taos_counter_destroy(taos_counter_t *self) {
}
int taos_counter_inc(taos_counter_t *self, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (self->type != TAOS_COUNTER) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
@ -54,7 +54,7 @@ int taos_counter_inc(taos_counter_t *self, const char **label_values) {
}
int taos_counter_add(taos_counter_t *self, double r_value, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (self->type != TAOS_COUNTER) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);

View File

@ -33,7 +33,7 @@ taos_gauge_t *taos_gauge_new(const char *name, const char *help, size_t label_ke
}
int taos_gauge_destroy(taos_gauge_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
r = taos_metric_destroy(self);
self = NULL;
@ -41,7 +41,7 @@ int taos_gauge_destroy(taos_gauge_t *self) {
}
/*
int taos_gauge_inc(taos_gauge_t *self, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (self->type != TAOS_GAUGE) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
@ -53,7 +53,7 @@ int taos_gauge_inc(taos_gauge_t *self, const char **label_values) {
}
int taos_gauge_dec(taos_gauge_t *self, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (self->type != TAOS_GAUGE) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
@ -65,7 +65,7 @@ int taos_gauge_dec(taos_gauge_t *self, const char **label_values) {
}
int taos_gauge_add(taos_gauge_t *self, double r_value, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (self->type != TAOS_GAUGE) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
@ -77,7 +77,7 @@ int taos_gauge_add(taos_gauge_t *self, double r_value, const char **label_values
}
int taos_gauge_sub(taos_gauge_t *self, double r_value, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (self->type != TAOS_GAUGE) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
@ -89,7 +89,7 @@ int taos_gauge_sub(taos_gauge_t *self, double r_value, const char **label_values
}
*/
int taos_gauge_set(taos_gauge_t *self, double r_value, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (self->type != TAOS_GAUGE) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);

View File

@ -34,8 +34,7 @@ taos_linked_list_t *taos_linked_list_new(void) {
}
int taos_linked_list_purge(taos_linked_list_t *self) {
TAOS_ASSERT(self != NULL);
if (self == NULL) return 1;
TAOS_TEST_PARA(self != NULL);
taos_linked_list_node_t *node = self->head;
while (node != NULL) {
taos_linked_list_node_t *next = node->next;
@ -57,7 +56,7 @@ int taos_linked_list_purge(taos_linked_list_t *self) {
}
int taos_linked_list_destroy(taos_linked_list_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
int ret = 0;
@ -69,7 +68,7 @@ int taos_linked_list_destroy(taos_linked_list_t *self) {
}
void *taos_linked_list_first(taos_linked_list_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
if (self->head) {
return self->head->item;
} else {
@ -78,7 +77,7 @@ void *taos_linked_list_first(taos_linked_list_t *self) {
}
void *taos_linked_list_last(taos_linked_list_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
if (self->tail) {
return self->tail->item;
} else {
@ -87,8 +86,7 @@ void *taos_linked_list_last(taos_linked_list_t *self) {
}
int taos_linked_list_append(taos_linked_list_t *self, void *item) {
TAOS_ASSERT(self != NULL);
if (self == NULL) return 1;
TAOS_TEST_PARA(self != NULL);
taos_linked_list_node_t *node = (taos_linked_list_node_t *)taos_malloc(sizeof(taos_linked_list_node_t));
node->item = item;
@ -104,8 +102,7 @@ int taos_linked_list_append(taos_linked_list_t *self, void *item) {
}
int taos_linked_list_push(taos_linked_list_t *self, void *item) {
TAOS_ASSERT(self != NULL);
if (self == NULL) return 1;
TAOS_TEST_PARA(self != NULL);
taos_linked_list_node_t *node = (taos_linked_list_node_t *)taos_malloc(sizeof(taos_linked_list_node_t));
node->item = item;
@ -120,7 +117,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item) {
/*
void *taos_linked_list_pop(taos_linked_list_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return NULL;
taos_linked_list_node_t *node = self->head;
void *item = NULL;
@ -146,8 +143,7 @@ void *taos_linked_list_pop(taos_linked_list_t *self) {
*/
int taos_linked_list_remove(taos_linked_list_t *self, void *item) {
TAOS_ASSERT(self != NULL);
if (self == NULL) return 1;
TAOS_TEST_PARA(self != NULL);
taos_linked_list_node_t *node;
taos_linked_list_node_t *prev_node = NULL;
#ifdef TAOS_LOG_ENABLE
@ -225,8 +221,7 @@ int taos_linked_list_remove(taos_linked_list_t *self, void *item) {
}
taos_linked_list_compare_t taos_linked_list_compare(taos_linked_list_t *self, void *item_a, void *item_b) {
TAOS_ASSERT(self != NULL);
if (self == NULL) return 1;
TAOS_TEST_PARA(self != NULL);
if (self->compare_fn) {
return (*self->compare_fn)(item_a, item_b);
} else {
@ -235,20 +230,18 @@ taos_linked_list_compare_t taos_linked_list_compare(taos_linked_list_t *self, vo
}
size_t taos_linked_list_size(taos_linked_list_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
return self->size;
}
int taos_linked_list_set_free_fn(taos_linked_list_t *self, taos_linked_list_free_item_fn free_fn) {
TAOS_ASSERT(self != NULL);
if (self == NULL) return 1;
TAOS_TEST_PARA(self != NULL);
self->free_fn = free_fn;
return 0;
}
int taos_linked_list_set_compare_fn(taos_linked_list_t *self, taos_linked_list_compare_item_fn compare_fn) {
TAOS_ASSERT(self != NULL);
if (self == NULL) return 1;
TAOS_TEST_PARA(self != NULL);
self->compare_fn = compare_fn;
return 0;
}

View File

@ -46,7 +46,7 @@ taos_map_node_t *taos_map_node_new(const char *key, void *value, taos_map_node_f
}
int taos_map_node_destroy(taos_map_node_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 0;
taos_free((void *)self->key);
self->key = NULL;
@ -120,7 +120,7 @@ taos_map_t *taos_map_new() {
}
int taos_map_destroy(taos_map_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
int ret = 0;
@ -199,7 +199,7 @@ static void *taos_map_get_internal(const char *key, size_t *size, size_t *max_si
}
void *taos_map_get(taos_map_t *self, const char *key) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
int r = 0;
r = pthread_rwlock_wrlock(self->rwlock);
if (r) {
@ -217,7 +217,7 @@ void *taos_map_get(taos_map_t *self, const char *key) {
}
void *taos_map_get_withoutlock(taos_map_t *self, const char *key) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
int r = 0;
void *payload =
taos_map_get_internal(key, &self->size, &self->max_size, self->keys, self->addrs, self->free_value_fn);
@ -255,7 +255,7 @@ static int taos_map_set_internal(const char *key, void *value, size_t *size, siz
}
int taos_map_ensure_space(taos_map_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
if (self->size <= self->max_size / 2) {
@ -329,7 +329,7 @@ int taos_map_ensure_space(taos_map_t *self) {
}
int taos_map_set(taos_map_t *self, const char *key, void *value) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
r = pthread_rwlock_wrlock(self->rwlock);
if (r) {
@ -394,7 +394,7 @@ static int taos_map_delete_internal(const char *key, size_t *size, size_t *max_s
}
int taos_map_delete(taos_map_t *self, const char *key) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
int ret = 0;
r = pthread_rwlock_wrlock(self->rwlock);
@ -413,12 +413,12 @@ int taos_map_delete(taos_map_t *self, const char *key) {
}
int taos_map_set_free_value_fn(taos_map_t *self, taos_map_node_free_value_fn free_value_fn) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
self->free_value_fn = free_value_fn;
return 0;
}
size_t taos_map_size(taos_map_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
return self->size;
}

View File

@ -89,7 +89,7 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name,
}
int taos_metric_destroy(taos_metric_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 0;
int r = 0;
@ -144,7 +144,7 @@ void taos_metric_free_generic(void *item) {
}
taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
int r = 0;
r = pthread_rwlock_wrlock(self->rwlock);
if (r) {

View File

@ -46,7 +46,7 @@ taos_metric_formatter_t *taos_metric_formatter_new() {
}
int taos_metric_formatter_destroy(taos_metric_formatter_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 0;
int r = 0;
@ -66,7 +66,7 @@ int taos_metric_formatter_destroy(taos_metric_formatter_t *self) {
}
/*
int taos_metric_formatter_load_help(taos_metric_formatter_t *self, const char *name, const char *help) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;
@ -87,7 +87,7 @@ int taos_metric_formatter_load_help(taos_metric_formatter_t *self, const char *n
}
int taos_metric_formatter_load_type(taos_metric_formatter_t *self, const char *name, taos_metric_type_t metric_type) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;
@ -109,7 +109,7 @@ int taos_metric_formatter_load_type(taos_metric_formatter_t *self, const char *n
*/
int taos_metric_formatter_load_l_value(taos_metric_formatter_t *self, const char *name, const char *suffix,
size_t label_count, const char **label_keys, const char **label_values) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;
@ -158,9 +158,9 @@ int taos_metric_formatter_load_l_value(taos_metric_formatter_t *self, const char
return 0;
}
/*
int taos_metric_formatter_load_sample(taos_metric_formatter_t *self, taos_metric_sample_t *sample,
int taos_metric_formatter_load_sample(taos_metric_formatter_t *self, taos_metric_sample_t *sample,
char *ts, char *format) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;
@ -188,12 +188,12 @@ int taos_metric_formatter_load_sample(taos_metric_formatter_t *self, taos_metric
}
*/
int taos_metric_formatter_clear(taos_metric_formatter_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
return taos_string_builder_clear(self->string_builder);
}
char *taos_metric_formatter_dump(taos_metric_formatter_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
int r = 0;
if (self == NULL) return NULL;
char *data = taos_string_builder_dump(self->string_builder);
@ -207,7 +207,7 @@ char *taos_metric_formatter_dump(taos_metric_formatter_t *self) {
}
/*
int taos_metric_formatter_load_metric(taos_metric_formatter_t *self, taos_metric_t *metric, char *ts, char *format) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;
@ -234,7 +234,7 @@ int taos_metric_formatter_load_metric(taos_metric_formatter_t *self, taos_metric
}
int taos_metric_formatter_load_metrics(taos_metric_formatter_t *self, taos_map_t *collectors, char *ts, char *format) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
for (taos_linked_list_node_t *current_node = collectors->keys->head; current_node != NULL;
current_node = current_node->next) {

View File

@ -29,7 +29,7 @@
int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_metric_sample_t *sample,
char *ts, char *format, char *metricName, int32_t metric_type,
SJson *arrayMetricGroups) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;
@ -129,7 +129,7 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me
int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_metric_t *metric, char *ts, char *format,
SJson* tableArray) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
int r = 0;
@ -195,7 +195,7 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me
int taos_metric_formatter_load_metrics_new(taos_metric_formatter_t *self, taos_map_t *collectors, char *ts,
char *format, SJson* tableArray) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
for (taos_linked_list_node_t *current_node = collectors->keys->head; current_node != NULL;

View File

@ -43,7 +43,7 @@ taos_metric_sample_t *taos_metric_sample_new(taos_metric_type_t type, const char
}
int taos_metric_sample_destroy(taos_metric_sample_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 0;
taos_free((void *)self->l_value);
self->l_value = NULL;
@ -67,7 +67,7 @@ void taos_metric_sample_free_generic(void *gen) {
}
int taos_metric_sample_add(taos_metric_sample_t *self, double r_value) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (r_value < 0) {
return 1;
}
@ -94,14 +94,14 @@ int taos_metric_sample_add(taos_metric_sample_t *self, double r_value) {
/*
int taos_metric_sample_sub(taos_metric_sample_t *self, double r_value) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self->type != TAOS_GAUGE) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
return 1;
}
#ifdef C11_ATOMIC
///_Atomic/
///_Atomic/
double old = atomic_load(&self->r_value);
for (;;) {
_Atomic double new = ATOMIC_VAR_INIT(old - r_value);

View File

@ -52,7 +52,7 @@ taos_string_builder_t *taos_string_builder_new(void) {
}
int taos_string_builder_init(taos_string_builder_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
self->str = (char *)taos_malloc(self->init_size);
*self->str = '\0';
@ -62,7 +62,7 @@ int taos_string_builder_init(taos_string_builder_t *self) {
}
int taos_string_builder_destroy(taos_string_builder_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 0;
taos_free(self->str);
self->str = NULL;
@ -78,7 +78,7 @@ int taos_string_builder_destroy(taos_string_builder_t *self) {
* is called in methods that need to add one or more characters to the underlying string.
*/
static int taos_string_builder_ensure_space(taos_string_builder_t *self, size_t add_len) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (add_len == 0 || self->allocated >= self->len + add_len + 1) return 0;
while (self->allocated < self->len + add_len + 1) self->allocated <<= 1;
@ -87,7 +87,7 @@ static int taos_string_builder_ensure_space(taos_string_builder_t *self, size_t
}
int taos_string_builder_add_str(taos_string_builder_t *self, const char *str) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
if (self == NULL) return 1;
@ -104,7 +104,7 @@ int taos_string_builder_add_str(taos_string_builder_t *self, const char *str) {
}
int taos_string_builder_add_char(taos_string_builder_t *self, char c) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
int r = 0;
if (self == NULL) return 1;
@ -118,7 +118,7 @@ int taos_string_builder_add_char(taos_string_builder_t *self, char c) {
}
int taos_string_builder_truncate(taos_string_builder_t *self, size_t len) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1;
if (len >= self->len) return 0;
@ -128,19 +128,19 @@ int taos_string_builder_truncate(taos_string_builder_t *self, size_t len) {
}
int taos_string_builder_clear(taos_string_builder_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
taos_free(self->str);
self->str = NULL;
return taos_string_builder_init(self);
}
size_t taos_string_builder_len(taos_string_builder_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA(self != NULL);
return self->len;
}
char *taos_string_builder_dump(taos_string_builder_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
// +1 to accommodate \0
char *out = (char *)taos_malloc((self->len + 1) * sizeof(char));
memcpy(out, self->str, self->len + 1);
@ -148,6 +148,6 @@ char *taos_string_builder_dump(taos_string_builder_t *self) {
}
char *taos_string_builder_str(taos_string_builder_t *self) {
TAOS_ASSERT(self != NULL);
TAOS_TEST_PARA_NULL(self != NULL);
return self->str;
}