zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] using sysread/syswrite with coprocess
@ 2024-05-09 13:09 Anthony Heading
  2024-05-09 22:38 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Anthony Heading @ 2024-05-09 13:09 UTC (permalink / raw)
  To: zsh-workers

Does the patch below make sense?  I couldn't see a way to do this otherwise, as it doesn't look like the coprocess fds are exposed by any parameter to enable them to be passed explicitly.  I see that using 'p' as a magic integer is supported by 'print' but undocumented, so maybe this style isn't preferred.


diff --git Src/Modules/system.c Src/Modules/system.c
index 929a8b002..e272ff391 100644
--- Src/Modules/system.c
+++ Src/Modules/system.c
@@ -78,14 +78,24 @@ bin_sysread(char *nam, char **args, Options ops, UNUSED(int func))
 
     /* -i: input file descriptor if not stdin */
     if (OPT_ISSET(ops, 'i')) {
-	infd = getposint(OPT_ARG(ops, 'i'), nam);
+	char *infdarg = OPT_ARG(ops, 'i');
+	if (!strcmp(infdarg, "p")) {
+	    infd = coprocin;
+	} else {
+	    infd = getposint(infdarg, nam);
+	}
 	if (infd < 0)
 	    return 1;
     }
 
     /* -o: output file descriptor, else store in REPLY */
     if (OPT_ISSET(ops, 'o')) {
-	outfd = getposint(OPT_ARG(ops, 'o'), nam);
+	char *outfdarg = OPT_ARG(ops, 'o');
+	if (!strcmp(outfdarg, "p")) {
+	    outfd = coprocout;
+	} else {
+	    outfd = getposint(outfdarg, nam);
+	}
 	if (outfd < 0)
 	    return 1;
     }
@@ -244,7 +254,12 @@ bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
 
     /* -o: output file descriptor if not stdout */
     if (OPT_ISSET(ops, 'o')) {
-	outfd = getposint(OPT_ARG(ops, 'o'), nam);
+	char *outfdarg = OPT_ARG(ops, 'o');
+	if (!strcmp(outfdarg, "p")) {
+	    outfd = coprocout;
+	} else {
+	    outfd = getposint(outfdarg, nam);
+	}
 	if (outfd < 0)
 	    return 1;
     }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] using sysread/syswrite with coprocess
  2024-05-09 13:09 [PATCH] using sysread/syswrite with coprocess Anthony Heading
@ 2024-05-09 22:38 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2024-05-09 22:38 UTC (permalink / raw)
  To: Anthony Heading; +Cc: zsh-workers

On Thu, May 9, 2024 at 6:09 AM Anthony Heading <ajrh@ajrh.net> wrote:
>
> Does the patch below make sense?  I couldn't see a way to do this otherwise

There's nothing technically wrong with the patch, but you can do
  coproc ...
  exec {coprocin}>&p
  exec {coprocout}<&p
and then
  syswrite -o $coprocin ...
or
  sysread -i $coprocout ...

Whether it makes sense to support direct access to the coproc FD by
either "-o p" / "-i p" or simply -p as with print / read, or neither,
I will leave for larger discussion.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-09 22:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-09 13:09 [PATCH] using sysread/syswrite with coprocess Anthony Heading
2024-05-09 22:38 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).