Skip to content

Commit

Permalink
- address review feedback
Browse files Browse the repository at this point in the history
Required-githooks: true

Signed-off-by: Alexander A Oganezov <[email protected]>
  • Loading branch information
frostedcmos committed Jun 8, 2024
1 parent 2b449c8 commit 9e11079
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/cart/crt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "crt_internal.h"

struct crt_gdata crt_gdata;
struct crt_envs_t g_envs;
struct crt_envs crt_genvs;
static volatile int gdata_init_flag;
struct crt_plugin_gdata crt_plugin_gdata;
static bool g_prov_settings_applied[CRT_PROV_COUNT];
Expand Down Expand Up @@ -55,7 +55,7 @@ crt_lib_init(void)
crt_gdata.cg_iv_inline_limit = 19456; /* 19KB */

/* envs not inited until crt_init() time */
memset(&g_envs, 0x0, sizeof(struct crt_envs_t));
memset(&crt_genvs, 0x0, sizeof(crt_genvs));
}

/* Library deinit */
Expand Down
39 changes: 20 additions & 19 deletions src/cart/crt_internal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct crt_event_cb_priv {

#define ENV_STR_NO_PRINT(x) ENV_STR(x)

struct crt_envs_t {
struct crt_envs {
CRT_ENV_LIST;
bool inited;
};
Expand All @@ -238,48 +238,49 @@ struct crt_envs_t {
#undef ENV_STR
#undef ENV_STR_NO_PRINT

extern struct crt_envs_t g_envs;
extern struct crt_envs crt_genvs;

static inline void
crt_env_fini(void);

static inline void
crt_env_init(void)
{
/* release strings if already inited previously */
if (g_envs.inited)
if (crt_genvs.inited)
crt_env_fini();

#define ENV(x) \
do { \
g_envs._rc_##x = d_getenv_uint(#x, &g_envs._##x); \
g_envs._no_print_##x = 0; \
crt_genvs._rc_##x = d_getenv_uint(#x, &crt_genvs._##x); \
crt_genvs._no_print_##x = 0; \
} while (0);

#define ENV_STR(x) \
do { \
g_envs._rc_##x = d_agetenv_str(&g_envs._##x, #x); \
g_envs._no_print_##x = 0; \
crt_genvs._rc_##x = d_agetenv_str(&crt_genvs._##x, #x); \
crt_genvs._no_print_##x = 0; \
} while (0);

#define ENV_STR_NO_PRINT(x) \
do { \
g_envs._rc_##x = d_agetenv_str(&g_envs._##x, #x); \
g_envs._no_print_##x = 1; \
crt_genvs._rc_##x = d_agetenv_str(&crt_genvs._##x, #x); \
crt_genvs._no_print_##x = 1; \
} while (0);

CRT_ENV_LIST;
#undef ENV
#undef ENV_STR
#undef ENV_STR_NO_PRINT

g_envs.inited = true;
crt_genvs.inited = true;
}

static inline void
crt_env_fini(void)
{
#define ENV(x) (void)
#define ENV_STR(x) d_freeenv_str(&g_envs._##x);
#define ENV_STR(x) d_freeenv_str(&crt_genvs._##x);
#define ENV_STR_NO_PRINT ENV_STR

CRT_ENV_LIST
Expand All @@ -288,14 +289,14 @@ crt_env_fini(void)
#undef ENV_STR
#undef ENV_STR_NO_PRINT

g_envs.inited = false;
crt_genvs.inited = false;
}

/* Returns value if env was present at load time */
#define crt_env_get(name, val) \
D_ASSERT(g_envs.inited); \
if (g_envs._rc_##name == 0) \
*val = g_envs._##name;
D_ASSERT(crt_genvs.inited); \
if (crt_genvs._rc_##name == 0) \
*val = crt_genvs._##name;

static inline void
crt_env_dump(void)
Expand All @@ -304,12 +305,12 @@ crt_env_dump(void)

/* Only dump envariables that were set */
#define ENV(x) \
if (!g_envs._rc_##x && g_envs._no_print_##x == 0) \
D_INFO("%s = %d\n", #x, g_envs._##x);
if (!crt_genvs._rc_##x && crt_genvs._no_print_##x == 0) \
D_INFO("%s = %d\n", #x, crt_genvs._##x);

#define ENV_STR(x) \
if (!g_envs._rc_##x) \
D_INFO("%s = %s\n", #x, g_envs._no_print_##x ? "****" : g_envs._##x);
if (!crt_genvs._rc_##x) \
D_INFO("%s = %s\n", #x, crt_genvs._no_print_##x ? "****" : crt_genvs._##x);

#define ENV_STR_NO_PRINT ENV_STR

Expand Down

0 comments on commit 9e11079

Please sign in to comment.