various: use mp_assert macro
This commit is contained in:
1 parent
c0dbdcf7ad
commit
1c49cfdb97
149 files changed
+817
-813
No files matched your search
+1
-1
@@ -351,7 +351,7 @@ struct bstr bstr_sanitize_utf8_latin1(void *talloc_ctx, struct bstr s)
|
||||
static void resize_append(void *talloc_ctx, bstr *s, size_t append_min)
|
||||
{
|
||||
size_t size = talloc_get_size(s->start);
|
||||
assert(s->len <= size);
|
||||
mp_assert(s->len <= size);
|
||||
if (append_min > size - s->len) {
|
||||
if (append_min < size)
|
||||
append_min = size; // preallocate in power of 2s
|
||||
|
||||
@@ -739,7 +739,7 @@ int term_disp_width(bstr str, int max_width, const unsigned char **cut_pos)
|
||||
current_width = MPMIN(current_width, 2);
|
||||
next:
|
||||
if (width + current_width > max_width) {
|
||||
assert(prev_pos < str.start + str.len);
|
||||
mp_assert(prev_pos < str.start + str.len);
|
||||
*cut_pos = prev_pos;
|
||||
break;
|
||||
}
|
||||
|
||||
+16
-16
@@ -63,10 +63,10 @@ struct mp_dispatch_item {
|
||||
static void queue_dtor(void *p)
|
||||
{
|
||||
struct mp_dispatch_queue *queue = p;
|
||||
assert(!queue->head);
|
||||
assert(!queue->in_process);
|
||||
assert(!queue->lock_requests);
|
||||
assert(!queue->locked);
|
||||
mp_assert(!queue->head);
|
||||
mp_assert(!queue->in_process);
|
||||
mp_assert(!queue->lock_requests);
|
||||
mp_assert(!queue->locked);
|
||||
mp_cond_destroy(&queue->cond);
|
||||
mp_mutex_destroy(&queue->lock);
|
||||
}
|
||||
@@ -273,7 +273,7 @@ void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout)
|
||||
{
|
||||
mp_mutex_lock(&queue->lock);
|
||||
queue->wait = timeout > 0 ? mp_time_ns_add(mp_time_ns(), timeout) : 0;
|
||||
assert(!queue->in_process); // recursion not allowed
|
||||
mp_assert(!queue->in_process); // recursion not allowed
|
||||
queue->in_process = true;
|
||||
queue->in_process_thread_id = mp_thread_current_id();
|
||||
// Wake up thread which called mp_dispatch_lock().
|
||||
@@ -293,14 +293,14 @@ void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout)
|
||||
// while the dispatch item is processed.
|
||||
// At the same time, we must prevent other threads from returning
|
||||
// from mp_dispatch_lock(), which is done by locked=true.
|
||||
assert(!queue->locked);
|
||||
mp_assert(!queue->locked);
|
||||
queue->locked = true;
|
||||
mp_mutex_unlock(&queue->lock);
|
||||
|
||||
item->fn(item->fn_data);
|
||||
|
||||
mp_mutex_lock(&queue->lock);
|
||||
assert(queue->locked);
|
||||
mp_assert(queue->locked);
|
||||
queue->locked = false;
|
||||
// Wakeup mp_dispatch_run(), also mp_dispatch_lock().
|
||||
mp_cond_broadcast(&queue->cond);
|
||||
@@ -316,7 +316,7 @@ void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout)
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(!queue->locked);
|
||||
mp_assert(!queue->locked);
|
||||
queue->in_process = false;
|
||||
queue->interrupted = false;
|
||||
mp_mutex_unlock(&queue->lock);
|
||||
@@ -366,10 +366,10 @@ void mp_dispatch_lock(struct mp_dispatch_queue *queue)
|
||||
mp_mutex_lock(&queue->lock);
|
||||
// Must not be called recursively from dispatched callbacks.
|
||||
if (queue->in_process)
|
||||
assert(!mp_thread_id_equal(queue->in_process_thread_id, mp_thread_current_id()));
|
||||
mp_assert(!mp_thread_id_equal(queue->in_process_thread_id, mp_thread_current_id()));
|
||||
// Must not be called recursively at all.
|
||||
if (queue->locked_explicit)
|
||||
assert(!mp_thread_id_equal(queue->locked_explicit_thread_id, mp_thread_current_id()));
|
||||
mp_assert(!mp_thread_id_equal(queue->locked_explicit_thread_id, mp_thread_current_id()));
|
||||
queue->lock_requests += 1;
|
||||
// And now wait until the target thread gets "trapped" within the
|
||||
// mp_dispatch_queue_process() call, which will mean we get exclusive
|
||||
@@ -389,9 +389,9 @@ void mp_dispatch_lock(struct mp_dispatch_queue *queue)
|
||||
while (!queue->in_process || queue->locked)
|
||||
mp_cond_wait(&queue->cond, &queue->lock);
|
||||
// "Lock".
|
||||
assert(queue->lock_requests);
|
||||
assert(!queue->locked);
|
||||
assert(!queue->locked_explicit);
|
||||
mp_assert(queue->lock_requests);
|
||||
mp_assert(!queue->locked);
|
||||
mp_assert(!queue->locked_explicit);
|
||||
queue->locked = true;
|
||||
queue->locked_explicit = true;
|
||||
queue->locked_explicit_thread_id = mp_thread_current_id();
|
||||
@@ -402,10 +402,10 @@ void mp_dispatch_lock(struct mp_dispatch_queue *queue)
|
||||
void mp_dispatch_unlock(struct mp_dispatch_queue *queue)
|
||||
{
|
||||
mp_mutex_lock(&queue->lock);
|
||||
assert(queue->locked);
|
||||
mp_assert(queue->locked);
|
||||
// Must be called after a mp_dispatch_lock(), from the same thread.
|
||||
assert(queue->locked_explicit);
|
||||
assert(mp_thread_id_equal(queue->locked_explicit_thread_id, mp_thread_current_id()));
|
||||
mp_assert(queue->locked_explicit);
|
||||
mp_assert(mp_thread_id_equal(queue->locked_explicit_thread_id, mp_thread_current_id()));
|
||||
// "Unlock".
|
||||
queue->locked = false;
|
||||
queue->locked_explicit = false;
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ int mp_mkostemps(char *template, int suffixlen, int flags)
|
||||
|
||||
bool mp_save_to_file(const char *filepath, const void *data, size_t size)
|
||||
{
|
||||
assert(filepath && data && size);
|
||||
mp_assert(filepath && data && size);
|
||||
|
||||
bool result = false;
|
||||
char *tmp = talloc_asprintf(NULL, "%sXXXXXX", filepath);
|
||||
|
||||
+1
-1
@@ -257,7 +257,7 @@ static const char special_escape[] = {
|
||||
|
||||
static void write_json_str(bstr *b, unsigned char *str)
|
||||
{
|
||||
assert(str);
|
||||
mp_assert(str);
|
||||
|
||||
APPEND(b, "\"");
|
||||
while (1) {
|
||||
|
||||
+8
-8
@@ -12,14 +12,14 @@
|
||||
void node_init(struct mpv_node *dst, int format, struct mpv_node *parent)
|
||||
{
|
||||
// Other formats need to be initialized manually.
|
||||
assert(format == MPV_FORMAT_NODE_MAP || format == MPV_FORMAT_NODE_ARRAY ||
|
||||
mp_assert(format == MPV_FORMAT_NODE_MAP || format == MPV_FORMAT_NODE_ARRAY ||
|
||||
format == MPV_FORMAT_FLAG || format == MPV_FORMAT_INT64 ||
|
||||
format == MPV_FORMAT_DOUBLE || format == MPV_FORMAT_BYTE_ARRAY ||
|
||||
format == MPV_FORMAT_NONE);
|
||||
|
||||
void *ta_parent = NULL;
|
||||
if (parent) {
|
||||
assert(parent->format == MPV_FORMAT_NODE_MAP ||
|
||||
mp_assert(parent->format == MPV_FORMAT_NODE_MAP ||
|
||||
parent->format == MPV_FORMAT_NODE_ARRAY);
|
||||
ta_parent = parent->u.list;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ void node_init(struct mpv_node *dst, int format, struct mpv_node *parent)
|
||||
struct mpv_node *node_array_add(struct mpv_node *dst, int format)
|
||||
{
|
||||
struct mpv_node_list *list = dst->u.list;
|
||||
assert(dst->format == MPV_FORMAT_NODE_ARRAY && dst->u.list);
|
||||
mp_assert(dst->format == MPV_FORMAT_NODE_ARRAY && dst->u.list);
|
||||
MP_TARRAY_GROW(list, list->values, list->num);
|
||||
node_init(&list->values[list->num], format, dst);
|
||||
return &list->values[list->num++];
|
||||
@@ -47,16 +47,16 @@ struct mpv_node *node_array_add(struct mpv_node *dst, int format)
|
||||
// m_option_type_node memory management rules apply.
|
||||
struct mpv_node *node_map_add(struct mpv_node *dst, const char *key, int format)
|
||||
{
|
||||
assert(key);
|
||||
mp_assert(key);
|
||||
return node_map_badd(dst, bstr0(key), format);
|
||||
}
|
||||
|
||||
struct mpv_node *node_map_badd(struct mpv_node *dst, struct bstr key, int format)
|
||||
{
|
||||
assert(key.start);
|
||||
mp_assert(key.start);
|
||||
|
||||
struct mpv_node_list *list = dst->u.list;
|
||||
assert(dst->format == MPV_FORMAT_NODE_MAP && dst->u.list);
|
||||
mp_assert(dst->format == MPV_FORMAT_NODE_MAP && dst->u.list);
|
||||
MP_TARRAY_GROW(list, list->values, list->num);
|
||||
MP_TARRAY_GROW(list, list->keys, list->num);
|
||||
list->keys[list->num] = bstrdup0(list, key);
|
||||
@@ -69,7 +69,7 @@ struct mpv_node *node_map_badd(struct mpv_node *dst, struct bstr key, int format
|
||||
// m_option_type_node memory management rules apply.
|
||||
void node_map_add_string(struct mpv_node *dst, const char *key, const char *val)
|
||||
{
|
||||
assert(val);
|
||||
mp_assert(val);
|
||||
|
||||
struct mpv_node *entry = node_map_add(dst, key, MPV_FORMAT_NONE);
|
||||
entry->format = MPV_FORMAT_STRING;
|
||||
@@ -78,7 +78,7 @@ void node_map_add_string(struct mpv_node *dst, const char *key, const char *val)
|
||||
|
||||
void node_map_add_bstr(struct mpv_node *dst, const char *key, bstr val)
|
||||
{
|
||||
assert(val.start);
|
||||
mp_assert(val.start);
|
||||
|
||||
struct mpv_node *entry = node_map_add(dst, key, MPV_FORMAT_NONE);
|
||||
entry->format = MPV_FORMAT_STRING;
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ void mp_path_strip_trailing_separator(char *path)
|
||||
|
||||
char *mp_splitext(const char *path, bstr *root)
|
||||
{
|
||||
assert(path);
|
||||
mp_assert(path);
|
||||
int skip = (*path == '.'); // skip leading dot for "hidden" unix files
|
||||
const char *split = strrchr(path + skip, '.');
|
||||
if (!split || !split[1] || strchr(split, '/'))
|
||||
|
||||
+6
-6
@@ -133,8 +133,8 @@ static void thread_pool_dtor(void *ctx)
|
||||
for (int n = 0; n < num_threads; n++)
|
||||
mp_thread_join(threads[n]);
|
||||
|
||||
assert(pool->num_work == 0);
|
||||
assert(pool->num_threads == 0);
|
||||
mp_assert(pool->num_work == 0);
|
||||
mp_assert(pool->num_threads == 0);
|
||||
mp_cond_destroy(&pool->wakeup);
|
||||
mp_mutex_destroy(&pool->lock);
|
||||
}
|
||||
@@ -153,9 +153,9 @@ static bool add_thread(struct mp_thread_pool *pool)
|
||||
struct mp_thread_pool *mp_thread_pool_create(void *ta_parent, int init_threads,
|
||||
int min_threads, int max_threads)
|
||||
{
|
||||
assert(min_threads >= 0);
|
||||
assert(init_threads <= min_threads);
|
||||
assert(max_threads > 0 && max_threads >= min_threads);
|
||||
mp_assert(min_threads >= 0);
|
||||
mp_assert(init_threads <= min_threads);
|
||||
mp_assert(max_threads > 0 && max_threads >= min_threads);
|
||||
|
||||
struct mp_thread_pool *pool = talloc_zero(ta_parent, struct mp_thread_pool);
|
||||
talloc_set_destructor(pool, thread_pool_dtor);
|
||||
@@ -183,7 +183,7 @@ static bool thread_pool_add(struct mp_thread_pool *pool, void (*fn)(void *ctx),
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
assert(fn);
|
||||
mp_assert(fn);
|
||||
|
||||
mp_mutex_lock(&pool->lock);
|
||||
struct work work = {fn, fn_ctx};
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ uintptr_t mp_waiter_wait(struct mp_waiter *waiter)
|
||||
void mp_waiter_wakeup(struct mp_waiter *waiter, uintptr_t value)
|
||||
{
|
||||
mp_mutex_lock(&waiter->lock);
|
||||
assert(!waiter->done);
|
||||
mp_assert(!waiter->done);
|
||||
waiter->done = true;
|
||||
waiter->value = value;
|
||||
mp_cond_signal(&waiter->wakeup);
|
||||
@@ -102,7 +102,7 @@ static void cancel_destroy(void *p)
|
||||
{
|
||||
struct mp_cancel *c = p;
|
||||
|
||||
assert(!c->slaves.head); // API user error
|
||||
mp_assert(!c->slaves.head); // API user error
|
||||
|
||||
mp_cancel_set_parent(c, NULL);
|
||||
|
||||
|
||||
Reference in new issue
Block a user