mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
webpmux: simplify InitializeConfig()
put WebPMuxConfig on the stack in main() rather than allocating it in
InitializeConfig(); removes a level of indirection there.
(cherry picked from commit c0a462cac2
)
Change-Id: I81d386f7472ebbd322dd3fdbfda9d78dbeb62a66
This commit is contained in:
parent
3e70e64153
commit
e407b5d516
@ -488,7 +488,7 @@ static int ParseBgcolorArgs(const char* args, uint32_t* const bgcolor) {
|
|||||||
static void DeleteConfig(WebPMuxConfig* config) {
|
static void DeleteConfig(WebPMuxConfig* config) {
|
||||||
if (config != NULL) {
|
if (config != NULL) {
|
||||||
free(config->feature_.args_);
|
free(config->feature_.args_);
|
||||||
free(config);
|
memset(config, 0, sizeof(*config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -791,33 +791,27 @@ static int ValidateConfig(WebPMuxConfig* config) {
|
|||||||
|
|
||||||
// Create config object from command-line arguments.
|
// Create config object from command-line arguments.
|
||||||
static int InitializeConfig(int argc, const char* argv[],
|
static int InitializeConfig(int argc, const char* argv[],
|
||||||
WebPMuxConfig** config) {
|
WebPMuxConfig* config) {
|
||||||
int num_feature_args = 0;
|
int num_feature_args = 0;
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
|
|
||||||
assert(config != NULL);
|
assert(config != NULL);
|
||||||
*config = NULL;
|
memset(config, 0, sizeof(*config));
|
||||||
|
|
||||||
// Validate command-line arguments.
|
// Validate command-line arguments.
|
||||||
if (!ValidateCommandLine(argc, argv, &num_feature_args)) {
|
if (!ValidateCommandLine(argc, argv, &num_feature_args)) {
|
||||||
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1);
|
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate memory.
|
config->feature_.arg_count_ = num_feature_args;
|
||||||
*config = (WebPMuxConfig*)calloc(1, sizeof(**config));
|
config->feature_.args_ =
|
||||||
if (*config == NULL) {
|
(FeatureArg*)calloc(num_feature_args, sizeof(*config->feature_.args_));
|
||||||
ERROR_GOTO1("ERROR: Memory allocation error.\n", Err1);
|
if (config->feature_.args_ == NULL) {
|
||||||
}
|
|
||||||
(*config)->feature_.arg_count_ = num_feature_args;
|
|
||||||
(*config)->feature_.args_ =
|
|
||||||
(FeatureArg*)calloc(num_feature_args, sizeof(FeatureArg));
|
|
||||||
if ((*config)->feature_.args_ == NULL) {
|
|
||||||
ERROR_GOTO1("ERROR: Memory allocation error.\n", Err1);
|
ERROR_GOTO1("ERROR: Memory allocation error.\n", Err1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse command-line.
|
// Parse command-line.
|
||||||
if (!ParseCommandLine(argc, argv, *config) ||
|
if (!ParseCommandLine(argc, argv, config) || !ValidateConfig(config)) {
|
||||||
!ValidateConfig(*config)) {
|
|
||||||
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1);
|
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1075,14 +1069,14 @@ static int Process(const WebPMuxConfig* config) {
|
|||||||
// Main.
|
// Main.
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
WebPMuxConfig* config;
|
WebPMuxConfig config;
|
||||||
int ok = InitializeConfig(argc - 1, argv + 1, &config);
|
int ok = InitializeConfig(argc - 1, argv + 1, &config);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
ok = Process(config);
|
ok = Process(&config);
|
||||||
} else {
|
} else {
|
||||||
PrintHelp();
|
PrintHelp();
|
||||||
}
|
}
|
||||||
DeleteConfig(config);
|
DeleteConfig(&config);
|
||||||
return !ok;
|
return !ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user