From: Andrew Reynolds Date: Tue, 21 Apr 2020 05:33:50 +0000 (-0500) Subject: Fix for parse options related to binary name (#4368) X-Git-Tag: cvc5-1.0.0~3348 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=233dca9a28575631dec2cf004fe07fe6b994a9df;p=cvc5.git Fix for parse options related to binary name (#4368) Possible fix for the nightlies. In some configurations, a unit test fails when using the function for parsing options via manual argv construction https://github.com/CVC4/CVC4/blob/master/test/unit/expr/expr_public.h#L58 This reverts a behavior change from 3dfb48b. In particular, we always parse and ignore the binary name instead of skipping it outright. This more accurately reflects the original code. --- diff --git a/src/options/options_template.cpp b/src/options/options_template.cpp index faaa446ce..8a227a2e7 100644 --- a/src/options/options_template.cpp +++ b/src/options/options_template.cpp @@ -574,8 +574,9 @@ void Options::parseOptionsRecursive(Options* options, optreset = 1; // on BSD getopt() (e.g. Mac OS), might need this #endif /* HAVE_DECL_OPTRESET */ - // start with position after the binary name - int main_optind = 1; + // We must parse the binary name, which is manually ignored below. Setting + // this to 1 leads to incorrect behavior on some platforms. + int main_optind = 0; int old_optind; @@ -618,19 +619,6 @@ void Options::parseOptionsRecursive(Options* options, // The initial getopt_long call should always determine that argv[0] // is not an option and returns -1. We always manually advance beyond // this element. - // - // We have to reinitialize optind to 0 instead of 1 as we need to support - // changing the argv array passed to getopt. - // This is needed as are using GNU extensions. - // From: http://man7.org/linux/man-pages/man3/getopt.3.html - // A program that scans multiple argument vectors, or rescans the same - // vector more than once, and wants to make use of GNU extensions such - // as '+' and '-' at the start of optstring, or changes the value of - // POSIXLY_CORRECT between scans, must reinitialize getopt() by - // resetting optind to 0, rather than the traditional value of 1. - // (Resetting to 0 forces the invocation of an internal initialization - // routine that rechecks POSIXLY_CORRECT and checks for GNU extensions - // in optstring.) if ( old_optind == 0 && c == -1 ) { Assert(main_optind > 0); continue;