From 7265a79e46ebf85f4402bb672e82b2747cfd4ad7 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 25 May 2026 10:31:55 +0200 Subject: [PATCH] Drop "restrict" keyword The "restrict" keyword can be used to indicate that no other pointer will be used to access a chunk of memory while the restricted pointer is alive. If that promise is not upheld, undefined behavior is triggered. It may be difficult to ensure this property, and the property may be brittle - becoming invalid as code evolves. Just like "inline", let's just leave optimizations up to the compiler to figure out. --- backend/drm/util.c | 14 +++++++------- backend/session/session.c | 4 ++-- include/backend/drm/util.h | 6 +++--- include/backend/session/session.h | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/drm/util.c b/backend/drm/util.c index 1e0307dcb..57e68f33f 100644 --- a/backend/drm/util.c +++ b/backend/drm/util.c @@ -135,13 +135,13 @@ static bool is_taken(size_t n, const uint32_t arr[static n], uint32_t key) { */ struct match_state { const size_t num_conns; - const uint32_t *restrict conns; + const uint32_t *conns; const size_t num_crtcs; size_t score; size_t replaced; - uint32_t *restrict res; - uint32_t *restrict best; - const uint32_t *restrict orig; + uint32_t *res; + uint32_t *best; + const uint32_t *orig; bool exit_early; }; @@ -236,9 +236,9 @@ static bool match_connectors_with_crtcs_(struct match_state *st, } void match_connectors_with_crtcs(size_t num_conns, - const uint32_t conns[static restrict num_conns], - size_t num_crtcs, const uint32_t prev_crtcs[static restrict num_crtcs], - uint32_t new_crtcs[static restrict num_crtcs]) { + const uint32_t conns[static num_conns], + size_t num_crtcs, const uint32_t prev_crtcs[static num_crtcs], + uint32_t new_crtcs[static num_crtcs]) { uint32_t solution[num_crtcs]; for (size_t i = 0; i < num_crtcs; ++i) { solution[i] = UNMATCHED; diff --git a/backend/session/session.c b/backend/session/session.c index 868774399..1e587f793 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -395,8 +395,8 @@ bool wlr_session_change_vt(struct wlr_session *session, unsigned vt) { /* Tests if 'path' is KMS compatible by trying to open it. Returns the opened * device on success. */ -struct wlr_device *session_open_if_kms(struct wlr_session *restrict session, - const char *restrict path) { +struct wlr_device *session_open_if_kms(struct wlr_session *session, + const char *path) { if (!path) { return NULL; } diff --git a/include/backend/drm/util.h b/include/backend/drm/util.h index 9ba5f435e..a7d36638d 100644 --- a/include/backend/drm/util.h +++ b/include/backend/drm/util.h @@ -34,8 +34,8 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, * new_crtcs is populated with the new connector indices. */ void match_connectors_with_crtcs(size_t num_conns, - const uint32_t conns[static restrict num_conns], - size_t num_crtcs, const uint32_t prev_crtcs[static restrict num_crtcs], - uint32_t new_crtcs[static restrict num_crtcs]); + const uint32_t conns[static num_conns], + size_t num_crtcs, const uint32_t prev_crtcs[static num_crtcs], + uint32_t new_crtcs[static num_crtcs]); #endif diff --git a/include/backend/session/session.h b/include/backend/session/session.h index 0275f69fa..f3ff9f5bd 100644 --- a/include/backend/session/session.h +++ b/include/backend/session/session.h @@ -14,7 +14,7 @@ bool libseat_change_vt(struct wlr_session *base, unsigned vt); void session_init(struct wlr_session *session); -struct wlr_device *session_open_if_kms(struct wlr_session *restrict session, - const char *restrict path); +struct wlr_device *session_open_if_kms(struct wlr_session *session, + const char *path); #endif