various: replace abort() with MP_ASSERT_UNREACHABLE() where appropriate

In debug mode the macro causes an assertion failure.
In release mode it works differently and tells the compiler that it can
assume the codepath will never execute. For this reason I was conversative
in replacing it, e.g. in mpv-internal code that exhausts all valid values
of an enum or when a condition is clear from directly preceding code.
This commit is contained in:
sfan5 2023-01-10 19:26:51 +01:00
parent 7b03cd367d
commit 1201d59f0b
21 changed files with 35 additions and 35 deletions

View File

@ -702,7 +702,7 @@ static void convert_plane(int type, void *data, int num_samples)
break;
}
default:
abort();
MP_ASSERT_UNREACHABLE();
}
}

View File

@ -563,7 +563,7 @@ static char *append_params(void *ta_parent, const char *device, const char *p)
/* a simple list of parameters: add it at the end of the list */
return talloc_asprintf(ta_parent, "%s,%s", device, p);
}
abort();
MP_ASSERT_UNREACHABLE();
}
static int try_open_device(struct ao *ao, const char *device, int mode)

View File

@ -729,8 +729,9 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
GENERIC_ERR_MSG("pa_context_set_sink_input_mute() failed");
return CONTROL_ERROR;
}
} else
abort();
} else {
MP_ASSERT_UNREACHABLE();
}
return CONTROL_OK;
}

View File

@ -810,7 +810,7 @@ void mp_msg_log_buffer_destroy(struct mp_log_buffer *buffer)
}
}
abort();
MP_ASSERT_UNREACHABLE();
found:

View File

@ -2868,7 +2868,7 @@ static const char *d_level(enum demux_check level)
case DEMUX_CHECK_REQUEST:return "request";
case DEMUX_CHECK_NORMAL: return "normal";
}
abort();
MP_ASSERT_UNREACHABLE();
}
static int decode_float(char *str, float *out)

View File

@ -429,7 +429,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target,
uint32_t, num_elems[i]);
break;
default:
abort();
MP_ASSERT_UNREACHABLE();
}
}
}
@ -582,7 +582,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target,
MP_TRACE(ctx, "ebml_id %x\n", (unsigned)*idptr);
break;
default:
abort();
MP_ASSERT_UNREACHABLE();
}
*countptr += 1;
error:

View File

@ -1608,7 +1608,7 @@ static void mp_input_src_kill(struct mp_input_src *src)
return;
}
}
abort();
MP_ASSERT_UNREACHABLE();
}
void mp_input_src_init_done(struct mp_input_src *src)

View File

@ -136,7 +136,7 @@ bool equal_mpv_value(const void *a, const void *b, mpv_format format)
return true;
}
}
abort(); // supposed to be able to handle all defined types
MP_ASSERT_UNREACHABLE(); // supposed to be able to handle all defined types
}
// Remarks see equal_mpv_value().

View File

@ -770,7 +770,7 @@ static const struct m_opt_choice_alternatives *get_choice(const m_option_t *opt,
return NULL;
}
}
abort();
MP_ASSERT_UNREACHABLE();
}
static int choice_get(const m_option_t *opt, void *ta_parent,

View File

@ -763,7 +763,7 @@ static void send_reply(struct mpv_handle *ctx, uint64_t userdata,
assert(ctx->reserved_events > 0);
ctx->reserved_events--;
if (append_event(ctx, *event, false) < 0)
abort(); // not reached
MP_ASSERT_UNREACHABLE();
pthread_mutex_unlock(&ctx->lock);
}

View File

@ -409,7 +409,7 @@ static int mp_property_av_speed_correction(void *ctx, struct m_property *prop,
switch (type[0]) {
case 'a': val = mpctx->speed_factor_a; break;
case 'v': val = mpctx->speed_factor_v; break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
if (action == M_PROPERTY_PRINT) {

View File

@ -291,7 +291,7 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek)
if (len >= 0)
seek_pts = seek.amount * len;
break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
double demux_pts = seek_pts;
@ -458,7 +458,7 @@ void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
*seek = (struct seek_params){ 0 };
return;
}
abort();
MP_ASSERT_UNREACHABLE();
}
void execute_queued_seek(struct MPContext *mpctx)

View File

@ -785,7 +785,7 @@ void mp_get_csp_matrix(struct mp_csp_params *params, struct mp_cmat *m)
break;
}
default:
abort();
MP_ASSERT_UNREACHABLE();
};
if (params->is_float)
@ -822,7 +822,7 @@ void mp_get_csp_matrix(struct mp_csp_params *params, struct mp_cmat *m)
case MP_CSP_LEVELS_PC: yuvlev = yuvfull; break;
case -1: yuvlev = anyfull; break;
default:
abort();
MP_ASSERT_UNREACHABLE();
}
int levels_out = params->levels_out;
@ -836,7 +836,7 @@ void mp_get_csp_matrix(struct mp_csp_params *params, struct mp_cmat *m)
case MP_CSP_LEVELS_TV: rgblev = rgblim; break;
case MP_CSP_LEVELS_PC: rgblev = rgbfull; break;
default:
abort();
MP_ASSERT_UNREACHABLE();
}
double ymul = (rgblev.max - rgblev.min) / (yuvlev.ymax - yuvlev.ymin);

View File

@ -510,7 +510,7 @@ static struct ra_tex *tex_create(struct ra *ra,
tex_p->res = (ID3D11Resource *)tex_p->tex3d;
break;
default:
abort();
MP_ASSERT_UNREACHABLE();
}
tex_p->array_slice = -1;

View File

@ -225,7 +225,7 @@ bool mpgl_osd_draw_prepare(struct mpgl_osd *ctx, int index,
break;
}
default:
abort();
MP_ASSERT_UNREACHABLE();
}
return true;

View File

@ -486,7 +486,7 @@ static const char *vao_glsl_type(const struct ra_renderpass_input *e)
case 2: return "vec2";
case 3: return "vec3";
case 4: return "vec4";
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
}
@ -553,7 +553,7 @@ static void update_uniform(struct gl_shader_cache *sc, struct sc_entry *e,
assert(e->pushc);
update_pushc(sc->ra, e->pushc, u);
break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
}

View File

@ -102,7 +102,7 @@ bool eval_szexpr(struct mp_log *log, void *priv,
switch (expr[i].val.op) {
case SZEXP_OP_NOT: stack[idx-1] = !stack[idx-1]; break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
continue;
@ -125,7 +125,7 @@ bool eval_szexpr(struct mp_log *log, void *priv,
case SZEXP_OP_GT: res = op1 > op2; break;
case SZEXP_OP_LT: res = op1 < op2; break;
case SZEXP_OP_EQ: res = op1 == op2; break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
if (!isfinite(res)) {

View File

@ -1915,8 +1915,7 @@ static void pass_sample(struct gl_video *p, struct image img,
} else if (scaler->kernel) {
pass_sample_separated(p, img, scaler, w, h);
} else {
// Should never happen
abort();
MP_ASSERT_UNREACHABLE(); // should never happen
}
// Apply any required multipliers. Separated scaling already does this in

View File

@ -295,7 +295,7 @@ static struct ra_tex *gl_tex_create_blank(struct ra *ra,
case 1: tex_gl->target = GL_TEXTURE_1D; break;
case 2: tex_gl->target = GL_TEXTURE_2D; break;
case 3: tex_gl->target = GL_TEXTURE_3D; break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
if (params->non_normalized) {
assert(params->dimensions == 2);
@ -631,7 +631,7 @@ static struct ra_buf *gl_buf_create(struct ra *ra,
case RA_BUF_TYPE_TEX_UPLOAD: hint = GL_STREAM_DRAW; break;
case RA_BUF_TYPE_SHADER_STORAGE: hint = GL_STREAM_COPY; break;
case RA_BUF_TYPE_UNIFORM: hint = GL_STATIC_DRAW; break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
gl->BufferData(buf_gl->target, params->size, params->initial_data, hint);
@ -738,7 +738,7 @@ static const char *shader_typestr(GLenum type)
case GL_VERTEX_SHADER: return "vertex";
case GL_FRAGMENT_SHADER: return "fragment";
case GL_COMPUTE_SHADER: return "compute";
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
}
@ -964,14 +964,14 @@ static void update_uniform(struct ra *ra, struct ra_renderpass *pass,
case 2: gl->Uniform2f(loc, f[0], f[1]); break;
case 3: gl->Uniform3f(loc, f[0], f[1], f[2]); break;
case 4: gl->Uniform4f(loc, f[0], f[1], f[2], f[3]); break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
} else if (input->dim_v == 2 && input->dim_m == 2) {
gl->UniformMatrix2fv(loc, 1, GL_FALSE, f);
} else if (input->dim_v == 3 && input->dim_m == 3) {
gl->UniformMatrix3fv(loc, 1, GL_FALSE, f);
} else {
abort();
MP_ASSERT_UNREACHABLE();
}
break;
}
@ -1002,7 +1002,7 @@ static void update_uniform(struct ra *ra, struct ra_renderpass *pass,
break;
}
default:
abort();
MP_ASSERT_UNREACHABLE();
}
}
@ -1086,7 +1086,7 @@ static void gl_renderpass_run(struct ra *ra,
gl->MemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
break;
}
default: abort();
default: MP_ASSERT_UNREACHABLE();
}
for (int n = 0; n < params->num_values; n++)

View File

@ -617,7 +617,7 @@ static void renderpass_run_pl(struct ra *ra,
case RA_VARTYPE_BUF_RW:
bind.object = (* (struct ra_buf **) val->data)->priv;
break;
default: abort();
default: MP_ASSERT_UNREACHABLE();
};
p->binds[p->inp_index[val->index]] = bind;

View File

@ -600,7 +600,7 @@ static void generate_osd_part(struct vo *vo, struct sub_bitmaps *imgs)
format = VDP_RGBA_FORMAT_B8G8R8A8;
break;
default:
abort();
MP_ASSERT_UNREACHABLE();
};
assert(imgs->packed);