debug: Introduce VREND_DEBUG_ENABLED flag

VREND_DEBUG_ENABLED represents if debugging features are enabled and is
controlled by NDEBUG macro. By using VREND_DEBUG_ENABLED in
an if statement instead of using NDEBUG in ifdef, the compiler can
validate the content of the conditional and know its variable usage to
avoid meaningless warnings.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
macos/master
Akihiko Odaki 3 years ago
parent 18dcea9041
commit fbbc6728d7
  1. 19
      src/vrend_debug.h
  2. 3
      src/vrend_decode.c
  3. 14
      src/vrend_renderer.c

@ -79,31 +79,30 @@ static inline void vrend_printf(const char *fmt, ...)
va_end(va);
}
#ifndef NDEBUG
#ifdef NDEBUG
#define VREND_DEBUG_ENABLED (false)
#else
#define VREND_DEBUG_ENABLED (true)
#endif
#define VREND_DEBUG(flag, ctx, ...) \
if (vrend_debug(ctx, flag)) \
if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \
vrend_print_context_name(ctx); \
vrend_printf(__VA_ARGS__); \
} while (0)
#define VREND_DEBUG_EXT(flag, ctx, X) \
if (vrend_debug(ctx, flag)) \
if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \
vrend_print_context_name(ctx); \
X; \
} while (0)
#define VREND_DEBUG_NOCTX(flag, ctx, ...) \
if (vrend_debug(ctx, flag)) \
if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \
vrend_printf(__VA_ARGS__); \
} while (0)
#else
#define VREND_DEBUG(flag, ctx, ...) (void)ctx
#define VREND_DEBUG_EXT(flag, ctx, X) (void)ctx
#define VREND_DEBUG_NOCTX(flag, ctx, ...) (void)ctx
#endif
#endif

@ -1711,10 +1711,7 @@ static int vrend_decode_ctx_submit_cmd(struct virgl_context *ctx,
uint32_t buf_offset = 0;
while (buf_offset < buf_total) {
#ifndef NDEBUG
const uint32_t cur_offset = buf_offset;
#endif
const uint32_t *buf = &typed_buf[buf_offset];
uint32_t len = *buf >> 16;
uint32_t cmd = *buf & 0xff;

@ -3864,11 +3864,9 @@ int vrend_create_shader(struct vrend_context *ctx,
free(tokens);
ret = EINVAL;
goto error;
} else {
#ifdef NDEBUG
free(sel->tmp_buf);
sel->tmp_buf = NULL;
#endif
} else if (!VREND_DEBUG_ENABLED) {
free(sel->tmp_buf);
sel->tmp_buf = NULL;
}
free(tokens);
sub_ctx->long_shader_in_progress_handle[type] = 0;
@ -6489,9 +6487,9 @@ int vrend_renderer_init(const struct vrend_if_cbs *cbs, uint32_t flags)
vrend_state.max_texture_3d_size =
vrend_state.max_texture_cube_size = 16384;
#ifndef NDEBUG
vrend_init_debug_flags();
#endif
if (VREND_DEBUG_ENABLED) {
vrend_init_debug_flags();
}
ctx_params.shared = false;
for (uint32_t i = 0; i < ARRAY_SIZE(gl_versions); i++) {

Loading…
Cancel
Save