Use standard __VA_OPT__ instead of GNU's ##__VA_ARGS__

C23 has standardized a way to write variadic macros that accept
zero arguments:
https://open-std.org/JTC1/SC22/WG14/www/docs/n3033.htm

Use that instead of the GNU extension when available.
This commit is contained in:
Simon Ser 2024-01-05 11:48:33 +01:00 committed by Simon Zeni
parent 315e022f2f
commit 3880ee15d7
3 changed files with 33 additions and 3 deletions

View File

@ -220,9 +220,20 @@ void drm_page_flip_destroy(struct wlr_drm_page_flip *page_flip);
struct wlr_drm_layer *get_drm_layer(struct wlr_drm_backend *drm, struct wlr_drm_layer *get_drm_layer(struct wlr_drm_backend *drm,
struct wlr_output_layer *layer); struct wlr_output_layer *layer);
#if __STDC_VERSION__ >= 202311L
#define wlr_drm_conn_log(conn, verb, fmt, ...) \
wlr_log(verb, "connector %s: " fmt, conn->name __VA_OPT__(,) __VA_ARGS__)
#define wlr_drm_conn_log_errno(conn, verb, fmt, ...) \
wlr_log_errno(verb, "connector %s: " fmt, conn->name __VA_OPT(,) __VA_ARGS__)
#else
#define wlr_drm_conn_log(conn, verb, fmt, ...) \ #define wlr_drm_conn_log(conn, verb, fmt, ...) \
wlr_log(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__) wlr_log(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)
#define wlr_drm_conn_log_errno(conn, verb, fmt, ...) \ #define wlr_drm_conn_log_errno(conn, verb, fmt, ...) \
wlr_log_errno(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__) wlr_log_errno(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)
#endif #endif
#endif

View File

@ -515,7 +515,16 @@ void vulkan_change_layout(VkCommandBuffer cb, VkImage img,
VkImageLayout ol, VkPipelineStageFlags srcs, VkAccessFlags srca, VkImageLayout ol, VkPipelineStageFlags srcs, VkAccessFlags srca,
VkImageLayout nl, VkPipelineStageFlags dsts, VkAccessFlags dsta); VkImageLayout nl, VkPipelineStageFlags dsts, VkAccessFlags dsta);
#if __STDC_VERSION__ >= 202311L
#define wlr_vk_error(fmt, res, ...) wlr_log(WLR_ERROR, fmt ": %s (%d)", \
vulkan_strerror(res), res __VA_OPT(,) __VA_ARGS__)
#else
#define wlr_vk_error(fmt, res, ...) wlr_log(WLR_ERROR, fmt ": %s (%d)", \ #define wlr_vk_error(fmt, res, ...) wlr_log(WLR_ERROR, fmt ": %s (%d)", \
vulkan_strerror(res), res, ##__VA_ARGS__) vulkan_strerror(res), res, ##__VA_ARGS__)
#endif
#endif // RENDER_VULKAN_H #endif // RENDER_VULKAN_H

View File

@ -64,13 +64,23 @@ void _wlr_vlog(enum wlr_log_importance verbosity, const char *format, va_list ar
#define _WLR_FILENAME __FILE__ #define _WLR_FILENAME __FILE__
#endif #endif
#define wlr_log(verb, fmt, ...) \
_wlr_log(verb, "[%s:%d] " fmt, _WLR_FILENAME, __LINE__, ##__VA_ARGS__)
#define wlr_vlog(verb, fmt, args) \ #define wlr_vlog(verb, fmt, args) \
_wlr_vlog(verb, "[%s:%d] " fmt, _WLR_FILENAME, __LINE__, args) _wlr_vlog(verb, "[%s:%d] " fmt, _WLR_FILENAME, __LINE__, args)
#if __STDC_VERSION__ >= 202311L
#define wlr_log(verb, fmt, ...) \
_wlr_log(verb, "[%s:%d] " fmt, _WLR_FILENAME, __LINE__ __VA_OPT__(,) __VA_ARGS__)
#define wlr_log_errno(verb, fmt, ...) \
wlr_log(verb, fmt ": %s" __VA_OPT__(,) __VA_ARGS__, strerror(errno))
#else
#define wlr_log(verb, fmt, ...) \
_wlr_log(verb, "[%s:%d] " fmt, _WLR_FILENAME, __LINE__, ##__VA_ARGS__)
#define wlr_log_errno(verb, fmt, ...) \ #define wlr_log_errno(verb, fmt, ...) \
wlr_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno)) wlr_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno))
#endif #endif
#endif