@cryptotaxi247 / netdata-1 / commits / bcb9c8682

Make libnetdata headers compilable by C++. (#10185)

Tomáš Kopal committed Nov 7, 2020 at 01:10 UTC bcb9c868275062212f20127c6b450e2770fe418c
15 files changed +46 -30
collectors/apps.plugin/apps_plugin.c
+2 -2
@@ -535,7 +535,7 @@ enum user_or_group_id_type {
535 struct user_or_group_ids{
536 enum user_or_group_id_type type;
537
538 - avl_tree index;
538 + avl_tree_type index;
539 struct user_or_group_id *root;
540
541 char filename[FILENAME_MAX + 1];
@@ -1691,7 +1691,7 @@ int file_descriptor_compare(void* a, void* b) {
1691
1692 // int file_descriptor_iterator(avl *a) { if(a) {}; return 0; }
1693
1694 -avl_tree all_files_index = {
1694 +avl_tree_type all_files_index = {
1695 NULL,
1696 file_descriptor_compare
1697 };
collectors/statsd.plugin/statsd.c
+1 -1
@@ -22,7 +22,7 @@
22 #define STATSD_FIRST_PTR_MUTEX_UNLOCK(index) netdata_mutex_unlock(&((index)->first_mutex))
23 #define STATSD_DICTIONARY_OPTIONS DICTIONARY_FLAG_DEFAULT
24 #else
25 -#define STATSD_AVL_TREE avl_tree
25 +#define STATSD_AVL_TREE avl_tree_type
26 #define STATSD_AVL_INSERT avl_insert
27 #define STATSD_AVL_SEARCH avl_search
28 #define STATSD_AVL_INDEX_INIT { .root = NULL, .compar = statsd_metric_compare }
collectors/tc.plugin/plugin_tc.c
+2 -2
@@ -81,7 +81,7 @@ struct tc_device {
81 RRDSET *st_tokens;
82 RRDSET *st_ctokens;
83
84 - avl_tree classes_index;
84 + avl_tree_type classes_index;
85
86 struct tc_class *classes;
87 struct tc_class *last_class;
@@ -102,7 +102,7 @@ static int tc_device_compare(void* a, void* b) {
102 else return strcmp(((struct tc_device *)a)->id, ((struct tc_device *)b)->id);
103 }
104
105 -avl_tree tc_device_root_index = {
105 +avl_tree_type tc_device_root_index = {
106 NULL,
107 tc_device_compare
108 };
database/rrdcalc.c
+3 -3
@@ -322,7 +322,7 @@ inline void rrdcalc_add_to_host(RRDHOST *host, RRDCALC *rc) {
322
323 if(rc->calculation) {
324 rc->calculation->status = &rc->status;
325 - rc->calculation->this = &rc->value;
325 + rc->calculation->myself = &rc->value;
326 rc->calculation->after = &rc->db_after;
327 rc->calculation->before = &rc->db_before;
328 rc->calculation->rrdcalc = rc;
@@ -330,7 +330,7 @@ inline void rrdcalc_add_to_host(RRDHOST *host, RRDCALC *rc) {
330
331 if(rc->warning) {
332 rc->warning->status = &rc->status;
333 - rc->warning->this = &rc->value;
333 + rc->warning->myself = &rc->value;
334 rc->warning->after = &rc->db_after;
335 rc->warning->before = &rc->db_before;
336 rc->warning->rrdcalc = rc;
@@ -338,7 +338,7 @@ inline void rrdcalc_add_to_host(RRDHOST *host, RRDCALC *rc) {
338
339 if(rc->critical) {
340 rc->critical->status = &rc->status;
341 - rc->critical->this = &rc->value;
341 + rc->critical->myself = &rc->value;
342 rc->critical->after = &rc->db_after;
343 rc->critical->before = &rc->db_before;
344 rc->critical->rrdcalc = rc;
libnetdata/avl/avl.c
+5 -5
@@ -17,7 +17,7 @@
17
18 /* Search |tree| for an item matching |item|, and return it if found.
19 Otherwise return |NULL|. */
20 -avl *avl_search(avl_tree *tree, avl *item) {
20 +avl *avl_search(avl_tree_type *tree, avl *item) {
21 avl *p;
22
23 // assert (tree != NULL && item != NULL);
@@ -40,7 +40,7 @@ avl *avl_search(avl_tree *tree, avl *item) {
40 If a duplicate item is found in the tree,
41 returns a pointer to the duplicate without inserting |item|.
42 */
43 -avl *avl_insert(avl_tree *tree, avl *item) {
43 +avl *avl_insert(avl_tree_type *tree, avl *item) {
44 avl *y, *z; /* Top node to update balance factor, and parent. */
45 avl *p, *q; /* Iterator, and parent. */
46 avl *n; /* Newly inserted node. */
@@ -136,7 +136,7 @@ avl *avl_insert(avl_tree *tree, avl *item) {
136
137 /* Deletes from |tree| and returns an item matching |item|.
138 Returns a null pointer if no matching item found. */
139 -avl *avl_remove(avl_tree *tree, avl *item) {
139 +avl *avl_remove(avl_tree_type *tree, avl *item) {
140 /* Stack of nodes. */
141 avl *pa[AVL_MAX_HEIGHT]; /* Nodes. */
142 unsigned char da[AVL_MAX_HEIGHT]; /* |avl_link[]| indexes. */
@@ -306,7 +306,7 @@ int avl_walker(avl *node, int (*callback)(void * /*entry*/, void * /*data*/), vo
306 return total;
307 }
308
309 -int avl_traverse(avl_tree *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
309 +int avl_traverse(avl_tree_type *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
310 if(tree->root)
311 return avl_walker(tree->root, callback, data);
312 else
@@ -396,7 +396,7 @@ int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void * /*entry*/, voi
396 return ret;
397 }
398
399 -void avl_init(avl_tree *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
399 +void avl_init(avl_tree_type *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
400 tree->root = NULL;
401 tree->compar = compar;
402 }
libnetdata/avl/avl.h
+8 -8
@@ -34,13 +34,13 @@ typedef struct avl {
34 } avl;
35
36 /* An AVL tree */
37 -typedef struct avl_tree {
37 +typedef struct avl_tree_type {
38 avl *root;
39 int (*compar)(void *a, void *b);
40 -} avl_tree;
40 +} avl_tree_type;
41
42 typedef struct avl_tree_lock {
43 - avl_tree avl_tree;
43 + avl_tree_type avl_tree;
44
45 #ifndef AVL_WITHOUT_PTHREADS
46 #ifdef AVL_LOCK_WITH_MUTEX
@@ -60,7 +60,7 @@ typedef struct avl_tree_lock {
60 * be properly allocated by the caller.
61 */
62 avl *avl_insert_lock(avl_tree_lock *tree, avl *item) NEVERNULL WARNUNUSED;
63 -avl *avl_insert(avl_tree *tree, avl *item) NEVERNULL WARNUNUSED;
63 +avl *avl_insert(avl_tree_type *tree, avl *item) NEVERNULL WARNUNUSED;
64
65 /* Remove an element a from the AVL tree t
66 * returns a pointer to the removed element
@@ -68,22 +68,22 @@ avl *avl_insert(avl_tree *tree, avl *item) NEVERNULL WARNUNUSED;
68 * (equal as returned by t->compar())
69 */
70 avl *avl_remove_lock(avl_tree_lock *tree, avl *item) WARNUNUSED;
71 -avl *avl_remove(avl_tree *tree, avl *item) WARNUNUSED;
71 +avl *avl_remove(avl_tree_type *tree, avl *item) WARNUNUSED;
72
73 /* Find the element into the tree that equal to a
74 * (equal as returned by t->compar())
75 * returns NULL is no element is equal to a
76 */
77 avl *avl_search_lock(avl_tree_lock *tree, avl *item);
78 -avl *avl_search(avl_tree *tree, avl *item);
78 +avl *avl_search(avl_tree_type *tree, avl *item);
79
80 /* Initialize the avl_tree_lock
81 */
82 void avl_init_lock(avl_tree_lock *tree, int (*compar)(void *a, void *b));
83 -void avl_init(avl_tree *tree, int (*compar)(void *a, void *b));
83 +void avl_init(avl_tree_type *tree, int (*compar)(void *a, void *b));
84
85
86 int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void *entry, void *data), void *data);
87 -int avl_traverse(avl_tree *tree, int (*callback)(void *entry, void *data), void *data);
87 +int avl_traverse(avl_tree_type *tree, int (*callback)(void *entry, void *data), void *data);
88
89 #endif /* avl.h */
libnetdata/config/appconfig.h
+2 -2
@@ -111,7 +111,7 @@
111 #define CONFIG_VALUE_CHECKED 0x08 // has been checked if the value is different from the default
112
113 struct config_option {
114 - avl avl; // the index entry of this entry - this has to be first!
114 + avl avl_node; // the index entry of this entry - this has to be first!
115
116 uint8_t flags;
117 uint32_t hash; // a simple hash to speed up searching
@@ -124,7 +124,7 @@ struct config_option {
124 };
125
126 struct section {
127 - avl avl; // the index entry of this section - this has to be first!
127 + avl avl_node; // the index entry of this section - this has to be first!
128
129 uint32_t hash; // a simple hash to speed up searching
130 // we first compare hashes, and only if the hashes are equal we do string comparisons
libnetdata/dictionary/dictionary.h
+2 -2
@@ -13,7 +13,7 @@ struct dictionary_stats {
13 };
14
15 typedef struct name_value {
16 - avl avl; // the index - this has to be first!
16 + avl avl_node; // the index - this has to be first!
17
18 uint32_t hash; // a simple hash to speed up searching
19 // we first compare hashes, and only if the hashes are equal we do string comparisons
@@ -23,7 +23,7 @@ typedef struct name_value {
23 } NAME_VALUE;
24
25 typedef struct dictionary {
26 - avl_tree values_index;
26 + avl_tree_type values_index;
27
28 uint8_t flags;
29
libnetdata/eval/eval.c
+1 -1
@@ -80,7 +80,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
80 }
81
82 if(unlikely(v->hash == this_hash && !strcmp(v->name, "this"))) {
83 - n = (exp->this)?*exp->this:NAN;
83 + n = (exp->myself)?*exp->myself:NAN;
84 buffer_strcat(exp->error_msg, "[ $this = ");
85 print_parsed_as_constant(exp->error_msg, n);
86 buffer_strcat(exp->error_msg, " ] ");
libnetdata/eval/eval.h
+1 -1
@@ -28,7 +28,7 @@ typedef struct eval_expression {
28 const char *parsed_as;
29
30 RRDCALC_STATUS *status;
31 - calculated_number *this;
31 + calculated_number *myself;
32 time_t *after;
33 time_t *before;
34
libnetdata/libnetdata.h
+8
@@ -3,6 +3,10 @@
3 #ifndef NETDATA_LIB_H
4 #define NETDATA_LIB_H 1
5
6 +# ifdef __cplusplus
7 +extern "C" {
8 +# endif
9 +
10 #ifdef HAVE_CONFIG_H
11 #include <config.h>
12 #endif
@@ -328,4 +332,8 @@ extern char *netdata_configured_host_prefix;
332 // BEWARE: Outside of the C code this also exists in alarm-notify.sh
333 #define DEFAULT_CLOUD_BASE_URL "https://app.netdata.cloud"
334
335 +# ifdef __cplusplus
336 +}
337 +# endif
338 +
339 #endif // NETDATA_LIB_H
libnetdata/log/log.h
+8
@@ -3,6 +3,10 @@
3 #ifndef NETDATA_LOG_H
4 #define NETDATA_LOG_H 1
5
6 +# ifdef __cplusplus
7 +extern "C" {
8 +# endif
9 +
10 #include "../libnetdata.h"
11
12 #define D_WEB_BUFFER 0x0000000000000001
@@ -98,4 +102,8 @@ extern void error_int( const char *prefix, const char *file, const char *functio
102 extern void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) NORETURN PRINTFLIKE(4, 5);
103 extern void log_access( const char *fmt, ... ) PRINTFLIKE(1, 2);
104
105 +# ifdef __cplusplus
106 +}
107 +# endif
108 +
109 #endif /* NETDATA_LOG_H */
registry/registry_internals.h
+1 -1
@@ -57,7 +57,7 @@ struct registry {
57 DICTIONARY *persons; // dictionary of REGISTRY_PERSON *, with key the REGISTRY_PERSON.guid
58 DICTIONARY *machines; // dictionary of REGISTRY_MACHINE *, with key the REGISTRY_MACHINE.guid
59
60 - avl_tree registry_urls_root_index;
60 + avl_tree_type registry_urls_root_index;
61
62 netdata_mutex_t lock;
63 };
registry/registry_person.h
+1 -1
@@ -30,7 +30,7 @@ typedef struct registry_person_url REGISTRY_PERSON_URL;
30 struct registry_person {
31 char guid[GUID_LEN + 1]; // the person GUID
32
33 - avl_tree person_urls; // dictionary of PERSON_URLs
33 + avl_tree_type person_urls; // dictionary of PERSON_URLs
34
35 uint32_t first_t; // the first time we saw this
36 uint32_t last_t; // the last time we saw this
spawn/spawn.h
+1 -1
@@ -58,7 +58,7 @@ struct spawn_cmd_info {
58
59 /* spawn command queue */
60 struct spawn_queue {
61 - avl_tree cmd_tree;
61 + avl_tree_type cmd_tree;
62
63 /* concurrency control of command queue */
64 uv_mutex_t mutex;