From e7cc4bc180d5bc77d5dd2bceae1a3da033b5c3f6 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 21 Mar 2021 08:50:49 -0700 Subject: [PATCH] fix(format): remove 0x prefix from %p (#2151) * fix(format): remove 0x prefix from %p since %p already add this prefix automatically * fix(printf): make %p more compatible with the standard --- src/core/lv_obj.c | 2 +- src/core/lv_obj_class.c | 4 ++-- src/core/lv_obj_tree.c | 8 ++++---- src/core/lv_refr.c | 2 +- src/extra/layouts/flex/lv_flex.c | 2 +- src/extra/layouts/grid/lv_grid.c | 2 +- src/misc/lv_mem.c | 14 +++++++------- src/misc/lv_printf.c | 33 +++++++++++++------------------- src/misc/lv_timer.c | 6 +++--- 9 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index f627381fc..45881464a 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -193,7 +193,7 @@ lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, void * param) LV_ASSERT_OBJ(obj, MY_CLASS); - EVENT_TRACE("Sending event %d to 0x%p with 0x%p param", event, obj, param); + EVENT_TRACE("Sending event %d to %p with %p param", event, obj, param); /*Build a simple linked list from the objects used in the events *It's important to know if an this object was deleted by a nested event diff --git a/src/core/lv_obj_class.c b/src/core/lv_obj_class.c index e8939c20a..88c47543a 100644 --- a/src/core/lv_obj_class.c +++ b/src/core/lv_obj_class.c @@ -42,7 +42,7 @@ static uint32_t get_instance_size(const lv_obj_class_t * class_p); lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class_p, lv_obj_t * parent, const lv_obj_t * copy) { - LV_TRACE_OBJ_CREATE("Creating object with 0x%p class on 0x%p parent", class_p, parent); + LV_TRACE_OBJ_CREATE("Creating object with %p class on %p parent", class_p, parent); uint32_t s = get_instance_size(class_p); lv_obj_t * obj = lv_mem_alloc(s); lv_memset_00(obj, s); @@ -66,7 +66,7 @@ lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class_p, lv_obj_t * p if(!copy) lv_theme_apply(obj); // else lv_style_list_copy(&checkbox->style_indic, &checkbox_copy->style_indic); - LV_TRACE_OBJ_CREATE("Object created at 0x%p address with 0x%p class on 0x%p parent", obj, class_p, parent); + LV_TRACE_OBJ_CREATE("Object created at %p address with %p class on %p parent", obj, class_p, parent); return obj; } diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index 555facc65..b447540ae 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -45,7 +45,7 @@ static void obj_del_core(lv_obj_t * obj); void lv_obj_del(lv_obj_t * obj) { - LV_LOG_TRACE("begin (delete 0x%p)", obj) + LV_LOG_TRACE("begin (delete %p)", obj) LV_ASSERT_OBJ(obj, MY_CLASS); lv_obj_invalidate(obj); @@ -82,12 +82,12 @@ void lv_obj_del(lv_obj_t * obj) } LV_ASSERT_MEM_INTEGRITY(); - LV_LOG_TRACE("finished (delete 0x%p)", obj) + LV_LOG_TRACE("finished (delete %p)", obj) } void lv_obj_clean(lv_obj_t * obj) { - LV_LOG_TRACE("begin (delete 0x%p)", obj) + LV_LOG_TRACE("begin (delete %p)", obj) LV_ASSERT_OBJ(obj, MY_CLASS); lv_obj_invalidate(obj); @@ -106,7 +106,7 @@ void lv_obj_clean(lv_obj_t * obj) LV_ASSERT_MEM_INTEGRITY(); - LV_LOG_TRACE("finished (delete 0x%p)", obj) + LV_LOG_TRACE("finished (delete %p)", obj) } void lv_obj_del_anim_ready_cb(lv_anim_t * a) diff --git a/src/core/lv_refr.c b/src/core/lv_refr.c index 725113155..4446faca0 100644 --- a/src/core/lv_refr.c +++ b/src/core/lv_refr.c @@ -925,6 +925,6 @@ 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) { - TRACE_REFR("Calling flush_cb on (%d;%d)(%d;%d) area with 0x%p image pointer", area->x1, area->y1, area->x2, area->y2, 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, color_p); drv->flush_cb(drv, area, color_p); } diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index 39d16e6b1..68f405eed 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -157,7 +157,7 @@ static void flex_update(lv_obj_t * cont) if(cont->spec_attr == NULL) return; const lv_flex_t * f = (const lv_flex_t *)cont->spec_attr->layout_dsc; - LV_LOG_INFO("update 0x%p container", cont); + LV_LOG_INFO("update %p container", cont); bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; bool row = f->dir == LV_FLEX_FLOW_ROW ? true : false; diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index e3600484f..6fa47dafb 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -122,7 +122,7 @@ static void grid_update(lv_obj_t * cont) if(cont->spec_attr == NULL) return; if(cont->spec_attr->layout_dsc == NULL) return; - LV_LOG_INFO("update 0x%p container", cont); + LV_LOG_INFO("update %p container", cont); full_refresh(cont); diff --git a/src/misc/lv_mem.c b/src/misc/lv_mem.c index ac20966ad..484210a71 100644 --- a/src/misc/lv_mem.c +++ b/src/misc/lv_mem.c @@ -140,7 +140,7 @@ void * lv_mem_alloc(size_t size) (int)mon.free_biggest_size); } - MEM_TRACE("allocated at 0x%p", alloc); + MEM_TRACE("allocated at %p", alloc); return alloc; } @@ -150,7 +150,7 @@ void * lv_mem_alloc(size_t size) */ void lv_mem_free(void * data) { - MEM_TRACE("freeing 0x%p", data); + MEM_TRACE("freeing %p", data); if(data == &zero_mem) return; if(data == NULL) return; @@ -173,7 +173,7 @@ void lv_mem_free(void * data) */ void * lv_mem_realloc(void * data_p, size_t new_size) { - MEM_TRACE("reallocating 0x%p with %d size", data_p, new_size); + MEM_TRACE("reallocating %p with %d size", data_p, new_size); if(new_size == 0) { MEM_TRACE("using zero_mem"); lv_mem_free(data_p); @@ -192,7 +192,7 @@ void * lv_mem_realloc(void * data_p, size_t new_size) return NULL; } - MEM_TRACE("allocated at 0x%p", new_p); + MEM_TRACE("allocated at %p", new_p); return new_p; } @@ -277,7 +277,7 @@ void * lv_mem_buf_get(uint32_t size) if(i_guess >= 0) { LV_GC_ROOT(lv_mem_buf[i_guess]).used = 1; - MEM_TRACE("returning already allocated buffer (buffer id: %d, address: 0x%p)", i_guess, LV_GC_ROOT(lv_mem_buf[i_guess]).p); + MEM_TRACE("returning already allocated buffer (buffer id: %d, address: %p)", i_guess, LV_GC_ROOT(lv_mem_buf[i_guess]).p); return LV_GC_ROOT(lv_mem_buf[i_guess]).p; } @@ -292,7 +292,7 @@ void * lv_mem_buf_get(uint32_t size) LV_GC_ROOT(lv_mem_buf[i]).used = 1; LV_GC_ROOT(lv_mem_buf[i]).size = size; LV_GC_ROOT(lv_mem_buf[i]).p = buf; - MEM_TRACE("allocated (buffer id: %d, address: 0x%p)", i, LV_GC_ROOT(lv_mem_buf[i]).p); + MEM_TRACE("allocated (buffer id: %d, address: %p)", i, LV_GC_ROOT(lv_mem_buf[i]).p); return LV_GC_ROOT(lv_mem_buf[i]).p; } } @@ -308,7 +308,7 @@ void * lv_mem_buf_get(uint32_t size) */ void lv_mem_buf_release(void * p) { - MEM_TRACE("begin (address: 0x%p)", p); + MEM_TRACE("begin (address: %p)", p); for(uint8_t i = 0; i < LV_MEM_BUF_MAX_NUM; i++) { if(LV_GC_ROOT(lv_mem_buf[i]).p == p) { diff --git a/src/misc/lv_printf.c b/src/misc/lv_printf.c index 8d141fd3a..1a31e78f5 100644 --- a/src/misc/lv_printf.c +++ b/src/misc/lv_printf.c @@ -679,6 +679,8 @@ static int _vsnprintf(out_fct_type out, char * buffer, const size_t maxlen, cons case 'u' : case 'x' : case 'X' : + case 'p' : + case 'P' : case 'o' : case 'b' : { // set the base @@ -686,6 +688,16 @@ static int _vsnprintf(out_fct_type out, char * buffer, const size_t maxlen, cons if(*format == 'x' || *format == 'X') { base = 16U; } + else if(*format == 'p' || *format == 'P') { + base = 16U; + flags |= FLAGS_HASH; // always hash for pointer format +#if defined(PRINTF_SUPPORT_LONG_LONG) + if(sizeof(uintptr_t) == sizeof(long long)) + flags |= FLAGS_LONG_LONG; + else +#endif + flags |= FLAGS_LONG; + } else if(*format == 'o') { base = 8U; } @@ -697,7 +709,7 @@ static int _vsnprintf(out_fct_type out, char * buffer, const size_t maxlen, cons flags &= ~FLAGS_HASH; // no hash for dec format } // uppercase - if(*format == 'X') { + if(*format == 'X' || *format == 'P') { flags |= FLAGS_UPPERCASE; } @@ -817,25 +829,6 @@ static int _vsnprintf(out_fct_type out, char * buffer, const size_t maxlen, cons break; } - case 'p' : { - width = sizeof(void *) * 2U; - flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE; -#if defined(PRINTF_SUPPORT_LONG_LONG) - const bool is_ll = sizeof(uintptr_t) == sizeof(long long); - if(is_ll) { - idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void *), false, 16U, precision, width, flags); - } - else { -#endif - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void *)), false, 16U, precision, width, - flags); -#if defined(PRINTF_SUPPORT_LONG_LONG) - } -#endif - format++; - break; - } - case '%' : out('%', buffer, idx++, maxlen); format++; diff --git a/src/misc/lv_timer.c b/src/misc/lv_timer.c index 038a6dbf5..b751c6284 100644 --- a/src/misc/lv_timer.c +++ b/src/misc/lv_timer.c @@ -286,9 +286,9 @@ static bool lv_timer_exec(lv_timer_t * timer) bool exec = false; if(lv_timer_time_remaining(timer) == 0) { timer->last_run = lv_tick_get(); - TIMER_TRACE("calling timer callback: 0x%p", timer->timer_cb); + TIMER_TRACE("calling timer callback: %p", timer->timer_cb); if(timer->timer_cb) timer->timer_cb(timer); - TIMER_TRACE("timer callback 0x%p finished", timer->timer_cb); + TIMER_TRACE("timer callback %p finished", timer->timer_cb); LV_ASSERT_MEM_INTEGRITY(); /*Delete if it was a one shot lv_timer*/ @@ -297,7 +297,7 @@ static bool lv_timer_exec(lv_timer_t * timer) timer->repeat_count--; } if(timer->repeat_count == 0) { - TIMER_TRACE("deleting timer with 0x%p callback because the repeat count is over", timer->timer_cb); + TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb); lv_timer_del(timer); } }