src: switch asserts to wl_abort

assert()s can be compiled away by #defining NDEBUG. Some build systems
do this. Using wl_abort gives a human readable error message and it
isn't compiled away. This commit closes issue #230.

Signed-off-by: meltq <tejasvipin76@gmail.com>
This commit is contained in:
meltq 2024-06-30 22:36:11 +05:30 committed by Tejas Vipin
parent fa1811ce3e
commit 0cecde304f
5 changed files with 36 additions and 16 deletions

View file

@ -75,7 +75,8 @@ struct wl_connection {
static inline size_t
size_pot(uint32_t size_bits)
{
assert(size_bits < 8 * sizeof(size_t));
if (!(size_bits < 8 * sizeof(size_t)))
wl_abort("Too many bits for size_t\n");
return ((size_t)1) << size_bits;
}

View file

@ -447,7 +447,8 @@ wl_timer_heap_disarm(struct wl_timer_heap *timers,
struct wl_event_source_timer *last_end_evt;
int old_source_idx;
assert(source->heap_idx >= 0);
if (!(source->heap_idx >= 0))
wl_abort("Timer has already been disarmed\n");
old_source_idx = source->heap_idx;
source->heap_idx = -1;
@ -476,7 +477,8 @@ wl_timer_heap_arm(struct wl_timer_heap *timers,
struct wl_event_source_timer *source,
struct timespec deadline)
{
assert(source->heap_idx == -1);
if (!(source->heap_idx == -1))
wl_abort("Timer is already armed\n");
source->deadline = deadline;
timers->data[timers->active] = source;

View file

@ -235,13 +235,16 @@ wl_event_queue_init(struct wl_event_queue *queue,
static void
wl_proxy_unref(struct wl_proxy *proxy)
{
assert(proxy->refcount > 0);
if (!(proxy->refcount > 0))
wl_abort("Proxy requested for unref has no references\n");
if (--proxy->refcount > 0)
return;
/* If we get here, the client must have explicitly requested
* deletion. */
assert(proxy->flags & WL_PROXY_FLAG_DESTROYED);
if (!(proxy->flags & WL_PROXY_FLAG_DESTROYED))
wl_abort("Proxy with no references not yet explicitly"
"destroyed\n");
free(proxy);
}
@ -1172,7 +1175,8 @@ connect_to_socket(const char *name)
"%s", name) + 1;
}
assert(name_size > 0);
if (!(name_size > 0))
wl_abort("Error assigning path name for socket connection\n");
if (name_size > (int)sizeof addr.sun_path) {
if (!path_is_absolute) {
wl_log("error: socket path \"%s/%s\" plus null terminator"
@ -2453,7 +2457,9 @@ wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue)
wl_list_remove(&proxy->queue_link);
if (queue) {
assert(proxy->display == queue->display);
if (!(proxy->display == queue->display))
wl_abort("Proxy and queue point to different "
"wl_displays");
proxy->queue = queue;
} else {
proxy->queue = &proxy->display->default_queue;
@ -2581,7 +2587,8 @@ wl_proxy_wrapper_destroy(void *proxy_wrapper)
wl_abort("Tried to destroy non-wrapper proxy with "
"wl_proxy_wrapper_destroy\n");
assert(wrapper->refcount == 1);
if (!(wrapper->refcount == 1))
wl_abort("Expected proxy wrapper's refcount to be 1\n");
pthread_mutex_lock(&wrapper->display->mutex);

View file

@ -1714,7 +1714,8 @@ wl_socket_init_for_display_name(struct wl_socket *s, const char *name)
name_size = snprintf(s->addr.sun_path, sizeof s->addr.sun_path,
"%s%s%s", runtime_dir, separator, name) + 1;
assert(name_size > 0);
if (!(name_size > 0))
wl_abort("Error assigning path name for socket address\n");
if (name_size > (int)sizeof s->addr.sun_path) {
wl_log("error: socket path \"%s%s%s\" plus null terminator"
" exceeds 108 bytes\n", runtime_dir, separator, name);

View file

@ -144,12 +144,17 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external)
{
if (external) {
pool->external_refcount--;
assert(pool->external_refcount >= 0);
if (!(pool->external_refcount >= 0))
wl_abort("Requested to unref an external reference to "
"pool but none found\n");
if (pool->external_refcount == 0)
shm_pool_finish_resize(pool);
} else {
pool->internal_refcount--;
assert(pool->internal_refcount >= 0);
if (!(pool->internal_refcount >= 0))
wl_abort("Requested to unref an internal reference to "
"pool but none found\n");
}
if (pool->internal_refcount + pool->external_refcount > 0)
@ -509,8 +514,9 @@ wl_shm_buffer_get_height(struct wl_shm_buffer *buffer)
WL_EXPORT struct wl_shm_pool *
wl_shm_buffer_ref_pool(struct wl_shm_buffer *buffer)
{
assert(buffer->pool->internal_refcount +
buffer->pool->external_refcount);
if (!(buffer->pool->internal_refcount +
buffer->pool->external_refcount))
wl_abort("Can't get reference to pool that has been freed\n");
buffer->pool->external_refcount++;
return buffer->pool;
@ -658,8 +664,9 @@ wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer)
pthread_setspecific(wl_shm_sigbus_data_key, sigbus_data);
}
assert(sigbus_data->current_pool == NULL ||
sigbus_data->current_pool == pool);
if (!(sigbus_data->current_pool == NULL ||
sigbus_data->current_pool == pool))
wl_abort("Incorrect pool passed for current thread\n");
sigbus_data->current_pool = pool;
sigbus_data->access_count++;
@ -686,7 +693,9 @@ wl_shm_buffer_end_access(struct wl_shm_buffer *buffer)
return;
sigbus_data = pthread_getspecific(wl_shm_sigbus_data_key);
assert(sigbus_data && sigbus_data->access_count >= 1);
if (!(sigbus_data && sigbus_data->access_count >= 1))
wl_abort("sigbus_data is NULL or wl_shm_buffer_begin_access "
"wasn't called before\n");
if (--sigbus_data->access_count == 0) {
if (sigbus_data->fallback_mapping_used) {