osdep: add MP_UNREACHABLE

This seems to work on gcc, clang and mingw as-is, but I made it
conditional on __GNUC__ just in case, even though I can't figure out
which compilers we care about that don't export this define.

Also replace all instances of assert(0) in the code by MP_UNREACHABLE(),
which is a strict improvement.
This commit is contained in:
Niklas Haas 2021-10-25 10:49:11 +02:00 committed by Niklas Haas
parent 2107671691
commit c704824b45
13 changed files with 19 additions and 13 deletions

View File

@ -1506,7 +1506,7 @@ static void find_backward_restart_pos(struct demux_stream *ds)
// Or if preroll is involved, the first preroll packet.
while (ds->reader_head != target) {
if (!advance_reader_head(ds))
assert(0); // target must be in list
MP_UNREACHABLE(); // target must be in list
}
double seek_pts;

View File

@ -2872,7 +2872,7 @@ static int read_next_block_into_queue(demuxer_t *demuxer)
if (mkv_d->cluster_end != EBML_UINT_INVALID)
mkv_d->cluster_end += stream_tell(s);
}
assert(0); // unreachable
MP_UNREACHABLE();
add_block:
index_block(demuxer, &block);

View File

@ -394,7 +394,7 @@ static bool init_pads(struct lavfi *c)
} else if (pad->type == MP_FRAME_VIDEO) {
dst_filter = avfilter_get_by_name("buffersink");
} else {
assert(0);
MP_UNREACHABLE();
}
if (!dst_filter)
@ -484,7 +484,7 @@ static bool init_pads(struct lavfi *c)
params->frame_rate = av_d2q(fmt->nominal_fps, 1000000);
filter_name = "buffer";
} else {
assert(0);
MP_UNREACHABLE();
}
params->time_base = pad->timebase;

View File

@ -250,7 +250,7 @@ static void fixed_aframe_size_process(struct mp_filter *f)
int in_samples = mp_aframe_get_size(p->in);
int copy = MPMIN(in_samples, p->samples - p->out_written);
if (!mp_aframe_copy_samples(p->out, p->out_written, p->in, 0, copy))
assert(0);
MP_UNREACHABLE();
mp_aframe_skip_samples(p->in, copy);
p->out_written += copy;
}

View File

@ -372,7 +372,7 @@ static struct mp_pin *find_connected_end(struct mp_pin *p)
return other;
p = other->user_conn;
}
assert(0);
MP_UNREACHABLE();
}
// With p being part of a connection, create the pin_connection and set all

View File

@ -105,7 +105,7 @@ static void *worker_thread(void *arg)
return NULL;
}
}
assert(0);
MP_UNREACHABLE();
}
pthread_mutex_unlock(&pool->lock);

View File

@ -879,7 +879,7 @@ void mp_read_option_raw(struct mpv_global *global, const char *name,
}
}
assert(0); // not found
MP_UNREACHABLE(); // not found
}
static const struct m_config_group *find_group(struct mpv_global *global,

View File

@ -176,7 +176,7 @@ static bstr read_file(struct mp_log *log, const char *filename)
}
size += s;
}
assert(0);
MP_UNREACHABLE();
}
// Load options and profiles from from a config file.

View File

@ -23,4 +23,10 @@
#define alignof(x) (offsetof(struct {char unalign_; x u;}, u))
#endif
#ifdef __GNUC__
#define MP_UNREACHABLE() (assert(!"unreachable"), __builtin_unreachable())
#else
#define MP_UNREACHABLE() (assert(!"unreachable"), abort())
#endif
#endif

View File

@ -155,7 +155,7 @@ static void hook_remove(struct MPContext *mpctx, struct hook_handler *h)
return;
}
}
assert(0);
MP_UNREACHABLE();
}
bool mp_hook_test_completion(struct MPContext *mpctx, char *type)

View File

@ -593,7 +593,7 @@ static bool endian_swap_bytes(void *d, size_t bytes, size_t word_size)
AV_WL32(ud + x * 2, AV_RB32(ud + x * 2));
break;
default:
assert(0);
MP_UNREACHABLE();
}
return true;

View File

@ -4237,7 +4237,7 @@ static void gl_video_dr_free_buffer(void *opaque, uint8_t *data)
}
}
// not found - must not happen
assert(0);
MP_UNREACHABLE();
}
struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h,

View File

@ -169,7 +169,7 @@ static void swap_endian(struct mp_image *dst, int dst_x, int dst_y,
((uint32_t *)d)[x] = av_bswap32(((uint32_t *)s)[x]);
break;
default:
assert(0);
MP_UNREACHABLE();
}
}
}