From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?utf-8?Q?Ludovic_Court=C3=A8s?= Newsgroups: gmane.lisp.guile.devel Subject: Re: guile pipeline do-over Date: Sat, 07 Mar 2020 16:46:47 +0100 Message-ID: <87imjgi2vs.fsf@gnu.org> References: <8736al24jt.fsf@verum.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="130361"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: Guile Devel To: Rutger van Beusekom Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Mar 07 16:47:07 2020 Return-path: Envelope-to: guile-devel@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 1jAbfP-000XnO-7P for guile-devel@m.gmane-mx.org; Sat, 07 Mar 2020 16:47:07 +0100 Original-Received: from localhost ([::1]:49942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAbfN-00015d-RQ for guile-devel@m.gmane-mx.org; Sat, 07 Mar 2020 10:47:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37009) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAbf8-000154-De for guile-devel@gnu.org; Sat, 07 Mar 2020 10:46:51 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:40468) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jAbf8-0003VN-17; Sat, 07 Mar 2020 10:46:50 -0500 Original-Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=60380 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jAbf7-0001hg-Gg; Sat, 07 Mar 2020 10:46:49 -0500 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 18 =?utf-8?Q?Vent=C3=B4se?= an 228 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu In-Reply-To: <8736al24jt.fsf@verum.com> (Rutger van Beusekom's message of "Fri, 06 Mar 2020 10:52:54 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20434 Archived-At: Hi Rutger! Rutger van Beusekom skribis: > This patch replaces open-process with piped-process in posix.c and > reimplement open-process with piped-process in popen.scm. This allows > setting up a pipeline in guile scheme using the new pipeline procedure > in popen.scm and enables its use on operating systems which happen to > lack the capability to fork, but do offer the capability captured by > start_child (see posix.c). Nice! That=E2=80=99s definitely very useful to have. We=E2=80=99ll need t= o check what Andy thinks, but I think it can be added in the 3.0 series. > From 3c8f5d534419418234cfe7d3eda8227951bc208a Mon Sep 17 00:00:00 2001 > From: Rutger van Beusekom > Date: Mon, 2 Mar 2020 10:38:57 +0100 > Subject: [PATCH] Allow client code to create pipe pairs when opening a > process. > > * libguile/posix.c (scm_piped_process): Replace open_process by piped_pro= cess. Could you mention functions renamed/removed here? The ChangeLog format is about boringly listing all the language-entity-level changes. :-) > * module/ice-9/popen.scm (pipe->fdes): Convert pipe pair to fdes pair. > (open-process): Implement open-process with piped-process. > (pipeline): Implement a pipeline with piped-process. > static SCM > -scm_open_process (SCM mode, SCM prog, SCM args) > -#define FUNC_NAME "open-process" > +scm_piped_process (SCM prog, SCM args, SCM from, SCM to) > +#define FUNC_NAME "piped-process" > +/* SCM_DEFINE (scm_piped_process, "piped-process", 2, 2, 0, */ > +/* (SCM prog, SCM args, SCM from, SCM to), */ > +/* "Execute the command indicated by @var{prog} with arguments @var(args= ),\n" */ > +/* "optionally connected by an input and an output pipe.\n" */ > +/* "@var(from) and @var(to) are either #f or a valid file descriptor\n" = */ > +/* "of an input and an output pipe, respectively.\n" */ > +/* "\n" */ > +/* "This function returns the PID of the process executing @var(prog)." = */ > +/* "\n" */ > +/* "Example:\n" */ > +/* "(let ((p (pipe)))\n" */ > +/* " (piped-process \"echo\" '(\"foo\" \"bar\")\n" */ > +/* " (cons (port->fdes (car p))\n" */ > +/* " (port->fdes (cdr p))))\n" */ > +/* " (display (read-string (car p))))\n" */ > +/* "(let ((p (pipe)))\n" */ > +/* " (read-string (piped-process \"echo\" '(\"foo\" \"bar\")\n" */ > +/* " (port->fdes (car p)))))\n") */ > +/* #define FUNC_NAME scm_piped_process */ I guess you can remove the commented-out bits=E2=80=A6 > - int c2p[2]; /* Child to parent. */ > - int p2c[2]; /* Parent to child. */ > + int c2p[2] =3D {}; /* Child to parent. */ > + int p2c[2] =3D {}; /* Parent to child. */ =E2=80=A6 and this hunk, to minimize change. > +++ b/module/ice-9/popen.scm > @@ -22,9 +22,10 @@ > #:use-module (rnrs bytevectors) > #:use-module (ice-9 binary-ports) > #:use-module (ice-9 threads) > + #:use-module (srfi srfi-1) > #:use-module (srfi srfi-9) > #:export (port/pid-table open-pipe* open-pipe close-pipe open-input-pi= pe > - open-output-pipe open-input-output-pipe)) > + open-output-pipe open-input-output-pipe pipe->fdes piped-pro= cess pipeline)) I would not export =E2=80=98pipe->fdes=E2=80=99. I=E2=80=99m not sure abou= t exporting =E2=80=98piped-process=E2=80=99: it=E2=80=99s a bit low-level and we might = want to reserve ourselves the possibility to change it, like this patch does actually. WDYT? > +(define (open-process mode command . args) > + (let* ((from (and (or (equal? mode OPEN_READ) (equal? mode OPEN_BOTH))= (pipe->fdes))) > + (to (and (or (equal? mode OPEN_WRITE) (equal? mode OPEN_BOTH)) = (pipe->fdes))) > + (pid (piped-process command args from to))) > + (values (and from (fdes->inport (car from))) (and to (fdes->outport = (cdr to))) pid))) Please wrap lines to 80 chars. I suggest using =E2=80=98string=3D?=E2=80=99 above instead of =E2=80=98equa= l?=E2=80=99. Also, could you add a docstring? > +(define (pipeline procs) > + "Execute a pipeline of @code(procs) -- where a proc is a list of a > +command and its arguments as strings -- returning an input port to the > +end of the pipeline, an output port to the beginning of the pipeline and > +a list of PIDs of the @code(procs)" Perhaps s/procs/commands/ would be clearer? Also, @var{commands} instead of @code. Could you also add an entry in doc/ref/*.texi, in the =E2=80=9CPipes=E2=80= =9D node, perhaps with one of the examples you gave? > +++ b/test-suite/tests/popen.test > @@ -211,3 +211,37 @@ exec 2>~a; read REPLY" > (let ((st (close-pipe (open-output-pipe "exit 1")))) > (and (status:exit-val st) > (=3D 1 (status:exit-val st))))))) > + > + > +;; > +;; pipeline related tests > +;; > + > +(use-modules (ice-9 receive)) > +(use-modules (ice-9 rdelim)) Please move these to the top-level =E2=80=98define-module=E2=80=99 form. One last thing: we=E2=80=99d need you to assign copyright to the FSF for th= is. We can discuss it off-line if you want. Thank you for this great and long overdue addition! Ludo=E2=80=99.