Commit f982d006 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '636ced8e'

* commit '636ced8e':
  cmdutils: wrap exit explicitly

Conflicts:
	avprobe.c
	cmdutils.c
	ffmpeg.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 4cd066b6 636ced8e
......@@ -111,6 +111,21 @@ static void log_callback_report(void *ptr, int level, const char *fmt, va_list v
fflush(report_file);
}
static void (*program_exit)(int ret);
void register_exit(void (*cb)(int ret))
{
program_exit = cb;
}
void exit_program(int ret)
{
if (program_exit)
program_exit(ret);
exit(ret);
}
double parse_number_or_die(const char *context, const char *numstr, int type,
double min, double max)
{
......@@ -128,7 +143,7 @@ double parse_number_or_die(const char *context, const char *numstr, int type,
else
return d;
av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
exit(1);
exit_program(1);
return 0;
}
......@@ -139,7 +154,7 @@ int64_t parse_time_or_die(const char *context, const char *timestr,
if (av_parse_time(&us, timestr, is_duration) < 0) {
av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
is_duration ? "duration" : "date", context, timestr);
exit(1);
exit_program(1);
}
return us;
}
......@@ -304,7 +319,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
}
}
if (po->flags & OPT_EXIT)
exit(0);
exit_program(0);
return 0;
}
......@@ -364,7 +379,7 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
opt++;
if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
exit(1);
exit_program(1);
optindex += ret;
} else {
if (parse_arg_function)
......@@ -637,7 +652,7 @@ static void init_parse_context(OptionParseContext *octx,
octx->nb_groups = nb_groups;
octx->groups = av_mallocz(sizeof(*octx->groups) * octx->nb_groups);
if (!octx->groups)
exit(1);
exit_program(1);
for (i = 0; i < octx->nb_groups; i++)
octx->groups[i].group_def = &groups[i];
......@@ -817,7 +832,7 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg)
"Possible levels are numbers or:\n", arg);
for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
exit(1);
exit_program(1);
}
av_log_set_level(level);
return 0;
......@@ -1924,13 +1939,13 @@ void *grow_array(void *array, int elem_size, int *size, int new_size)
{
if (new_size >= INT_MAX / elem_size) {
av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
exit(1);
exit_program(1);
}
if (*size < new_size) {
uint8_t *tmp = av_realloc(array, new_size*elem_size);
if (!tmp) {
av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
exit(1);
exit_program(1);
}
memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
*size = new_size;
......
......@@ -54,6 +54,16 @@ extern struct SwsContext *sws_opts;
extern AVDictionary *swr_opts;
extern AVDictionary *format_opts, *codec_opts, *resample_opts;
/**
* Register a program-specific cleanup routine.
*/
void register_exit(void (*cb)(int ret));
/**
* Wraps exit with a program-specific cleanup routine.
*/
void exit_program(int ret);
/**
* Initialize the cmdutils option system, in particular
* allocate the *_opts contexts.
......
This diff is collapsed.
......@@ -159,7 +159,7 @@ static uint64_t *nb_streams_packets;
static uint64_t *nb_streams_frames;
static int *selected_streams;
static void exit_program(void)
static void ffprobe_cleanup(int ret)
{
int i;
for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
......@@ -2123,7 +2123,7 @@ static void opt_input_file(void *optctx, const char *arg)
av_log(NULL, AV_LOG_ERROR,
"Argument '%s' provided as input filename, but '%s' was already specified.\n",
arg, input_filename);
exit(1);
exit_program(1);
}
if (!strcmp(arg, "-"))
arg = "pipe:";
......@@ -2273,7 +2273,7 @@ int main(int argc, char **argv)
int ret, i;
av_log_set_flags(AV_LOG_SKIP_REPEATED);
atexit(exit_program);
register_exit(ffprobe_cleanup);
options = real_options;
parse_loglevel(argc, argv, options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment