From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Dale Mellor Newsgroups: gmane.lisp.guile.bugs Subject: bug#40719: [PATCH 0/4] GNU Mcron and the (ice-9 getopt-long) module Date: Sun, 19 Apr 2020 18:47:22 +0100 Organization: DM Bespoke Computer Solutions Ltd Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="96208"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.30.5-1.1 To: 40719@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sun Apr 19 20:36:15 2020 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQEnd-000Ova-GA for guile-bugs@m.gmane-mx.org; Sun, 19 Apr 2020 20:36:13 +0200 Original-Received: from localhost ([::1]:46422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQEnc-00049p-2n for guile-bugs@m.gmane-mx.org; Sun, 19 Apr 2020 14:36:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38658 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQEnT-00049f-Gp for bug-guile@gnu.org; Sun, 19 Apr 2020 14:36:03 -0400 Original-Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQEnS-0006Kx-UK for bug-guile@gnu.org; Sun, 19 Apr 2020 14:36:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34398) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQEnS-0006JZ-Hv for bug-guile@gnu.org; Sun, 19 Apr 2020 14:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQEnS-0005JT-EC for bug-guile@gnu.org; Sun, 19 Apr 2020 14:36:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dale Mellor Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 19 Apr 2020 18:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40719 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.158732135520406 (code B ref -1); Sun, 19 Apr 2020 18:36:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Apr 2020 18:35:55 +0000 Original-Received: from localhost ([127.0.0.1]:45944 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQEnL-0005J3-1b for submit@debbugs.gnu.org; Sun, 19 Apr 2020 14:35:55 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:40759) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQEVo-0004pq-BG for submit@debbugs.gnu.org; Sun, 19 Apr 2020 14:17:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34088 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQEVf-0005sr-6L for bug-guile@gnu.org; Sun, 19 Apr 2020 14:17:48 -0400 Original-Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQEVe-0006gn-S4 for bug-guile@gnu.org; Sun, 19 Apr 2020 14:17:39 -0400 Original-Received: from ec2-52-19-174-175.eu-west-1.compute.amazonaws.com ([52.19.174.175]:45794 helo=rdmp.org) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jQEVe-0006fl-G6 for bug-guile@gnu.org; Sun, 19 Apr 2020 14:17:38 -0400 Original-Received: from [127.0.0.1] (helo=localhost) by rdmp.org with esmtp (Exim 4.92) (envelope-from ) id 1jQE2N-0002XS-1T for bug-guile@gnu.org; Sun, 19 Apr 2020 17:47:23 +0000 Received-SPF: softfail client-ip=52.19.174.175; envelope-from=guile-qf1qmg@rdmp.org; helo=rdmp.org X-detected-operating-system: by eggs1p.gnu.org: Genre and OS details not recognized. X-Mailman-Approved-At: Sun, 19 Apr 2020 14:35:54 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:9719 Archived-At: /Mcron/ is a GNU package which runs unattended jobs in the operating system at dynamically computed times; it is 99% Guile but currently shrouded in a thin veneer of C code for historical reasons, which have by now vanished. The Guile /getopt-long/ module parses a command lineʼs arguments for options and their values according to a provided grammar. In the process of removing the thin veneer of C code from around the /GNU Mcron/ package, I am running up against niggles in the implementation of the /(ice-9 getopt-long)/ module. The intention with /mcron/ has always been that a command-line argument be provided which allows the user to request the display of the next eight jobs to run, or allows the user to specify the number of such jobs. Thus the intention was that command-lines like ‘mcron -s4 file’, ‘mcron -s 4 file’, and ‘mcron -s file’ would all work; alas, the last one, actually the most important case, doesnʼt with the current module, which issues a fatal exit on the grounds that ‘file’ fails to meet predicated requirements of the option for ‘-s’ that it should represent a decimal number. It is clear that /getopt-long/ can do better than this, especially if the consumer of the module provides predicates on values which options can take, e.g. value should be numerical. It can then objectively decide that an argument should be taken to be a value, an option itself, or a ‘loose’ argument. There are other problems which can be cleared up with the enhanced logic, as outlined in Point 2 below. The following patches clear up the situation. 1) The first patch introduces some 28 new tests of the existing /getopt-long/ module; these are non-controversial and the current code passes all the tests, but they exercise more of the corner cases and provide confidence that a new implementation does not break existing behaviour. 2) The second patch inverts one test which I disagree with (see Point 3, below), and introduces 18 more tests which represent currently indeterminate and unsupported behaviour, some nevertheless desired by /mcron/; all of these create either test FAIL cases with the current code-base, or total panic-escape from the calling application. Some specific test failures: 1. A command-line like ‘foo --test=’ produces a /test/ result with the empty string as value; I would expect /#t/ as the value (which indicates that the option is there but has no given value). 2. A command-line with a negative number always errors. According to the in-line documentation negative numbers canʼt ever appear loose on the command-line, but this seems like a case which might be realistic in real life and there is no reason to reject them. 3. A command like ‘foo -abc d’ in which /b/ takes a mandatory argument and /c/ is an allowed option, errors out, but in my opinion in this case /b/ should take “c” as its value and the command-line as a whole is *not* erroneous. If /b/ takes an optional value things are more tricky to deal with, but if there is a predicate on the values which /b/ can take, then the parser can make a clearer decision on taking /c/ as a value or another option. This might seem picky, but the problem is that command-lines are supplied by (possibly hostile) end-users, *not* by the /getopt-long/ module, and not by the application which consumes the module, either. Thus this might be regarded as a security issue. 4. The command ‘mcron -s file’, where /s/ takes an optional numeric value, errors out. 3) The third patch fixes up the /getopt-long/ module to pass all the new tests, as well as all of the existing ones (with the single exception outlined in Point 2.3 above). Considering that the entire Guile build also depends on /getopt-long/, we can have some confidence that the changes do not bring any incompatibility with existing code. 4) The final patch fixes up various commentary and doc-strings in the code to emphasise the importance of predicates on optional values, and generally make things more concrete.