From 9373e766555049283d5536a03b3fc92f2510e794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Fri, 31 Jan 2025 12:34:31 +0100 Subject: [PATCH] shared: Rename NULL and not NULL pointer assertions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the NULL assertions more explicit. weston_assert_ptr_is_null() -> weston_assert_ptr_null() weston_assert_ptr() -> weston_assert_ptr_not_null() Signed-off-by: Loïc Molinari --- libweston/backend-drm/state-propose.c | 4 ++-- libweston/color-lcms/color-lcms.c | 6 +++--- libweston/color-lcms/color-profile.c | 2 +- libweston/color-lcms/color-transform.c | 4 ++-- libweston/color-management.c | 2 +- libweston/color-noop.c | 4 ++-- libweston/color-profile-param-builder.c | 2 +- libweston/linux-dmabuf.c | 16 ++++++++-------- shared/weston-assert.h | 4 ++-- tests/assert-test.c | 8 ++++---- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libweston/backend-drm/state-propose.c b/libweston/backend-drm/state-propose.c index c09c08b79..376db524f 100644 --- a/libweston/backend-drm/state-propose.c +++ b/libweston/backend-drm/state-propose.c @@ -570,7 +570,7 @@ drm_output_find_plane_for_view(struct drm_output_state *state, possible_plane_mask &= fb->plane_mask; } else { char *fr_str = bits_to_str(fb_failure_reasons, failure_reasons_to_str); - weston_assert_ptr(b->compositor, fr_str); + weston_assert_ptr_not_null(b->compositor, fr_str); drm_debug(b, "\t\t\t[view] couldn't get FB for view: %s\n", fr_str); free(fr_str); pnode->try_view_on_plane_failure_reasons |= fb_failure_reasons; @@ -995,7 +995,7 @@ drm_output_propose_state(struct weston_output *output_base, } else if (!ps) { char *fr_str = bits_to_str(pnode->try_view_on_plane_failure_reasons, failure_reasons_to_str); - weston_assert_ptr(b->compositor, fr_str); + weston_assert_ptr_not_null(b->compositor, fr_str); drm_debug(b, "\t\t\t\t[view] view %p will be placed " "on the renderer: %s\n", ev, fr_str); free(fr_str); diff --git a/libweston/color-lcms/color-lcms.c b/libweston/color-lcms/color-lcms.c index 785ee75f8..28921c940 100644 --- a/libweston/color-lcms/color-lcms.c +++ b/libweston/color-lcms/color-lcms.c @@ -385,20 +385,20 @@ cmlcms_init(struct weston_color_manager *cm_base) weston_compositor_add_log_scope(compositor, "color-lcms-transformations", "Color transformation creation and destruction.\n", transforms_scope_new_sub, NULL, cm); - weston_assert_ptr(compositor, cm->transforms_scope); + weston_assert_ptr_not_null(compositor, cm->transforms_scope); cm->optimizer_scope = weston_compositor_add_log_scope(compositor, "color-lcms-optimizer", "Color transformation pipeline optimizer. It's best " \ "used together with the color-lcms-transformations " \ "log scope.\n", NULL, NULL, NULL); - weston_assert_ptr(compositor, cm->optimizer_scope); + weston_assert_ptr_not_null(compositor, cm->optimizer_scope); cm->profiles_scope = weston_compositor_add_log_scope(compositor, "color-lcms-profiles", "Color profile creation and destruction.\n", profiles_scope_new_sub, NULL, cm); - weston_assert_ptr(compositor, cm->profiles_scope); + weston_assert_ptr_not_null(compositor, cm->profiles_scope); cm->lcms_ctx = cmsCreateContext(NULL, cm); if (!cm->lcms_ctx) { diff --git a/libweston/color-lcms/color-profile.c b/libweston/color-lcms/color-profile.c index 9edd64925..98c127333 100644 --- a/libweston/color-lcms/color-profile.c +++ b/libweston/color-lcms/color-profile.c @@ -298,7 +298,7 @@ ensure_output_profile_extract(struct cmlcms_color_profile *cprof, cprof->icc.profile, num_points, err_msg); if (ret) - weston_assert_ptr(compositor, cprof->extract.eotf.p); + weston_assert_ptr_not_null(compositor, cprof->extract.eotf.p); break; case CMLCMS_PROFILE_TYPE_PARAMS: /* TODO: need to address this when we create param profiles. */ diff --git a/libweston/color-lcms/color-transform.c b/libweston/color-lcms/color-transform.c index d4a02c471..643186a97 100644 --- a/libweston/color-lcms/color-transform.c +++ b/libweston/color-lcms/color-transform.c @@ -1255,7 +1255,7 @@ xform_realize_chain(struct cmlcms_color_transform *xform) chain[chain_len++] = output_profile->extract.vcgt; /* Render intent does not apply here, but need to set something. */ - weston_assert_ptr_is_null(cm->base.compositor, render_intent); + weston_assert_ptr_null(cm->base.compositor, render_intent); render_intent = weston_render_intent_info_from(cm->base.compositor, WESTON_RENDER_INTENT_ABSOLUTE); break; @@ -1268,7 +1268,7 @@ xform_realize_chain(struct cmlcms_color_transform *xform) } assert(chain_len <= ARRAY_LENGTH(chain)); - weston_assert_ptr(cm->base.compositor, render_intent); + weston_assert_ptr_not_null(cm->base.compositor, render_intent); /** * Binding to our LittleCMS plug-in occurs here. diff --git a/libweston/color-management.c b/libweston/color-management.c index 725333d3c..3369dd6cc 100644 --- a/libweston/color-management.c +++ b/libweston/color-management.c @@ -500,7 +500,7 @@ cm_output_get_image_description(struct wl_client *client, * object inert. We do that in weston_head_remove_global(), and the * cm_output_res user data (which was the head itself) is set to NULL. * So if we reached here, head is active and head->output != NULL. */ - weston_assert_ptr(compositor, output); + weston_assert_ptr_not_null(compositor, output); cm_image_desc = cm_image_desc_create(compositor->color_manager, output->color_profile, client, diff --git a/libweston/color-noop.c b/libweston/color-noop.c index 2fdfbdacc..8b514072f 100644 --- a/libweston/color-noop.c +++ b/libweston/color-noop.c @@ -167,7 +167,7 @@ cmnoop_get_surface_color_transform(struct weston_color_manager *cm_base, cmnoop->stock_cprof); /* The output must have a cprof, and it has to be the stock one. */ - weston_assert_ptr(compositor, output->color_profile); + weston_assert_ptr_not_null(compositor, output->color_profile); weston_assert_ptr_eq(compositor, to_cmnoop_cprof(output->color_profile), cmnoop->stock_cprof); @@ -189,7 +189,7 @@ cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base, struct weston_color_manager_noop *cmnoop = to_cmnoop(cm_base); struct weston_output_color_outcome *co; - weston_assert_ptr(compositor, output->color_profile); + weston_assert_ptr_not_null(compositor, output->color_profile); weston_assert_ptr_eq(compositor, to_cmnoop_cprof(output->color_profile), cmnoop->stock_cprof); diff --git a/libweston/color-profile-param-builder.c b/libweston/color-profile-param-builder.c index 7e7efbf9d..b1c46baf9 100644 --- a/libweston/color-profile-param-builder.c +++ b/libweston/color-profile-param-builder.c @@ -101,7 +101,7 @@ weston_color_profile_param_builder_create(struct weston_compositor *compositor) builder->err_fp = open_memstream(&builder->err_msg, &builder->err_msg_size); - weston_assert_ptr(compositor, builder->err_fp); + weston_assert_ptr_not_null(compositor, builder->err_fp); return builder; } diff --git a/libweston/linux-dmabuf.c b/libweston/linux-dmabuf.c index d37121d76..927bff49c 100644 --- a/libweston/linux-dmabuf.c +++ b/libweston/linux-dmabuf.c @@ -97,7 +97,7 @@ params_add(struct wl_client *client, } weston_assert_ptr_eq(buffer->compositor, buffer->params_resource, params_resource); - weston_assert_ptr_is_null(buffer->compositor, buffer->buffer_resource); + weston_assert_ptr_null(buffer->compositor, buffer->buffer_resource); if (plane_idx >= MAX_DMABUF_PLANES) { wl_resource_post_error(params_resource, @@ -155,7 +155,7 @@ destroy_linux_dmabuf_wl_buffer(struct wl_resource *resource) buffer = wl_resource_get_user_data(resource); weston_assert_ptr_eq(buffer->compositor, buffer->buffer_resource, resource); - weston_assert_ptr_is_null(buffer->compositor, buffer->params_resource); + weston_assert_ptr_null(buffer->compositor, buffer->params_resource); if (buffer->user_data_destroy_func) buffer->user_data_destroy_func(buffer); @@ -185,7 +185,7 @@ params_create_common(struct wl_client *client, } weston_assert_ptr_eq(buffer->compositor, buffer->params_resource, params_resource); - weston_assert_ptr_is_null(buffer->compositor, buffer->buffer_resource); + weston_assert_ptr_null(buffer->compositor, buffer->buffer_resource); /* Switch the linux_dmabuf_buffer object from params resource to * eventually wl_buffer resource. @@ -971,8 +971,8 @@ linux_dmabuf_buffer_get(struct weston_compositor *compositor, return NULL; buffer = wl_resource_get_user_data(resource); - weston_assert_ptr(compositor, buffer); - weston_assert_ptr_is_null(compositor, buffer->params_resource); + weston_assert_ptr_not_null(compositor, buffer); + weston_assert_ptr_null(compositor, buffer->params_resource); weston_assert_ptr_eq(compositor, buffer->buffer_resource, resource); return buffer; @@ -1058,7 +1058,7 @@ bind_linux_dmabuf(struct wl_client *client, /* If we got here, it means that the renderer is able to import dma-buf * buffers, and so it must have get_supported_formats() set. */ - weston_assert_ptr(compositor, compositor->renderer->get_supported_formats); + weston_assert_ptr_not_null(compositor, compositor->renderer->get_supported_formats); supported_formats = compositor->renderer->get_supported_formats(compositor); wl_array_for_each(fmt, &supported_formats->arr) { @@ -1133,12 +1133,12 @@ linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer, struct wl_resource *display_resource; uint32_t id; - weston_assert_ptr(buffer->compositor, buffer->buffer_resource); + weston_assert_ptr_not_null(buffer->compositor, buffer->buffer_resource); id = wl_resource_get_id(buffer->buffer_resource); client = wl_resource_get_client(buffer->buffer_resource); display_resource = wl_client_get_object(client, 1); - weston_assert_ptr(buffer->compositor, display_resource); + weston_assert_ptr_not_null(buffer->compositor, display_resource); wl_resource_post_error(display_resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "linux_dmabuf server error with " diff --git a/shared/weston-assert.h b/shared/weston-assert.h index 5d2fa2491..162221d37 100644 --- a/shared/weston-assert.h +++ b/shared/weston-assert.h @@ -88,10 +88,10 @@ do { \ #define weston_assert_false(compositor, a) \ weston_assert_(compositor, a, false, bool, "%d", ==) -#define weston_assert_ptr(compositor, a) \ +#define weston_assert_ptr_not_null(compositor, a) \ weston_assert_(compositor, a, NULL, const void *, "%p", !=) -#define weston_assert_ptr_is_null(compositor, a) \ +#define weston_assert_ptr_null(compositor, a) \ weston_assert_(compositor, a, NULL, const void *, "%p", ==) #define weston_assert_ptr_eq(compositor, a, b) \ diff --git a/tests/assert-test.c b/tests/assert-test.c index 655d69e41..f2e1044c8 100644 --- a/tests/assert-test.c +++ b/tests/assert-test.c @@ -99,16 +99,16 @@ TEST(asserts) ret = weston_assert_true(compositor, true && false); abort_if_not(ret == false); - ret = weston_assert_ptr(compositor, &ret); + ret = weston_assert_ptr_not_null(compositor, &ret); abort_if_not(ret); - ret = weston_assert_ptr(compositor, NULL); + ret = weston_assert_ptr_not_null(compositor, NULL); abort_if_not(ret == false); - ret = weston_assert_ptr_is_null(compositor, NULL); + ret = weston_assert_ptr_null(compositor, NULL); abort_if_not(ret); - ret = weston_assert_ptr_is_null(compositor, &ret); + ret = weston_assert_ptr_null(compositor, &ret); abort_if_not(ret == false); ret = weston_assert_ptr_eq(compositor, &ret, &ret);