* [PATCH] libiberty: writeargv: Simplify function error mode.
@ 2023-06-05 14:37 Costas Argyris
2023-06-06 3:12 ` Jeff Law
0 siblings, 1 reply; 4+ messages in thread
From: Costas Argyris @ 2023-06-05 14:37 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1.1: Type: text/plain, Size: 167 bytes --]
writeargv can be simplified by getting rid of the error exit mode
that was only relevant many years ago when the function used
to open the file descriptor internally.
[-- Attachment #2: 0001-libiberty-writeargv-Simplify-function-error-mode.patch --]
[-- Type: text/x-patch, Size: 2321 bytes --]
From 1271552baee5561fa61652f4ca7673c9667e4f8f Mon Sep 17 00:00:00 2001
From: Costas Argyris <costas.argyris@gmail.com>
Date: Mon, 5 Jun 2023 15:02:06 +0100
Subject: [PATCH] libiberty: writeargv: Simplify function error mode.
The goto-based error mode was based on a previous version
of the function where it was responsible for opening the
file, so it had to close it upon any exit:
https://inbox.sourceware.org/gcc-patches/20070417200340.GM9017@sparrowhawk.codesourcery.com/
(thanks pinskia)
This is no longer the case though since now the function
takes the file descriptor as input, so the exit mode on
error can be just a simple return 1 statement.
Signed-off-by: Costas Argyris <costas.argyris@gmail.com>
---
libiberty/argv.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/libiberty/argv.c b/libiberty/argv.c
index a95a10e14ff..1a18b4d8866 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -289,8 +289,8 @@ char **buildargv (const char *input)
@deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file})
Write each member of ARGV, handling all necessary quoting, to the file
-named by FILE, separated by whitespace. Return 0 on success, non-zero
-if an error occurred while writing to FILE.
+associated with FILE, separated by whitespace. Return 0 on success,
+non-zero if an error occurred while writing to FILE.
@end deftypefn
@@ -314,36 +314,25 @@ writeargv (char * const *argv, FILE *f)
if (ISSPACE(c) || c == '\\' || c == '\'' || c == '"')
if (EOF == fputc ('\\', f))
- {
- status = 1;
- goto done;
- }
+ return 1;
if (EOF == fputc (c, f))
- {
- status = 1;
- goto done;
- }
+ return 1;
+
arg++;
}
/* Write out a pair of quotes for an empty argument. */
if (arg == *argv)
- if (EOF == fputs ("\"\"", f))
- {
- status = 1;
- goto done;
- }
+ if (EOF == fputs ("\"\"", f))
+ return 1;
if (EOF == fputc ('\n', f))
- {
- status = 1;
- goto done;
- }
+ return 1;
+
argv++;
}
- done:
return status;
}
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] libiberty: writeargv: Simplify function error mode.
2023-06-05 14:37 [PATCH] libiberty: writeargv: Simplify function error mode Costas Argyris
@ 2023-06-06 3:12 ` Jeff Law
2023-06-06 8:44 ` Costas Argyris
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Law @ 2023-06-06 3:12 UTC (permalink / raw)
To: Costas Argyris, gcc-patches
On 6/5/23 08:37, Costas Argyris via Gcc-patches wrote:
> writeargv can be simplified by getting rid of the error exit mode
> that was only relevant many years ago when the function used
> to open the file descriptor internally.
[ ... ]
Thanks. I've pushed this to the trunk.
You could (as a follow-up) simplify it even further. There's no need
for the status variable as far as I can tell. You could just have the
final return be "return 0;" instead of "return status;".
Jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] libiberty: writeargv: Simplify function error mode.
2023-06-06 3:12 ` Jeff Law
@ 2023-06-06 8:44 ` Costas Argyris
2023-06-07 2:52 ` Jeff Law
0 siblings, 1 reply; 4+ messages in thread
From: Costas Argyris @ 2023-06-06 8:44 UTC (permalink / raw)
To: Jeff Law; +Cc: gcc-patches
[-- Attachment #1.1: Type: text/plain, Size: 749 bytes --]
You are right, this is also a remnant of the old function design
that I completely missed. Here is the follow-up patch for that.
Thanks for pointing it out.
Costas
On Tue, 6 Jun 2023 at 04:12, Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
> On 6/5/23 08:37, Costas Argyris via Gcc-patches wrote:
> > writeargv can be simplified by getting rid of the error exit mode
> > that was only relevant many years ago when the function used
> > to open the file descriptor internally.
> [ ... ]
> Thanks. I've pushed this to the trunk.
>
> You could (as a follow-up) simplify it even further. There's no need
> for the status variable as far as I can tell. You could just have the
> final return be "return 0;" instead of "return status;".
>
> Jeff
>
[-- Attachment #2: 0001-libiberty-writeargv-Remove-unnecessary-status-variab.patch --]
[-- Type: text/x-patch, Size: 865 bytes --]
From 13fdfea60eeac64e028315392614b955e998487d Mon Sep 17 00:00:00 2001
From: Costas Argyris <costas.argyris@gmail.com>
Date: Tue, 6 Jun 2023 09:15:48 +0100
Subject: [PATCH] libiberty: writeargv: Remove unnecessary status variable.
Follow-up from 4d1e4ce986f pointed out by jlaw.
Signed-off-by: Costas Argyris <costas.argyris@gmail.com>
---
libiberty/argv.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/libiberty/argv.c b/libiberty/argv.c
index 1a18b4d8866..c2823d3e4ba 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -299,8 +299,6 @@ non-zero if an error occurred while writing to FILE.
int
writeargv (char * const *argv, FILE *f)
{
- int status = 0;
-
if (f == NULL)
return 1;
@@ -333,7 +331,7 @@ writeargv (char * const *argv, FILE *f)
argv++;
}
- return status;
+ return 0;
}
/*
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] libiberty: writeargv: Simplify function error mode.
2023-06-06 8:44 ` Costas Argyris
@ 2023-06-07 2:52 ` Jeff Law
0 siblings, 0 replies; 4+ messages in thread
From: Jeff Law @ 2023-06-07 2:52 UTC (permalink / raw)
To: Costas Argyris; +Cc: gcc-patches
On 6/6/23 02:44, Costas Argyris wrote:
> You are right, this is also a remnant of the old function design
> that I completely missed. Here is the follow-up patch for that.
>
> Thanks for pointing it out.
>
> Costas
>
> On Tue, 6 Jun 2023 at 04:12, Jeff Law <jeffreyalaw@gmail.com
> <mailto:jeffreyalaw@gmail.com>> wrote:
>
>
>
> On 6/5/23 08:37, Costas Argyris via Gcc-patches wrote:
> > writeargv can be simplified by getting rid of the error exit mode
> > that was only relevant many years ago when the function used
> > to open the file descriptor internally.
> [ ... ]
> Thanks. I've pushed this to the trunk.
>
> You could (as a follow-up) simplify it even further. There's no need
> for the status variable as far as I can tell. You could just have the
> final return be "return 0;" instead of "return status;".
>
> Jeff
>
>
> 0001-libiberty-writeargv-Remove-unnecessary-status-variab.patch
>
> From 13fdfea60eeac64e028315392614b955e998487d Mon Sep 17 00:00:00 2001
> From: Costas Argyris<costas.argyris@gmail.com>
> Date: Tue, 6 Jun 2023 09:15:48 +0100
> Subject: [PATCH] libiberty: writeargv: Remove unnecessary status variable.
>
> Follow-up from 4d1e4ce986f pointed out by jlaw.
>
> Signed-off-by: Costas Argyris<costas.argyris@gmail.com
> ---
> libiberty/argv.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
Thanks. I created a ChangeLog entry and committed this change to the trunk.
Jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-07 2:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05 14:37 [PATCH] libiberty: writeargv: Simplify function error mode Costas Argyris
2023-06-06 3:12 ` Jeff Law
2023-06-06 8:44 ` Costas Argyris
2023-06-07 2:52 ` Jeff Law
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 read-only IMAP folder(s) and NNTP newsgroup(s).