Improve LV_FORMAT_ATTRIBUTE usage (#2673)
* fix(format): remove LV_FORMAT_ATTRIBUTE from the function body since it's enough to append LV_FORMAT_ATTRIBUTE to function declaration Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> * fix(format): add LV_FORMAT_ATTRIBUTE to lv_snprintf and lv_log Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> * fix(format): fix the format specifier warning Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
@@ -402,7 +402,7 @@ static lv_event_dsc_t * lv_obj_get_event_dsc(const lv_obj_t * obj, uint32_t id)
|
|||||||
|
|
||||||
static lv_res_t event_send_core(lv_event_t * e)
|
static lv_res_t event_send_core(lv_event_t * e)
|
||||||
{
|
{
|
||||||
EVENT_TRACE("Sending event %d to %p with %p param", e->code, e->current_target, e->param);
|
EVENT_TRACE("Sending event %d to %p with %p param", e->code, (void *)e->current_target, e->param);
|
||||||
|
|
||||||
/*Call the input device's feedback callback if set*/
|
/*Call the input device's feedback callback if set*/
|
||||||
lv_indev_t * indev_act = lv_indev_get_act();
|
lv_indev_t * indev_act = lv_indev_get_act();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ static uint32_t get_instance_size(const lv_obj_class_t * class_p);
|
|||||||
|
|
||||||
lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * parent)
|
lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * parent)
|
||||||
{
|
{
|
||||||
LV_TRACE_OBJ_CREATE("Creating object with %p class on %p parent", class_p, parent);
|
LV_TRACE_OBJ_CREATE("Creating object with %p class on %p parent", (void *)class_p, (void *)parent);
|
||||||
uint32_t s = get_instance_size(class_p);
|
uint32_t s = get_instance_size(class_p);
|
||||||
lv_obj_t * obj = lv_mem_alloc(s);
|
lv_obj_t * obj = lv_mem_alloc(s);
|
||||||
if(obj == NULL) return NULL;
|
if(obj == NULL) return NULL;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ static lv_obj_tree_walk_res_t walk_core(lv_obj_t * obj, lv_obj_tree_walk_cb_t cb
|
|||||||
|
|
||||||
void lv_obj_del(lv_obj_t * obj)
|
void lv_obj_del(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
LV_LOG_TRACE("begin (delete %p)", obj);
|
LV_LOG_TRACE("begin (delete %p)", (void *)obj);
|
||||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
lv_obj_invalidate(obj);
|
lv_obj_invalidate(obj);
|
||||||
|
|
||||||
@@ -78,12 +78,12 @@ void lv_obj_del(lv_obj_t * obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LV_ASSERT_MEM_INTEGRITY();
|
LV_ASSERT_MEM_INTEGRITY();
|
||||||
LV_LOG_TRACE("finished (delete %p)", obj);
|
LV_LOG_TRACE("finished (delete %p)", (void *)obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_obj_clean(lv_obj_t * obj)
|
void lv_obj_clean(lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
LV_LOG_TRACE("begin (delete %p)", obj);
|
LV_LOG_TRACE("begin (delete %p)", (void *)obj);
|
||||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
|
|
||||||
lv_obj_invalidate(obj);
|
lv_obj_invalidate(obj);
|
||||||
@@ -102,7 +102,7 @@ void lv_obj_clean(lv_obj_t * obj)
|
|||||||
|
|
||||||
LV_ASSERT_MEM_INTEGRITY();
|
LV_ASSERT_MEM_INTEGRITY();
|
||||||
|
|
||||||
LV_LOG_TRACE("finished (delete %p)", obj);
|
LV_LOG_TRACE("finished (delete %p)", (void *)obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_obj_del_delayed(lv_obj_t * obj, uint32_t delay_ms)
|
void lv_obj_del_delayed(lv_obj_t * obj, uint32_t delay_ms)
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ static lv_disp_t * disp_refr; /*Display being refreshed*/
|
|||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
#if LV_LOG_TRACE_DISP_REFR
|
#if LV_LOG_TRACE_DISP_REFR
|
||||||
#define TRACE_REFR(...) LV_LOG_TRACE( __VA_ARGS__)
|
#define REFR_TRACE(...) LV_LOG_TRACE(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define TRACE_REFR(...)
|
#define REFR_TRACE(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
@@ -181,7 +181,7 @@ void _lv_refr_set_disp_refreshing(lv_disp_t * disp)
|
|||||||
*/
|
*/
|
||||||
void _lv_disp_refr_timer(lv_timer_t * tmr)
|
void _lv_disp_refr_timer(lv_timer_t * tmr)
|
||||||
{
|
{
|
||||||
TRACE_REFR("begin");
|
REFR_TRACE("begin");
|
||||||
|
|
||||||
uint32_t start = lv_tick_get();
|
uint32_t start = lv_tick_get();
|
||||||
volatile uint32_t elaps = 0;
|
volatile uint32_t elaps = 0;
|
||||||
@@ -207,7 +207,7 @@ void _lv_disp_refr_timer(lv_timer_t * tmr)
|
|||||||
if(disp_refr->act_scr == NULL) {
|
if(disp_refr->act_scr == NULL) {
|
||||||
disp_refr->inv_p = 0;
|
disp_refr->inv_p = 0;
|
||||||
LV_LOG_WARN("there is no active screen");
|
LV_LOG_WARN("there is no active screen");
|
||||||
TRACE_REFR("finished");
|
REFR_TRACE("finished");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ void _lv_disp_refr_timer(lv_timer_t * tmr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TRACE_REFR("finished");
|
REFR_TRACE("finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LV_USE_PERF_MONITOR
|
#if LV_USE_PERF_MONITOR
|
||||||
@@ -962,8 +962,8 @@ static void draw_buf_flush(void)
|
|||||||
|
|
||||||
static void call_flush_cb(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p)
|
static void call_flush_cb(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p)
|
||||||
{
|
{
|
||||||
TRACE_REFR("Calling flush_cb on (%d;%d)(%d;%d) area with %p image pointer", area->x1, area->y1, area->x2, area->y2,
|
REFR_TRACE("Calling flush_cb on (%d;%d)(%d;%d) area with %p image pointer", area->x1, area->y1, area->x2, area->y2,
|
||||||
color_p);
|
(void *)color_p);
|
||||||
|
|
||||||
lv_area_t offset_area = {
|
lv_area_t offset_area = {
|
||||||
.x1 = area->x1 + drv->offset_x,
|
.x1 = area->x1 + drv->offset_x,
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ void lv_obj_set_style_flex_grow(lv_obj_t * obj, uint8_t value, lv_style_selector
|
|||||||
|
|
||||||
static void flex_update(lv_obj_t * cont, void * user_data)
|
static void flex_update(lv_obj_t * cont, void * user_data)
|
||||||
{
|
{
|
||||||
LV_LOG_INFO("update %p container", cont);
|
LV_LOG_INFO("update %p container", (void *)cont);
|
||||||
LV_UNUSED(user_data);
|
LV_UNUSED(user_data);
|
||||||
|
|
||||||
flex_t f;
|
flex_t f;
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ void lv_obj_set_style_grid_cell_y_align(lv_obj_t * obj, lv_coord_t value, lv_sty
|
|||||||
|
|
||||||
static void grid_update(lv_obj_t * cont, void * user_data)
|
static void grid_update(lv_obj_t * cont, void * user_data)
|
||||||
{
|
{
|
||||||
LV_LOG_INFO("update %p container", cont);
|
LV_LOG_INFO("update %p container", (void *)cont);
|
||||||
LV_UNUSED(user_data);
|
LV_UNUSED(user_data);
|
||||||
|
|
||||||
const lv_coord_t * col_templ = get_col_dsc(cont);
|
const lv_coord_t * col_templ = get_col_dsc(cont);
|
||||||
|
|||||||
@@ -37,11 +37,6 @@ extern "C" {
|
|||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
#if LV_USE_LOG && LV_LOG_TRACE_LAYOUT
|
|
||||||
# define LV_TRACE_LAYOUT(...) LV_LOG_TRACE( __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
# define LV_TRACE_LAYOUT(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /*extern "C"*/
|
} /*extern "C"*/
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
|||||||
#else
|
#else
|
||||||
lv_vaformat_t vaf = {format, &args};
|
lv_vaformat_t vaf = {format, &args};
|
||||||
lv_snprintf(buf, sizeof(buf), "[%s]\t(%" LV_PRId32 ".%03" LV_PRId32 ", +%" LV_PRId32 ")\t %s: %pV \t(in %s line #%d)\n",
|
lv_snprintf(buf, sizeof(buf), "[%s]\t(%" LV_PRId32 ".%03" LV_PRId32 ", +%" LV_PRId32 ")\t %s: %pV \t(in %s line #%d)\n",
|
||||||
lvl_prefix[level], t / 1000, t % 1000, t - last_log_time, func, &vaf, &file[p], line);
|
lvl_prefix[level], t / 1000, t % 1000, t - last_log_time, func, (void *)&vaf, &file[p], line);
|
||||||
#endif
|
#endif
|
||||||
custom_print_cb(buf);
|
custom_print_cb(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ extern "C" {
|
|||||||
#include "../lv_conf_internal.h"
|
#include "../lv_conf_internal.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "lv_types.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
@@ -77,7 +79,8 @@ void lv_log(const char * buf);
|
|||||||
* @param format printf-like format string
|
* @param format printf-like format string
|
||||||
* @param ... parameters for `format`
|
* @param ... parameters for `format`
|
||||||
*/
|
*/
|
||||||
void _lv_log_add(lv_log_level_t level, const char * file, int line, const char * func, const char * format, ...);
|
void _lv_log_add(lv_log_level_t level, const char * file, int line,
|
||||||
|
const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ void lv_mem_deinit(void)
|
|||||||
*/
|
*/
|
||||||
void * lv_mem_alloc(size_t size)
|
void * lv_mem_alloc(size_t size)
|
||||||
{
|
{
|
||||||
MEM_TRACE("allocating %d bytes", size);
|
MEM_TRACE("allocating %lu bytes", (unsigned long)size);
|
||||||
if(size == 0) {
|
if(size == 0) {
|
||||||
MEM_TRACE("using zero_mem");
|
MEM_TRACE("using zero_mem");
|
||||||
return &zero_mem;
|
return &zero_mem;
|
||||||
@@ -139,7 +139,7 @@ void * lv_mem_alloc(size_t size)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(alloc == NULL) {
|
if(alloc == NULL) {
|
||||||
LV_LOG_ERROR("couldn't allocate memory (%d bytes)", size);
|
LV_LOG_ERROR("couldn't allocate memory (%lu bytes)", (unsigned long)size);
|
||||||
lv_mem_monitor_t mon;
|
lv_mem_monitor_t mon;
|
||||||
lv_mem_monitor(&mon);
|
lv_mem_monitor(&mon);
|
||||||
LV_LOG_ERROR("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d",
|
LV_LOG_ERROR("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d",
|
||||||
@@ -180,7 +180,7 @@ void lv_mem_free(void * data)
|
|||||||
*/
|
*/
|
||||||
void * lv_mem_realloc(void * data_p, size_t new_size)
|
void * lv_mem_realloc(void * data_p, size_t new_size)
|
||||||
{
|
{
|
||||||
MEM_TRACE("reallocating %p with %d size", data_p, new_size);
|
MEM_TRACE("reallocating %p with %lu size", data_p, (unsigned long)new_size);
|
||||||
if(new_size == 0) {
|
if(new_size == 0) {
|
||||||
MEM_TRACE("using zero_mem");
|
MEM_TRACE("using zero_mem");
|
||||||
lv_mem_free(data_p);
|
lv_mem_free(data_p);
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ extern "C" {
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "lv_types.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char * fmt;
|
const char * fmt;
|
||||||
va_list * va;
|
va_list * va;
|
||||||
@@ -73,8 +75,8 @@ typedef struct {
|
|||||||
* null character. A value equal or larger than count indicates truncation. Only when the returned value
|
* null character. A value equal or larger than count indicates truncation. Only when the returned value
|
||||||
* is non-negative and less than count, the string has been completely written.
|
* is non-negative and less than count, the string has been completely written.
|
||||||
*/
|
*/
|
||||||
int lv_snprintf(char * buffer, size_t count, const char * format, ...);
|
int lv_snprintf(char * buffer, size_t count, const char * format, ...) LV_FORMAT_ATTRIBUTE(3, 4);
|
||||||
int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va);
|
int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va) LV_FORMAT_ATTRIBUTE(3, 0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include LV_SPRINTF_INCLUDE
|
#include LV_SPRINTF_INCLUDE
|
||||||
|
|||||||
@@ -308,16 +308,16 @@ static bool lv_timer_exec(lv_timer_t * timer)
|
|||||||
int32_t original_repeat_count = timer->repeat_count;
|
int32_t original_repeat_count = timer->repeat_count;
|
||||||
if(timer->repeat_count > 0) timer->repeat_count--;
|
if(timer->repeat_count > 0) timer->repeat_count--;
|
||||||
timer->last_run = lv_tick_get();
|
timer->last_run = lv_tick_get();
|
||||||
TIMER_TRACE("calling timer callback: %p", timer->timer_cb);
|
TIMER_TRACE("calling timer callback: %p", *((void **)&timer->timer_cb));
|
||||||
if(timer->timer_cb && original_repeat_count != 0) timer->timer_cb(timer);
|
if(timer->timer_cb && original_repeat_count != 0) timer->timer_cb(timer);
|
||||||
TIMER_TRACE("timer callback %p finished", timer->timer_cb);
|
TIMER_TRACE("timer callback %p finished", *((void **)&timer->timer_cb));
|
||||||
LV_ASSERT_MEM_INTEGRITY();
|
LV_ASSERT_MEM_INTEGRITY();
|
||||||
exec = true;
|
exec = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(timer_deleted == false) { /*The timer might be deleted by itself as well*/
|
if(timer_deleted == false) { /*The timer might be deleted by itself as well*/
|
||||||
if(timer->repeat_count == 0) { /*The repeat count is over, delete the timer*/
|
if(timer->repeat_count == 0) { /*The repeat count is over, delete the timer*/
|
||||||
TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb);
|
TIMER_TRACE("deleting timer with %p callback because the repeat count is over", *((void **)&timer->timer_cb));
|
||||||
lv_timer_del(timer);
|
lv_timer_del(timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ void _lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LV_FORMAT_ATTRIBUTE(1, 0) char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap)
|
char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap)
|
||||||
{
|
{
|
||||||
/*Allocate space for the new text by using trick from C99 standard section 7.19.6.12*/
|
/*Allocate space for the new text by using trick from C99 standard section 7.19.6.12*/
|
||||||
va_list ap_copy;
|
va_list ap_copy;
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text)
|
|||||||
lv_label_refr_text(obj);
|
lv_label_refr_text(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
LV_FORMAT_ATTRIBUTE(2, 3) void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
|
void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...)
|
||||||
{
|
{
|
||||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
LV_ASSERT_NULL(fmt);
|
LV_ASSERT_NULL(fmt);
|
||||||
|
|||||||
Reference in New Issue
Block a user