[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
sh-quote, execute, spawn-pipe, etc.: Make better use of 'const'
From: |
Bruno Haible |
Subject: |
sh-quote, execute, spawn-pipe, etc.: Make better use of 'const' |
Date: |
Sat, 12 Dec 2020 04:25:53 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-193-generic; KDE/5.18.0; x86_64; ; ) |
The execute, spawn-pipe, etc. functions so far take a 'char **' for
an array of strings to pass as arguments to a subprocess. This is
suboptimal, because it requires casts from 'const char *' to 'char *'
in many places.
It is better to make clear through the types that the arguments strings
are not being written to. This removes the need to cast from 'const char *'
to 'char *'. It introduces the need to cast from 'const char **' to 'char **',
but in much fewer places. Since a cast from 'const char **' to 'char **'
does not violate strict aliasing rules (ISO C 11 ยง 6.5.(7)), this is OK.
IMO POSIX doesn't get this right in the functions execv(), posix_spawn(),
iconv() etc.
2020-12-11 Bruno Haible <bruno@clisp.org>
sh-quote, execute, spawn-pipe, etc.: Make better use of 'const'.
* lib/sh-quote.h (shell_quote_argv): Does not need write access to the
elements of argv.
* lib/sh-quote.c (shell_quote_argv): Likewise.
* lib/windows-spawn.h (prepare_spawn): Add 'const' the argument type and
the return type.
* lib/windows-spawn.c (prepare_spawn): Likewise.
* lib/os2-spawn.h (prepare_spawn): Likewise.
* lib/os2-spawn.c (prepare_spawn): Likewise.
* lib/execute.h (execute): Does not need write access to the elements of
prog_argv.
* lib/execute.c (execute): Likewise.
* lib/spawn-pipe.h (create_pipe_out, create_pipe_in, create_pipe_bidi):
Likewise.
* lib/spawn-pipe.c (create_pipe, create_pipe_bidi, create_pipe_in,
create_pipe_out): Likewise.
* lib/pipe-filter.h (pipe_filter_ii_execute, pipe_filter_gi_create):
Likewise.
* lib/pipe-filter-ii.c (pipe_filter_ii_execute): Likewise.
* lib/pipe-filter-gi.c (pipe_filter_gi_create): Likewise.
* lib/javaexec.h (execute_fn): Does not need write access to the
elements of prog_argv.
* lib/javaexec.c (execute_java_class): Update variable types and remove
casts to 'char *'.
* lib/csharpexec.h (execute_fn): Does not need write access to the
elements of prog_argv.
* lib/csharpexec.c (execute_csharp_using_mono,
execute_csharp_using_sscli): Update variable types and remove casts to
'char *'.
* lib/javacomp.c (compile_using_envjavac, compile_using_gcj,
compile_using_javac, compile_using_jikes, is_envjavac_gcj,
is_envjavac_gcj43, is_gcj_present, is_gcj_43, is_javac_present,
is_jikes_present): Update variable types and remove casts to 'char *'.
* lib/javaversion.c (execute_and_read_line): Does not need write access
to the elements of prog_argv.
* lib/csharpcomp.c (compile_csharp_using_mono,
compile_csharp_using_sscli): Update variable types and remove casts to
'char *'.
* tests/test-sh-quote.c (main): Update variable types and remove casts
to 'char *'.
* tests/test-execute-main.c (main): Update variable types and remove
casts to 'char *'.
* tests/test-spawn-pipe-main.c (test_pipe): Update variable types and
remove casts to 'char *'.
* NEWS: Mention the changes.
diff --git a/NEWS b/NEWS
index 747165a..f484881 100644
--- a/NEWS
+++ b/NEWS
@@ -60,6 +60,39 @@ User visible incompatible changes
Date Modules Changes
+2020-12-11 sh-quote The argv argument of the 'shell_quote_argv'
function
+ is now of type 'const char * const *'. You no
+ longer need to cast read-only strings to 'char *'
+ when constructing this argument.
+ execute The prog_argv argument of the 'execute' function
+ is now of type 'const char * const *'. You no
+ longer need to cast read-only strings to 'char *'
+ when constructing this argument.
+ spawn-pipe The prog_argv argument of the functions
+ 'create_pipe_out', 'create_pipe_in',
+ 'create_pipe_bidi' is now of type
+ 'const char * const *'. You no longer need to cast
+ read-only strings to 'char *' when constructing
this
+ argument.
+ pipe-filter-gi The prog_argv argument of the
+ 'pipe_filter_gi_create' function is now of type
+ 'const char * const *'. You no longer need to cast
+ read-only strings to 'char *' when constructing
this
+ argument.
+ pipe-filter-ii The prog_argv argument of the
+ 'pipe_filter_ii_execute' function is now of type
+ 'const char * const *'. You no longer need to cast
+ read-only strings to 'char *' when constructing
this
+ argument.
+ javaexec The prog_argv argument of the 'execute_fn' function
+ type is now of type 'const char * const *'. Update
+ the signature of all your implementations of this
+ type.
+ csharpexec The prog_argv argument of the 'execute_fn' function
+ type is now of type 'const char * const *'. Update
+ the signature of all your implementations of this
+ type.
+
2020-12-02 spawn-pipe The functions 'create_pipe_out', 'create_pipe_in',
'create_pipe_bidi' now take a 4th argument
'const char *directory'. To maintain the previous
0001-sh-quote-execute-spawn-pipe-etc.-Make-better-use-of-.patch
Description: Text Data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- sh-quote, execute, spawn-pipe, etc.: Make better use of 'const',
Bruno Haible <=