Skip to content

Commit 8bf7cb5

Browse files
authored
Merge pull request #870 from openziti/misc-improvements
Misc improvements
2 parents b9b1949 + dc9038d commit 8bf7cb5

File tree

6 files changed

+31
-27
lines changed

6 files changed

+31
-27
lines changed

inc_internal/internal_model.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#include "ziti/model_support.h"
2020
#include "ziti/ziti_model.h"
2121

22+
// internal model is not exported
23+
#ifdef MODEL_VISIBILITY
24+
#undef MODEL_VISIBILITY
25+
#endif
26+
#define MODEL_VISIBILITY
27+
2228
// extends ziti_identity
2329
#define ZITI_IDENTITY_DATA_MODEL(XX, ...) \
2430
ZITI_IDENTITY_MODEL(XX, __VA_ARGS__) \

inc_internal/utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ typedef int *(*cond_error_t)(int);
7575

7676
#if __GNUC__
7777
#define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
78+
#define THREAD_LOCAL __thread
7879
#elif _MSC_VER
80+
#define THREAD_LOCAL __declspec(thread)
7981
#define UNUSED(x) UNUSED_ ## x
8082
#else
83+
#define THREAD_LOCAL
8184
#define UNUSED(x) UNUSED_ ## x
8285
#endif
8386

includes/ziti/model_support.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef intptr_t ssize_t;
6565
* `indent` is used for printing nested model objects
6666
*/
6767

68-
#define MODEL_API
68+
#define MODEL_VISIBILITY
6969

7070
#define MODEL_JSON_COMPACT 0x1
7171

@@ -85,16 +85,16 @@ DECLARE_MODEL_FUNCS(type)
8585

8686
#define DECLARE_MODEL_FUNCS(T) \
8787
typedef T ** T##_array; \
88-
MODEL_API const type_meta* get_##T##_meta();\
88+
MODEL_VISIBILITY const type_meta* get_##T##_meta();\
8989
static inline ptr(T) alloc_##T(){ return (ptr(T))model_alloc(get_##T##_meta()); }\
9090
static inline void free_##T(ptr(T) v) { model_free(v, get_##T##_meta()); } \
9191
static inline void free_##T##_ptr(ptr(T) v) { model_free(v, get_##T##_meta()); free(v); }; \
9292
static inline int cmp_##T(const ptr(T) lh, const ptr(T) rh) { return model_cmp(lh, rh, get_##T##_meta()); } \
93-
MODEL_API void free_##T##_array(array(T) *ap);\
94-
MODEL_API int parse_##T(ptr(T) v, const char* json, size_t len);\
95-
MODEL_API int parse_##T##_ptr(ptr(T) *p, const char* json, size_t len);\
96-
MODEL_API int parse_##T##_array(array(T) *a, const char* json, size_t len); \
97-
MODEL_API int parse_##T##_list(list(T) *l, const char* json, size_t len); \
93+
MODEL_VISIBILITY void free_##T##_array(array(T) *ap);\
94+
MODEL_VISIBILITY int parse_##T(ptr(T) v, const char* json, size_t len);\
95+
MODEL_VISIBILITY int parse_##T##_ptr(ptr(T) *p, const char* json, size_t len);\
96+
MODEL_VISIBILITY int parse_##T##_array(array(T) *a, const char* json, size_t len); \
97+
MODEL_VISIBILITY int parse_##T##_list(list(T) *l, const char* json, size_t len); \
9898
static inline ssize_t T##_to_json_r(const ptr(T) v, int flags, char *outbuf, size_t max) { return model_to_json_r(v, get_##T##_meta(), flags, outbuf, max); } \
9999
static inline char* T##_to_json(const ptr(T) v, int flags, size_t *len) { return model_to_json(v, get_##T##_meta(), flags, len); } \
100100
static inline int T##_from_json(ptr(T) v, struct json_object *j) { return model_from_json(v, j, get_##T##_meta()); } \
@@ -276,7 +276,7 @@ Enum (*value_of)(const char* n); \
276276
Enum (*value_ofn)(const char* s, size_t n); \
277277
Values(enum_field, Enum) \
278278
}; \
279-
MODEL_API const type_meta* get_##Enum##_meta();\
279+
MODEL_VISIBILITY const type_meta* get_##Enum##_meta();\
280280
extern const struct Enum##_s Enum##s;
281281

282282
#define get_value_of_ovrd(_1, _2, _3, _4, _5, NAME, ...) NAME

includes/ziti/ziti_model.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ typedef struct ziti_address_s {
224224

225225

226226
// make sure ziti model functions are properly exported
227-
#ifdef MODEL_API
228-
#undef MODEL_API
227+
#ifdef MODEL_VISIBILITY
228+
#undef MODEL_VISIBILITY
229229
#endif
230-
#define MODEL_API ZITI_FUNC
230+
#define MODEL_VISIBILITY ZITI_FUNC
231231

232232
ZITI_FUNC int parse_ziti_address_str(ziti_address *addr, const char *addr_str);
233233

library/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ function(config_ziti_library target)
124124
set_target_properties(${target} PROPERTIES
125125
C_STANDARD 11
126126
POSITION_INDEPENDENT_CODE ON
127+
C_VISIBILITY_PRESET hidden
128+
CXX_VISIBILITY_PRESET hidden
127129
)
128130

129131
target_sources(${target} PRIVATE ${ZITI_PRIVATE_SRC_FILES})

library/utils.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ static uint64_t starttime;
132132
static uint64_t last_update;
133133
static char log_timestamp[32];
134134

135-
static uv_key_t logbufs;
136-
137135
static log_writer logger = NULL;
138136

139137
static void init_debug(uv_loop_t *loop);
@@ -262,7 +260,6 @@ static void init_debug(uv_loop_t *loop) {
262260
#if defined(PTHREAD_ONCE_INIT)
263261
pthread_atfork(NULL, NULL, child_init);
264262
#endif
265-
uv_key_create(&logbufs);
266263
log_pid = uv_os_getpid();
267264
get_elapsed = get_elapsed_time;
268265
char *ts_format = getenv("ZITI_TIME_FORMAT");
@@ -320,22 +317,18 @@ static const char *basename(const char *path) {
320317
return path;
321318
}
322319

323-
void ziti_logger(int level, const char *module, const char *file, unsigned int line, const char *func, FORMAT_STRING(const char *fmt), ...) {
324320
#ifdef ZITI_DEBUG
325-
static size_t loglinelen = 32768;
321+
#define LOG_LINE_LENGTH 32768
326322
#else
327-
static size_t loglinelen = 1024;
323+
#define LOG_LINE_LENGTH 1024
328324
#endif
329325

326+
static THREAD_LOCAL char log_buf[LOG_LINE_LENGTH];
327+
328+
void ziti_logger(int level, const char *module, const char *file, unsigned int line, const char *func, FORMAT_STRING(const char *fmt), ...) {
330329
log_writer logfunc = logger;
331330
if (logfunc == NULL) { return; }
332331

333-
char *logbuf = (char *) uv_key_get(&logbufs);
334-
if (!logbuf) {
335-
logbuf = malloc(loglinelen);
336-
uv_key_set(&logbufs, logbuf);
337-
}
338-
339332
char location[128];
340333
char *last_slash = strrchr(file, DIR_SEP);
341334

@@ -370,14 +363,14 @@ void ziti_logger(int level, const char *module, const char *file, unsigned int l
370363

371364
va_list argp;
372365
va_start(argp, fmt);
373-
int len = vsnprintf(logbuf, loglinelen, fmt, argp);
366+
int len = vsnprintf(log_buf, sizeof(log_buf), fmt, argp);
374367
va_end(argp);
375368

376-
if (len > loglinelen) {
377-
len = (int) loglinelen;
369+
if (len > sizeof(log_buf)) {
370+
len = (int) sizeof(log_buf);
378371
}
379372

380-
logfunc(level, location, logbuf, len);
373+
logfunc(level, location, log_buf, len);
381374
}
382375

383376
static void default_log_writer(int level, const char *loc, const char *msg, size_t msglen) {

0 commit comments

Comments
 (0)