You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Andrew Black <ab...@roguewave.com> on 2006/08/10 01:06:56 UTC
[patch] exec utility windows port
Greetings all.
Attached is a patch altering source for the the exec utility so that it
should build on windows systems. This patch does not alter the solution
generation infrastructure to actually build the utility, but instead
changes the source of the utility to make it compatible with windows.
Change log follows (and it's a bit long).
--Andrew Black
Log:
* util.h (rw_snprintf): Add macro hack to work around lack of snprintf
definition on windows.
* cmdopt.cpp: Alter #includes to include windows.h on windows in place
of unistd.h.
* cmdopt.cpp (eval_options): use Sleep() on windows in place of
sleep(), signal() on windows in place of sigaction().
* cmdopt.cpp (split_opt_string): use '^' as escape character on windows
in place of '\'.
* exec.h (exec_attrs): Alter structure for windows builds.
* exec.cpp: Alter #includes to include windows.h and process.h on
windows in place of unistd.h and sys/wait.h
* exec.cpp (get_signame): Use rw_snprintf in place of snprintf.
* exec.cpp (handle_alrm, wait_for_child, open_input, replace_file,
exec_file): Compile (existing) versions only on non-windows platforms.
* exec.cpp (open_input, merge_argv, exec_file): Define new functions
using windows native API, which will compile only on windows platforms.
* output.cpp (check_example): Alter logic used to determine the
location of the reference file to handle windows filenames.
* runall.cpp (S_IXUSR, S_IXGRP, S_IXOTH): Define if not defined for
windows.
* runall.cpp (check_target_ok): Disable (unused) logic for output only
targets. Alter compile check on windows systems to correctly locate
.obj file.
* runall.cpp (process_results): Handle windows result codes correctly.
* runall.cpp (rw_basename): Correct handling of escaping in path names,
unix path token separators.
Re: [patch] exec utility windows port
Posted by Martin Sebor <se...@roguewave.com>.
Andrew Black wrote:
> And, take 2 on the patch. I believe I've resolved the issue with soft
> killing the child processes, but I am not completely happy with it. Part
> of this reason for this unhappiness is that the MSDN documentation on
> process creation flags seems to indicate that the Control-C signal
> handling is disabled on the new process group. Unfortunately, I don't
> think there's any way around this. Still, I don't see error messages
> when a child process is killed, so I think it will work.
Looks good! Committed thus:
http://svn.apache.org/viewvc?rev=432452&view=rev
Let's see what Farid says -- I assume this will be integrated
into the next version of the Windows build infrastructure, right?
Thanks
Martin
PS Your changelog is a work of art! ;-)
Re: [patch] exec utility windows port
Posted by Andrew Black <ab...@roguewave.com>.
And, take 2 on the patch. I believe I've resolved the issue with soft
killing the child processes, but I am not completely happy with it.
Part of this reason for this unhappiness is that the MSDN documentation
on process creation flags seems to indicate that the Control-C signal
handling is disabled on the new process group. Unfortunately, I don't
think there's any way around this. Still, I don't see error messages
when a child process is killed, so I think it will work.
--Andrew Black
Andrew Black wrote:
> Greetings
>
> Now that the preparation patch has been applied, I have updated the
> actual port patch to reflect the current state of subversion. This
> patch is attached. Below is the revised changelog which should reflect
> the changes made in this iteration of the patch.
>
> A concern I have about this patch is in the behavior of the soft kill
> logic. When I test the child process kill logic (by issuing a command
> like 'exec.exe -t3 "exec.exe --sleep=10"'), I receive error output
> similar to the following:
> > Sending child process Control-C failed with error 87. Additionally,
> FormatMessage failed with error 8.
> > Sending child process Control-Break failed with error 87.
> Additionally, FormatMessage failed with error 8.
> From these error messages, I believe that the soft kills aren't being
> sent to the child process, and I am uncertain as to the reason. I would
> appreciate it if someone who has more experience with Windows could look
> into the problem. I don't know if this is a big enough issue to stop
> the patch from going in as it stands, as we are able to hard kill
> processes, but it is something to consider first.
>
> --Andrew Black
>
> Log:
> * exec.h [_WIN32 || _WIN64] (exec_attrs): Alter structure definition
> for windows.
> * exec.cpp [_WIN32 || _WIN64]: Use windows.h and process.h in place
> of unistd.h and sys/wait.h on windows.
> [!_WIN32 && !_WIN64] (handle_alrm, wait_for_child, open_input,
> replace_file, exec_file): Reduce scope of (existing) functions to
> non-windows platforms only.
> [_WIN32 || _WIN64] (open_input, merge_argv, warn_last_error,
> exec_file): Define implementation of named functions for windows
> platforms only.
> * cmdopt.cpp [_WIN32 || _WIN64]: Use windows.h in place of unistd.h
> on windows.
> (escape_code, default_path_sep, suffix_sep, exe_suffix_len): Alter
> values for windows.
> (rw_sleep, rw_signal): Define platform independent wrapper for
> sleep/Sleep and sigaction/signal.
> (eval_options): Use above.
> * runall.cpp [!_WIN32 && !_WIN64]: Don't include sys/wait.h on windows.
> (S_IXUSR, S_IXGRP, S_IXOTH): Define values if undefined (for
> windows).
> (check_target_ok) [_WIN32 || _WIN64]: Make object file comparison
> operating system specific.
> (process_results) [_WIN32 || _WIN64]: Make error state processing
> code operating system specific.
> (rw_basename) [_WIN32 || _WIN64]: Treat / as an additional path
> separator on windows.
>
> Martin Sebor wrote:
>> Andrew Black wrote:
>>> I believe I posted my patch to the list prior to the referenced
>>> change being submitted to subversion, but I am uncertain why those
>>> particular hunks failed to apply (running svn up appears to have
>>> merged them without conflicts).
>>>
>>> Attached is a revised version of the patch that tries to address the
>>> formatting issues in changed code (a formatting and comment cleanup
>>> sweep is needed after the windows port is finished). I have also
>>> tried to alter the log based on the changes to the patch and the
>>> referenced link.
>>
>> Great, thank you! Applied as follows:
>> http://svn.apache.org/viewvc?rev=431984&view=rev
>>
>> Martin
Re: [patch] exec utility windows port
Posted by Andrew Black <ab...@roguewave.com>.
Greetings
Now that the preparation patch has been applied, I have updated the
actual port patch to reflect the current state of subversion. This
patch is attached. Below is the revised changelog which should reflect
the changes made in this iteration of the patch.
A concern I have about this patch is in the behavior of the soft kill
logic. When I test the child process kill logic (by issuing a command
like 'exec.exe -t3 "exec.exe --sleep=10"'), I receive error output
similar to the following:
> Sending child process Control-C failed with error 87. Additionally,
FormatMessage failed with error 8.
> Sending child process Control-Break failed with error 87.
Additionally, FormatMessage failed with error 8.
From these error messages, I believe that the soft kills aren't being
sent to the child process, and I am uncertain as to the reason. I would
appreciate it if someone who has more experience with Windows could look
into the problem. I don't know if this is a big enough issue to stop
the patch from going in as it stands, as we are able to hard kill
processes, but it is something to consider first.
--Andrew Black
Log:
* exec.h [_WIN32 || _WIN64] (exec_attrs): Alter structure definition
for windows.
* exec.cpp [_WIN32 || _WIN64]: Use windows.h and process.h in place of
unistd.h and sys/wait.h on windows.
[!_WIN32 && !_WIN64] (handle_alrm, wait_for_child, open_input,
replace_file, exec_file): Reduce scope of (existing) functions to
non-windows platforms only.
[_WIN32 || _WIN64] (open_input, merge_argv, warn_last_error,
exec_file): Define implementation of named functions for windows
platforms only.
* cmdopt.cpp [_WIN32 || _WIN64]: Use windows.h in place of unistd.h on
windows.
(escape_code, default_path_sep, suffix_sep, exe_suffix_len): Alter
values for windows.
(rw_sleep, rw_signal): Define platform independent wrapper for
sleep/Sleep and sigaction/signal.
(eval_options): Use above.
* runall.cpp [!_WIN32 && !_WIN64]: Don't include sys/wait.h on windows.
(S_IXUSR, S_IXGRP, S_IXOTH): Define values if undefined (for windows).
(check_target_ok) [_WIN32 || _WIN64]: Make object file comparison
operating system specific.
(process_results) [_WIN32 || _WIN64]: Make error state processing
code operating system specific.
(rw_basename) [_WIN32 || _WIN64]: Treat / as an additional path
separator on windows.
Martin Sebor wrote:
> Andrew Black wrote:
>> I believe I posted my patch to the list prior to the referenced change
>> being submitted to subversion, but I am uncertain why those particular
>> hunks failed to apply (running svn up appears to have merged them
>> without conflicts).
>>
>> Attached is a revised version of the patch that tries to address the
>> formatting issues in changed code (a formatting and comment cleanup
>> sweep is needed after the windows port is finished). I have also
>> tried to alter the log based on the changes to the patch and the
>> referenced link.
>
> Great, thank you! Applied as follows:
> http://svn.apache.org/viewvc?rev=431984&view=rev
>
> Martin
Re: [patch] exec utility windows port
Posted by Martin Sebor <se...@roguewave.com>.
Andrew Black wrote:
> I believe I posted my patch to the list prior to the referenced change
> being submitted to subversion, but I am uncertain why those particular
> hunks failed to apply (running svn up appears to have merged them
> without conflicts).
>
> Attached is a revised version of the patch that tries to address the
> formatting issues in changed code (a formatting and comment cleanup
> sweep is needed after the windows port is finished). I have also tried
> to alter the log based on the changes to the patch and the referenced link.
Great, thank you! Applied as follows:
http://svn.apache.org/viewvc?rev=431984&view=rev
Martin
Re: [patch] exec utility windows port
Posted by Andrew Black <ab...@roguewave.com>.
I believe I posted my patch to the list prior to the referenced change
being submitted to subversion, but I am uncertain why those particular
hunks failed to apply (running svn up appears to have merged them
without conflicts).
Attached is a revised version of the patch that tries to address the
formatting issues in changed code (a formatting and comment cleanup
sweep is needed after the windows port is finished). I have also tried
to alter the log based on the changes to the patch and the referenced link.
--Andrew Black
Log:
* util.h (reference_name, output_name): Declare functions to
generate the names for reference and output files respectively.
* util.cpp (reference_name, output_name): Define above.
(guarded_malloc, guarded_realloc): Allocate memory after asserts.
* cmdopt.h (escape_code, default_path_sep, suffix_len, suffix_sep):
Declare (platform specific) file system related constants.
* cmdopt.cpp (escape_code, default_path_sep, suffix_len,
suffix_sep): Define above for UNIX systems.
(split_opt_string): Move use of opts after assert, use
escape_code as escape character in place of '\'.
* exec.cpp: (get_signame): Enlarge static buffer, use sprintf in
place of snprintf.
(open_input): Use reference_name to determine input file name,
remove root_len variable, move use of in_root after asserts.
(exec_file): Alter to use output_name to determine output file name.
* output.cpp (check_example): Use reference_name to determine
reference file location, add assert on on_name.
(parse_output): Use output_name to determine output file name.
* runall.cpp (merge_argv): Use target after asserts.
(check_target_ok): Disable (unused) logic for output only
targets. Alter compile check on windows systems to correctly locate
.obj file.
(rw_basename): Use default_path_sep as separator.
(run_target): Use target, argv, childargv after asserts.
Martin Sebor wrote:
> Andrew Black wrote:
>> Ok...
>>
>> Lets try splitting some of the issues brought up into a separate patch
>> (attached, log below). This patch focuses on the snprintf issue, the
>> use of asserts(), and centralizing filename generation logic.
>> Included is the file name token abstraction logic. The possibility
>> was raised that path separators may be more than one character long.
>> I would agree that it should be considered, but I also feel that to
>> code for this possibility would slow the program down slightly, for no
>> immediate benefit, as all current target platforms seem to use a
>> single character as the directory separator.
>
> Andrew, I'm afraid this patch doesn't apply cleanly -- see below.
> I suspect you didn't integrate the following change (output.cpp.rej
> is attached): http://svn.apache.org/viewvc?view=rev&revision=431269.
>
> $ patch -d /build/sebor/stdcxx/util/ < ~/tmp/winprep2.diff
> Looks like a unified context diff.
> The next patch looks like a unified context diff.
> The next patch looks like a unified context diff.
> The next patch looks like a unified context diff.
> Hunk #1 failed at line 232.
> Hunk #2 failed at line 242.
> 2 out of 4 hunks failed: saving rejects to output.cpp.rej
> The next patch looks like a unified context diff.
> The next patch looks like a unified context diff.
> The next patch looks like a unified context diff.
> done
>
> Could you please fix that and resubmit the patch?
>
> Also, I would really like you to correct the little formatting
> problems that I pointed out in my first feedback. I will not
> commit the patch until these have been fixed. I believe a
> consistent formatting style is important to the readability
> of code and hence to its maintainability and I would rather
> not spend time reviewing another round of changes just to
> clean up these trivial problems.
>
>>
>> --Andrew Black
>>
>> Log:
>> * util.h (reference_name, output_name): Declare functions to
>> generate the names for reference and output files respectively.
>> * util.cpp (reference_name, output_name): Define above.
>> * util.cpp (guarded_malloc, guarded_realloc): move use of size
>> asserts
>
> Please do not repeat the file name or the function name part on
> subsequent lines. It makes it look like you changed more files
> than you actually did.
>
> You might want to give the Change Logs section of the GNU coding
> standards a read:
> http://www.gnu.org/prep/standards/html_node/Change-Logs.html
>
> Thanks
> Martin
Re: [patch] exec utility windows port
Posted by Martin Sebor <se...@roguewave.com>.
Andrew Black wrote:
> Ok...
>
> Lets try splitting some of the issues brought up into a separate patch
> (attached, log below). This patch focuses on the snprintf issue, the
> use of asserts(), and centralizing filename generation logic. Included
> is the file name token abstraction logic. The possibility was raised
> that path separators may be more than one character long. I would agree
> that it should be considered, but I also feel that to code for this
> possibility would slow the program down slightly, for no immediate
> benefit, as all current target platforms seem to use a single character
> as the directory separator.
Andrew, I'm afraid this patch doesn't apply cleanly -- see below.
I suspect you didn't integrate the following change (output.cpp.rej
is attached): http://svn.apache.org/viewvc?view=rev&revision=431269.
$ patch -d /build/sebor/stdcxx/util/ < ~/tmp/winprep2.diff
Looks like a unified context diff.
The next patch looks like a unified context diff.
The next patch looks like a unified context diff.
The next patch looks like a unified context diff.
Hunk #1 failed at line 232.
Hunk #2 failed at line 242.
2 out of 4 hunks failed: saving rejects to output.cpp.rej
The next patch looks like a unified context diff.
The next patch looks like a unified context diff.
The next patch looks like a unified context diff.
done
Could you please fix that and resubmit the patch?
Also, I would really like you to correct the little formatting
problems that I pointed out in my first feedback. I will not
commit the patch until these have been fixed. I believe a
consistent formatting style is important to the readability
of code and hence to its maintainability and I would rather
not spend time reviewing another round of changes just to
clean up these trivial problems.
>
> --Andrew Black
>
> Log:
> * util.h (reference_name, output_name): Declare functions to
> generate the names for reference and output files respectively.
> * util.cpp (reference_name, output_name): Define above.
> * util.cpp (guarded_malloc, guarded_realloc): move use of size asserts
Please do not repeat the file name or the function name part on
subsequent lines. It makes it look like you changed more files
than you actually did.
You might want to give the Change Logs section of the GNU coding
standards a read:
http://www.gnu.org/prep/standards/html_node/Change-Logs.html
Thanks
Martin
Re: [patch] exec utility windows port
Posted by Andrew Black <ab...@roguewave.com>.
Ok...
Lets try splitting some of the issues brought up into a separate patch
(attached, log below). This patch focuses on the snprintf issue, the
use of asserts(), and centralizing filename generation logic. Included
is the file name token abstraction logic. The possibility was raised
that path separators may be more than one character long. I would agree
that it should be considered, but I also feel that to code for this
possibility would slow the program down slightly, for no immediate
benefit, as all current target platforms seem to use a single character
as the directory separator.
--Andrew Black
Log:
* util.h (reference_name, output_name): Declare functions to generate
the names for reference and output files respectively.
* util.cpp (reference_name, output_name): Define above.
* util.cpp (guarded_malloc, guarded_realloc): move use of size asserts
* cmdopt.h (escape_code, default_path_sep, suffix_len, suffix_sep):
Declare (platform specific) file system related constants.
* cmdopt.cpp (escape_code, default_path_sep, suffix_len, suffix_sep):
Define above for unix systems.
* cmdopt.cpp (split_opt_string): Move use of opts after assert
* cmdopt.cpp (split_opt_string): Use escape_code as escape character in
place of '\'.
* exec.cpp (get_signame): Enlarge static buffer, use sprintf in place
of snprintf.
* exec.cpp (open_input): Move use of in_root after asserts.
* exec.cpp (open_input, exec_file): Alter to use reference_name,
output_name respectively to determine file locations.
* output.cpp (check_example): Move use of in_root after asserts, use
reference_name to determine reference file location.
* output.cpp (parse_output): Use output_name to determine output file name
* runall.cpp (merge_argv, run_target): Use target, argv, childargv
after asserts
* runall.cpp (check_target_ok): Disable (unused) logic for output only
targets. Alter compile check on windows systems to correctly locate
.obj file.
* runall.cpp (rw_basename): Use default_path_sep as separator.
Martin Sebor wrote:
> Andrew Black wrote:
>> Greetings
>>
>> Attached is a reworked version of the patch with the requested changes
>> included. Unfortunately, the change log has changed enough that a new
>> one is required.
>
> That's okay, we don't mind :)
>
>> If it is decided that the windows file structure is to be altered
>> (with regards to the location of object files), this patch will need
>> to be altered slightly.
>>
>> One that was asked was 'Why can't we use backslash as the escape
>> character on Windows?' My answer is that the character is used as a
>> path separator,
>
> Ugh.
>
>> and it would be impossible to disambiguate the conflicting uses. I
>> use ^ as the escape character on windows, as that's the escape
>> character used elsewhere in windows.
>>
>> Another question that was asked was about the block I #if 0 ed out.
>> This change was intentional. The block in question is/was used to
>> check compile only targets, but we don't have any of those at this
>> time. IF this check were to be kept, it would need platform specific
>> logic to handle the differences in suffixes for object files between
>> windows and unix.
>
> Okay. Thanks for adding the comment.
>
>>
>> --Andrew Black
>>
>> Log:
>
> Wow! Capitalized first letter in every sentence and all. I'm so
> proud of you! ;-)
>
>> * util.h (rw_snprintf): Add macro hack to work around lack of
>> snprintf definition on windows.
>> * util.h (reference_name, output_name): Declare functions to
>> generate the names for reference and output files respectively.
>> * util.cpp (reference_name, output_name): Define above.
>> * cmdopt.h (escape_code, default_path_sep, suffix_len): Declare
>> platform specific constants related to the file system.
>> * cmdopt.cpp (escape_code, default_path_sep, suffix_len): Define
>> above, conditional on platform.
>> * cmdopt.cpp: Alter #includes to include windows.h on windows in
>> place of unistd.h.
>> * cmdopt.cpp (rw_sleep, rw_signal): Define platform abstraction
>> functions for sleep and signal/sigaction, conditional on platform.
>> * cmdopt.cpp (eval_options): use use rw_sleep() in place of
>> sleep(), rw_signal() in place of sigaction().
>> * cmdopt.cpp (split_opt_string): use escape_code as escape
>> character in place of '\'.
>> * exec.h (exec_attrs): Alter structure for windows builds.
>> * exec.cpp: Alter #includes to include windows.h and process.h on
>> windows in place of unistd.h and sys/wait.h
>> * exec.cpp (get_signame): Use rw_snprintf in place of snprintf.
>> * exec.cpp (handle_alrm, wait_for_child, open_input, replace_file,
>> exec_file): Compile (existing) versions only on non-windows platforms.
>> * exec.cpp (open_input, exec_file): Alter (existing) version to
>> use reference_name, output_name respectively.
>> * exec.cpp (open_input, merge_argv, exec_file): Define new
>> functions using windows native API, which will compile only on windows
>> platforms.
>> * output.cpp (check_example): Use reference_name to determine
>> reference file location.
>> * runall.cpp (S_IXUSR, S_IXGRP, S_IXOTH): Define if not defined
>> for windows.
>> * runall.cpp (check_target_ok): Disable (unused) logic for output
>> only targets. Alter compile check on windows systems to correctly
>> locate .obj file.
>> * runall.cpp (process_results): Handle windows result codes
>> correctly.
>> * runall.cpp (rw_basename): Use default_path_sep as separator for
>> non-windows builds.
>>
>>
>> ------------------------------------------------------------------------
>>
>> Index: util.h
>> ===================================================================
>> --- util.h (revision 430088)
>> +++ util.h (working copy)
>> @@ -28,6 +28,15 @@
>> #define RW_UTIL_H
>>
>> /**
>> + Ugly workaround for windows non-definition of snprintf
>
> snprintf() is a C95 thing and we would be better off not relying
> on it. AFAICS, rw_snprintf() is only being used in exec.cpp (so
> the macro shouldn't be defined in a header) and it should be both
> easy and safe to replace it with sprintf.
>
>> +*/
>> +#if !defined (_WIN32) && !defined (_WIN64)
>> +# define rw_snprintf snprintf
>> +#else
>> +# define rw_snprintf _snprintf
>> +#endif
>> +
>> +/**
>> Generates a non-terminal error message on stderr.
>>
>> @param format printf () format string to display on stderr
>> @@ -52,4 +61,24 @@
>> void* guarded_realloc (void* source, const size_t size,
>> const char* const file, const unsigned line);
>>
>> +/**
>> + Generates the name of a reference (input/output) file, based on
>> dir and mode.
>> +
>> + This function allocates memory which is to be freed by the caller.
>> +
>> + @param dir example subdirectory to reference
>> + @param mode type of file to generate name for (should be 'in' or
>> 'out')
>> + @return translation of 'in_root/dir/mode/target_name.mode'
>> +*/
>> +char* reference_name(const char* dir, const char* mode);
>
> Could you please try to more consistently follow the formatting
> conventions I outlined in http://tinyurl.com/mmqgv (specifically
> 2. bullet 5 :) Thanks!
>
>> +
>> +/**
>> + Generates the name of the output file for the executable target.
>> +
>> + This function allocates memory which is to be freed by the caller.
>> +
>> + @param path of target to generate output name for
>> + @return translation of 'target.out'
>> +*/
>> +char* output_name(const char* target);
>
> Same here: missing space before the opening parenthesis.
>
>> #endif // RW_UTIL_H
>> Index: exec.cpp
>> ===================================================================
>> --- exec.cpp (revision 430088)
>> +++ exec.cpp (working copy)
>> @@ -37,10 +37,15 @@
> [...]
>> #include <sys/stat.h> /* for S_* */
>
> FWIW, comments like the one above aren't terribly helpful. I would
> suggest to name the first in a series or related symbols and append
> an ellipsis to indicate that other related symbols from the header
> might be needed.
>
> [...]
>> @@ -350,10 +355,11 @@
>> }
>>
>> /* We've run out of known signal numbers, so use a default name */
>> - snprintf (def, sizeof def, "SIG#%d", signo);
>> + rw_snprintf (def, sizeof def, "SIG#%d", signo);
>
> Given a large enough buffer we don't need to worry about overflow
> here since we know the maximum length of the string.
>
> [..]
>> @@ -727,3 +721,216 @@
> [...]
>> +static HANDLE
>> +open_input (const char* exec_name, SECURITY_ATTRIBUTES* child_sa)
>
> Do we actually use these security attributes for anything? I didn't
> look very carefully but it seems to me that we're just passing the
> thing around w/o ever using it for anything. Or did I miss something?
>
> [...]
>> +struct exec_attrs +exec_file (char** argv)
>> +{
>> + char* merged = merge_argv(argv);
> [...]
>> + context.hStdOutput = CreateFile (tmp_name, GENERIC_WRITE,
>> + FILE_SHARE_WRITE, &child_sa, CREATE_ALWAYS,
>> + FILE_ATTRIBUTE_NORMAL, NULL);
>> + if (INVALID_HANDLE_VALUE == context.hStdOutput)
>> + {
>
> The brace goes on the line above (here and everywhere else).
>
>> + status.status = -1;
>> + status.error = GetLastError ();
>> + return status;
>
> This looks like a memory leak -- the merged pointer is not freed
> before returning.
>
>> + }
>> +
>> + context.hStdError = context.hStdOutput;
>> + free (tmp_name);
>> +
>> + /* Input redirection */
>> + context.hStdInput = open_input (target_name, &child_sa);
>> + if (INVALID_HANDLE_VALUE == context.hStdInput)
>> + { + status.status = -1;
>> + status.error = GetLastError ();
>> + return status;
>
> Same here.
>
>> + }
>> + } +
>> + /* Create the child process */
>> + CreateProcess (argv[0], merged, 0, 0, 1, +
>> DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, 0, 0, &context, &child);
>
> Should we be handling errors from CreateProcess?
>
>> +
>> + /* Clean up handles */
>> + CloseHandle(context.hStdInput);
>> + CloseHandle(context.hStdOutput);
>
> And issue warnings when these fail? (We should if we do it on the
> UNIX side.)
>
>> +
>> + /* Clean up argument string*/
>> + free (merged);
>> +
>> + /* Wait for the child process to terminate */
>> + if(WAIT_OBJECT_0 == WaitForSingleObject (child.hProcess, (timeout
>> > 0) ? timeout * 1000 : INFINITE)) {
>
> I would suggest to break out the conditional expression into a separate
> statement and reducing the length of the line below 79 characters for
> readability.
>
>> + GetExitCodeProcess (child.hProcess, &status.status);
>> + status.error = 0;
>> + return status;
>> + } +
>> + {/* Try to soft kill child process group if it didn't terminate,
>> but only on NT */
>> + OSVERSIONINFO OSVer;
>> + OSVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
>> + GetVersionEx (&OSVer);
>> + if(VER_PLATFORM_WIN32_NT == OSVer.dwPlatformId) {
>
> Space after if please (same below).
>
>> + GenerateConsoleCtrlEvent (CTRL_C_EVENT, child.dwProcessId);
>> + if(WAIT_OBJECT_0 == WaitForSingleObject (child.hProcess,
>> 1000)) {
>> + GetExitCodeProcess (child.hProcess, &status.status);
>> + status.error = 1;
>> + return status;
>> + }
>> + GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT,
>> child.dwProcessId);
>> + if(WAIT_OBJECT_0 == WaitForSingleObject (child.hProcess,
>> 1000)) {
>> + GetExitCodeProcess (child.hProcess, &status.status);
>> + status.error = 2;
>> + return status;
>> + }
>> + }
>> + }
>> + /* Then hard kill the child process */
>> + TerminateProcess (child.hProcess, 3);
>
> Check if TerminateProcess succeeded?
>
> [...]
>> Index: cmdopt.cpp
> [...]
>> @@ -84,6 +88,43 @@
>> " '--option=value' or '--option value'.\n"
>> };
>>
>> +#if !defined (_WIN32) && !defined (_WIN64)
>> +const char escape_code = '\\';
>> +const char default_path_sep = '//';
>
> Is it safe to assume that the path separator is always one char
> long? (It might be, but I'm not sure. It seems the code would
> be more robust if we avoided making the assumption.)
>
> [...]
>> Index: output.cpp
>> ===================================================================
>> --- output.cpp (revision 430088)
>> +++ output.cpp (working copy)
>> @@ -233,8 +233,7 @@
>> {
>> struct stat file_info;
>> const size_t root_len = strlen (in_root);
>> - char* const ref_name = (char*)RW_MALLOC (root_len
>> - + strlen (target_name) +
>> 19);
>> + char* ref_name;
>> FILE* reference;
>>
>> assert (0 != in_root);
>> @@ -243,10 +242,7 @@
>> assert (0 != output);
>>
>> /* Try in_root/manual/out/target_name.out */
>> - memcpy (ref_name, in_root, root_len+1);
>> - strcat (ref_name, "/manual/out/");
>> - strcat (ref_name, target_name);
>> - strcat (ref_name, ".out");
>> + ref_name = reference_name("manual", "out");
>>
>> if (0 > stat (ref_name, &file_info)) {
>
> FYI: apparently, there is no native stat on z/OS (see STDCXX-265:
> http://issues.apache.org/jira/browse/STDCXX-265). We need to start
> thinking about abstracting this to its own function that can be
> implemented in terms of, say, fopen() on z/OS.
>
> [...]
>> +char*
>> +reference_name(const char* dir, const char* mode)
>> +{
>> + const size_t root_len = strlen (in_root);
>> + const size_t cmp_len = strlen (target_name) - exe_suffix_len;
>> + const size_t dir_len = strlen (dir);
>> + const size_t mode_len = strlen (mode);
>
> We should assert the preconditions of the function before we make
> any assumptions about them.
>
>> + char* const ref_name = (char*)RW_MALLOC (root_len + cmp_len +
>> dir_len + + mode_len * 2 +
>> 5);
>
> I suggest to precompute the size of the array and saving it in
> a local variable rather than computing it in the argument.
>
> [...]
>> + *(tail++) = default_path_sep;
>
> There is no need to parenthesize *(tail++): the expression has the
> same meaning without the parentheses and it's so well-established
> that using the parentheses will only be confusing.
>
>> + memcpy (tail , dir, dir_len);
>> + tail += dir_len;
>> + *(tail++) = default_path_sep;
>> + memcpy (tail , mode, mode_len);
>> + tail += mode_len;
>> + *(tail++) = default_path_sep;
>> + memcpy (tail , target_name, cmp_len);
>> + tail += cmp_len;
>> + *(tail++) = '.';
>
> I think z/OS uses a period as the directory separator so if that's
> true we should be prepared to avoid using it here...
>
> [...]
>> +char*
>> +output_name(const char* target)
>> +{
>> + const char* suffix = ".out";
>
> ...as well as here. Again, check with Scott Zhong, our z/OS guru,
> about this. (This is just a to-do item and shouldn't hold up your
> patch).
>
> [...]
>> Index: exec.h
>> ===================================================================
>> --- exec.h (revision 430088)
>> +++ exec.h (working copy)
>> @@ -28,8 +28,14 @@
>> #define RW_EXEC_H
>>
>> struct exec_attrs {
>> +#if !defined (_WIN32) && !defined (_WIN64)
>> int status;
>> int killed;
>> +#else
>> + /* AKA DWORD */
>
> Won't defining status to a different type on different platforms
> cause problems (e.g., warnings)? I would suggest to keep them
> the same, especially given that they are the same size.
>
>> + unsigned long status;
>> + unsigned long error;
>> +#endif /* _WIN{32,64} */
>> };
>>
>> int get_signo (const char* signame);
> [...]
>> Index: runall.cpp
> [...]
>> @@ -281,6 +314,7 @@
>> if (0 == result->status) {
>> parse_output (target);
>> } +#if !defined (_WIN32) && !defined (_WIN64)
>
> I wonder if replacing the above with
>
> #if defined (WIFEXITED)
>
> would make the code more robust.
>
> [...]
>> @@ -329,9 +371,13 @@
>>
>> assert (0 != path);
>>
>> - for (mark = pos = path; '\0' != *pos; ++pos)
>> + for (mark = pos = path; '\0' != *pos; ++pos) {
>> +#if !defined (_WIN32) && !defined (_WIN64)
>> + mark = (default_path_sep == *pos) ? pos + 1 : mark;
>> +#else
>> mark = ('/' == *pos || '\\' == *pos) ? pos + 1 : mark;
>
> Should we be checking for equality to path_sep here instead of
> hardcoding backslash (I know they are the same but just for
> consistency).
>
> Martin
Re: [patch] exec utility windows port
Posted by Martin Sebor <se...@roguewave.com>.
Andrew Black wrote:
> Greetings
>
> Attached is a reworked version of the patch with the requested changes
> included. Unfortunately, the change log has changed enough that a new
> one is required.
That's okay, we don't mind :)
> If it is decided that the windows file structure is to
> be altered (with regards to the location of object files), this patch
> will need to be altered slightly.
>
> One that was asked was 'Why can't we use backslash as the escape
> character on Windows?' My answer is that the character is used as a
> path separator,
Ugh.
> and it would be impossible to disambiguate the
> conflicting uses. I use ^ as the escape character on windows, as that's
> the escape character used elsewhere in windows.
>
> Another question that was asked was about the block I #if 0 ed out. This
> change was intentional. The block in question is/was used to check
> compile only targets, but we don't have any of those at this time. IF
> this check were to be kept, it would need platform specific logic to
> handle the differences in suffixes for object files between windows and
> unix.
Okay. Thanks for adding the comment.
>
> --Andrew Black
>
> Log:
Wow! Capitalized first letter in every sentence and all. I'm so
proud of you! ;-)
> * util.h (rw_snprintf): Add macro hack to work around lack of
> snprintf definition on windows.
> * util.h (reference_name, output_name): Declare functions to
> generate the names for reference and output files respectively.
> * util.cpp (reference_name, output_name): Define above.
> * cmdopt.h (escape_code, default_path_sep, suffix_len): Declare
> platform specific constants related to the file system.
> * cmdopt.cpp (escape_code, default_path_sep, suffix_len): Define
> above, conditional on platform.
> * cmdopt.cpp: Alter #includes to include windows.h on windows in
> place of unistd.h.
> * cmdopt.cpp (rw_sleep, rw_signal): Define platform abstraction
> functions for sleep and signal/sigaction, conditional on platform.
> * cmdopt.cpp (eval_options): use use rw_sleep() in place of sleep(),
> rw_signal() in place of sigaction().
> * cmdopt.cpp (split_opt_string): use escape_code as escape character
> in place of '\'.
> * exec.h (exec_attrs): Alter structure for windows builds.
> * exec.cpp: Alter #includes to include windows.h and process.h on
> windows in place of unistd.h and sys/wait.h
> * exec.cpp (get_signame): Use rw_snprintf in place of snprintf.
> * exec.cpp (handle_alrm, wait_for_child, open_input, replace_file,
> exec_file): Compile (existing) versions only on non-windows platforms.
> * exec.cpp (open_input, exec_file): Alter (existing) version to use
> reference_name, output_name respectively.
> * exec.cpp (open_input, merge_argv, exec_file): Define new functions
> using windows native API, which will compile only on windows platforms.
> * output.cpp (check_example): Use reference_name to determine
> reference file location.
> * runall.cpp (S_IXUSR, S_IXGRP, S_IXOTH): Define if not defined for
> windows.
> * runall.cpp (check_target_ok): Disable (unused) logic for output
> only targets. Alter compile check on windows systems to correctly
> locate .obj file.
> * runall.cpp (process_results): Handle windows result codes correctly.
> * runall.cpp (rw_basename): Use default_path_sep as separator for
> non-windows builds.
>
>
> ------------------------------------------------------------------------
>
> Index: util.h
> ===================================================================
> --- util.h (revision 430088)
> +++ util.h (working copy)
> @@ -28,6 +28,15 @@
> #define RW_UTIL_H
>
> /**
> + Ugly workaround for windows non-definition of snprintf
snprintf() is a C95 thing and we would be better off not relying
on it. AFAICS, rw_snprintf() is only being used in exec.cpp (so
the macro shouldn't be defined in a header) and it should be both
easy and safe to replace it with sprintf.
> +*/
> +#if !defined (_WIN32) && !defined (_WIN64)
> +# define rw_snprintf snprintf
> +#else
> +# define rw_snprintf _snprintf
> +#endif
> +
> +/**
> Generates a non-terminal error message on stderr.
>
> @param format printf () format string to display on stderr
> @@ -52,4 +61,24 @@
> void* guarded_realloc (void* source, const size_t size,
> const char* const file, const unsigned line);
>
> +/**
> + Generates the name of a reference (input/output) file, based on dir and mode.
> +
> + This function allocates memory which is to be freed by the caller.
> +
> + @param dir example subdirectory to reference
> + @param mode type of file to generate name for (should be 'in' or 'out')
> + @return translation of 'in_root/dir/mode/target_name.mode'
> +*/
> +char* reference_name(const char* dir, const char* mode);
Could you please try to more consistently follow the formatting
conventions I outlined in http://tinyurl.com/mmqgv (specifically
2. bullet 5 :) Thanks!
> +
> +/**
> + Generates the name of the output file for the executable target.
> +
> + This function allocates memory which is to be freed by the caller.
> +
> + @param path of target to generate output name for
> + @return translation of 'target.out'
> +*/
> +char* output_name(const char* target);
Same here: missing space before the opening parenthesis.
> #endif // RW_UTIL_H
> Index: exec.cpp
> ===================================================================
> --- exec.cpp (revision 430088)
> +++ exec.cpp (working copy)
> @@ -37,10 +37,15 @@
[...]
> #include <sys/stat.h> /* for S_* */
FWIW, comments like the one above aren't terribly helpful. I would
suggest to name the first in a series or related symbols and append
an ellipsis to indicate that other related symbols from the header
might be needed.
[...]
> @@ -350,10 +355,11 @@
> }
>
> /* We've run out of known signal numbers, so use a default name */
> - snprintf (def, sizeof def, "SIG#%d", signo);
> + rw_snprintf (def, sizeof def, "SIG#%d", signo);
Given a large enough buffer we don't need to worry about overflow
here since we know the maximum length of the string.
[..]
> @@ -727,3 +721,216 @@
[...]
> +static HANDLE
> +open_input (const char* exec_name, SECURITY_ATTRIBUTES* child_sa)
Do we actually use these security attributes for anything? I didn't
look very carefully but it seems to me that we're just passing the
thing around w/o ever using it for anything. Or did I miss something?
[...]
> +struct exec_attrs
> +exec_file (char** argv)
> +{
> + char* merged = merge_argv(argv);
[...]
> + context.hStdOutput = CreateFile (tmp_name, GENERIC_WRITE,
> + FILE_SHARE_WRITE, &child_sa, CREATE_ALWAYS,
> + FILE_ATTRIBUTE_NORMAL, NULL);
> + if (INVALID_HANDLE_VALUE == context.hStdOutput)
> + {
The brace goes on the line above (here and everywhere else).
> + status.status = -1;
> + status.error = GetLastError ();
> + return status;
This looks like a memory leak -- the merged pointer is not freed
before returning.
> + }
> +
> + context.hStdError = context.hStdOutput;
> + free (tmp_name);
> +
> + /* Input redirection */
> + context.hStdInput = open_input (target_name, &child_sa);
> + if (INVALID_HANDLE_VALUE == context.hStdInput)
> + {
> + status.status = -1;
> + status.error = GetLastError ();
> + return status;
Same here.
> + }
> + }
> +
> + /* Create the child process */
> + CreateProcess (argv[0], merged, 0, 0, 1,
> + DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, 0, 0, &context, &child);
Should we be handling errors from CreateProcess?
> +
> + /* Clean up handles */
> + CloseHandle(context.hStdInput);
> + CloseHandle(context.hStdOutput);
And issue warnings when these fail? (We should if we do it on the
UNIX side.)
> +
> + /* Clean up argument string*/
> + free (merged);
> +
> + /* Wait for the child process to terminate */
> + if(WAIT_OBJECT_0 == WaitForSingleObject (child.hProcess, (timeout > 0) ? timeout * 1000 : INFINITE)) {
I would suggest to break out the conditional expression into a separate
statement and reducing the length of the line below 79 characters for
readability.
> + GetExitCodeProcess (child.hProcess, &status.status);
> + status.error = 0;
> + return status;
> + }
> +
> + {/* Try to soft kill child process group if it didn't terminate, but only on NT */
> + OSVERSIONINFO OSVer;
> + OSVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
> + GetVersionEx (&OSVer);
> + if(VER_PLATFORM_WIN32_NT == OSVer.dwPlatformId) {
Space after if please (same below).
> + GenerateConsoleCtrlEvent (CTRL_C_EVENT, child.dwProcessId);
> + if(WAIT_OBJECT_0 == WaitForSingleObject (child.hProcess, 1000)) {
> + GetExitCodeProcess (child.hProcess, &status.status);
> + status.error = 1;
> + return status;
> + }
> + GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, child.dwProcessId);
> + if(WAIT_OBJECT_0 == WaitForSingleObject (child.hProcess, 1000)) {
> + GetExitCodeProcess (child.hProcess, &status.status);
> + status.error = 2;
> + return status;
> + }
> + }
> + }
> + /* Then hard kill the child process */
> + TerminateProcess (child.hProcess, 3);
Check if TerminateProcess succeeded?
[...]
> Index: cmdopt.cpp
[...]
> @@ -84,6 +88,43 @@
> " '--option=value' or '--option value'.\n"
> };
>
> +#if !defined (_WIN32) && !defined (_WIN64)
> +const char escape_code = '\\';
> +const char default_path_sep = '//';
Is it safe to assume that the path separator is always one char
long? (It might be, but I'm not sure. It seems the code would
be more robust if we avoided making the assumption.)
[...]
> Index: output.cpp
> ===================================================================
> --- output.cpp (revision 430088)
> +++ output.cpp (working copy)
> @@ -233,8 +233,7 @@
> {
> struct stat file_info;
> const size_t root_len = strlen (in_root);
> - char* const ref_name = (char*)RW_MALLOC (root_len
> - + strlen (target_name) + 19);
> + char* ref_name;
> FILE* reference;
>
> assert (0 != in_root);
> @@ -243,10 +242,7 @@
> assert (0 != output);
>
> /* Try in_root/manual/out/target_name.out */
> - memcpy (ref_name, in_root, root_len+1);
> - strcat (ref_name, "/manual/out/");
> - strcat (ref_name, target_name);
> - strcat (ref_name, ".out");
> + ref_name = reference_name("manual", "out");
>
> if (0 > stat (ref_name, &file_info)) {
FYI: apparently, there is no native stat on z/OS (see STDCXX-265:
http://issues.apache.org/jira/browse/STDCXX-265). We need to start
thinking about abstracting this to its own function that can be
implemented in terms of, say, fopen() on z/OS.
[...]
> +char*
> +reference_name(const char* dir, const char* mode)
> +{
> + const size_t root_len = strlen (in_root);
> + const size_t cmp_len = strlen (target_name) - exe_suffix_len;
> + const size_t dir_len = strlen (dir);
> + const size_t mode_len = strlen (mode);
We should assert the preconditions of the function before we make
any assumptions about them.
> + char* const ref_name = (char*)RW_MALLOC (root_len + cmp_len + dir_len +
> + mode_len * 2 + 5);
I suggest to precompute the size of the array and saving it in
a local variable rather than computing it in the argument.
[...]
> + *(tail++) = default_path_sep;
There is no need to parenthesize *(tail++): the expression has the
same meaning without the parentheses and it's so well-established
that using the parentheses will only be confusing.
> + memcpy (tail , dir, dir_len);
> + tail += dir_len;
> + *(tail++) = default_path_sep;
> + memcpy (tail , mode, mode_len);
> + tail += mode_len;
> + *(tail++) = default_path_sep;
> + memcpy (tail , target_name, cmp_len);
> + tail += cmp_len;
> + *(tail++) = '.';
I think z/OS uses a period as the directory separator so if that's
true we should be prepared to avoid using it here...
[...]
> +char*
> +output_name(const char* target)
> +{
> + const char* suffix = ".out";
...as well as here. Again, check with Scott Zhong, our z/OS guru,
about this. (This is just a to-do item and shouldn't hold up your
patch).
[...]
> Index: exec.h
> ===================================================================
> --- exec.h (revision 430088)
> +++ exec.h (working copy)
> @@ -28,8 +28,14 @@
> #define RW_EXEC_H
>
> struct exec_attrs {
> +#if !defined (_WIN32) && !defined (_WIN64)
> int status;
> int killed;
> +#else
> + /* AKA DWORD */
Won't defining status to a different type on different platforms
cause problems (e.g., warnings)? I would suggest to keep them
the same, especially given that they are the same size.
> + unsigned long status;
> + unsigned long error;
> +#endif /* _WIN{32,64} */
> };
>
> int get_signo (const char* signame);
[...]
> Index: runall.cpp
[...]
> @@ -281,6 +314,7 @@
> if (0 == result->status) {
> parse_output (target);
> }
> +#if !defined (_WIN32) && !defined (_WIN64)
I wonder if replacing the above with
#if defined (WIFEXITED)
would make the code more robust.
[...]
> @@ -329,9 +371,13 @@
>
> assert (0 != path);
>
> - for (mark = pos = path; '\0' != *pos; ++pos)
> + for (mark = pos = path; '\0' != *pos; ++pos) {
> +#if !defined (_WIN32) && !defined (_WIN64)
> + mark = (default_path_sep == *pos) ? pos + 1 : mark;
> +#else
> mark = ('/' == *pos || '\\' == *pos) ? pos + 1 : mark;
Should we be checking for equality to path_sep here instead of
hardcoding backslash (I know they are the same but just for
consistency).
Martin
Re: [patch] exec utility windows port
Posted by Andrew Black <ab...@roguewave.com>.
Greetings
Attached is a reworked version of the patch with the requested changes
included. Unfortunately, the change log has changed enough that a new
one is required. If it is decided that the windows file structure is to
be altered (with regards to the location of object files), this patch
will need to be altered slightly.
One that was asked was 'Why can't we use backslash as the escape
character on Windows?' My answer is that the character is used as a
path separator, and it would be impossible to disambiguate the
conflicting uses. I use ^ as the escape character on windows, as that's
the escape character used elsewhere in windows.
Another question that was asked was about the block I #if 0 ed out.
This change was intentional. The block in question is/was used to check
compile only targets, but we don't have any of those at this time. IF
this check were to be kept, it would need platform specific logic to
handle the differences in suffixes for object files between windows and
unix.
--Andrew Black
Log:
* util.h (rw_snprintf): Add macro hack to work around lack of snprintf
definition on windows.
* util.h (reference_name, output_name): Declare functions to generate
the names for reference and output files respectively.
* util.cpp (reference_name, output_name): Define above.
* cmdopt.h (escape_code, default_path_sep, suffix_len): Declare
platform specific constants related to the file system.
* cmdopt.cpp (escape_code, default_path_sep, suffix_len): Define above,
conditional on platform.
* cmdopt.cpp: Alter #includes to include windows.h on windows in place
of unistd.h.
* cmdopt.cpp (rw_sleep, rw_signal): Define platform abstraction
functions for sleep and signal/sigaction, conditional on platform.
* cmdopt.cpp (eval_options): use use rw_sleep() in place of sleep(),
rw_signal() in place of sigaction().
* cmdopt.cpp (split_opt_string): use escape_code as escape character in
place of '\'.
* exec.h (exec_attrs): Alter structure for windows builds.
* exec.cpp: Alter #includes to include windows.h and process.h on
windows in place of unistd.h and sys/wait.h
* exec.cpp (get_signame): Use rw_snprintf in place of snprintf.
* exec.cpp (handle_alrm, wait_for_child, open_input, replace_file,
exec_file): Compile (existing) versions only on non-windows platforms.
* exec.cpp (open_input, exec_file): Alter (existing) version to use
reference_name, output_name respectively.
* exec.cpp (open_input, merge_argv, exec_file): Define new functions
using windows native API, which will compile only on windows platforms.
* output.cpp (check_example): Use reference_name to determine reference
file location.
* runall.cpp (S_IXUSR, S_IXGRP, S_IXOTH): Define if not defined for
windows.
* runall.cpp (check_target_ok): Disable (unused) logic for output only
targets. Alter compile check on windows systems to correctly locate
.obj file.
* runall.cpp (process_results): Handle windows result codes correctly.
* runall.cpp (rw_basename): Use default_path_sep as separator for
non-windows builds.
Re: [patch] exec utility windows port
Posted by Martin Sebor <se...@roguewave.com>.
Andrew Black wrote:
> Greetings all.
>
> Attached is a patch altering source for the the exec utility so that it
> should build on windows systems. This patch does not alter the solution
> generation infrastructure to actually build the utility, but instead
> changes the source of the utility to make it compatible with windows.
One comment and request: I like the approach taken in exec.cpp
where you abstract the Windows code into new platform-specific
implementations of the existing functions. I would like to take
the same approach in the rest of the sources as well so as to
reduce the amount of platform #ifdefs in executable code. We
need to make the utility easily portable to other non-POSIX,
non-Windows environments (such as z/OS) and the best way to
do that is to abstract out all platform-dependent code into
the smallest possible functions without "polluting" the main
program logic with platform-specific details.
[...]
> Index: cmdopt.cpp
> ===================================================================
> --- cmdopt.cpp (revision 430088)
> +++ cmdopt.cpp (working copy)
> @@ -304,7 +308,11 @@
> if (optarg && *optarg) {
> const long nsec = strtol (optarg, &end, 10);
> if ('\0' == *end && 0 <= nsec && !errno) {
> +#if !defined (_WIN32) && !defined (_WIN64)
> sleep (nsec);
> +#else
> + Sleep (nsec * 1000);
> +#endif
This should be abstracted into a function (say rw_sleep).
> break;
> }
> }
> @@ -330,12 +338,18 @@
> if (optarg && *optarg) {
> const long signo = get_signo (optarg);
> if (0 <= signo) {
> +#if !defined (_WIN32) && !defined (_WIN64)
> struct sigaction act;
> memset (&act, 0, sizeof act);
> act.sa_handler = SIG_IGN;
> if (0 > sigaction (signo, &act, 0))
> terminate (1, "sigaction(%s, ...) failed: %s\n",
> get_signame (signo), strerror (errno));
As should this. I suggest rw_signal() implemented in terms of
sigaction on POSIX platforms and signal otherwise.
> +#else
> + if (SIG_ERR == signal (signo, SIG_IGN))
> + terminate (1, "sigaction(%s, ...) failed: %s\n",
> + get_signame (signo), strerror (errno));
> +#endif /* _WIN{32,64} */
> break;
> }
> }
> @@ -429,7 +443,11 @@
> }
> in_token = 1;
> switch (*pos) {
> +#if !defined (_WIN32) && !defined (_WIN64)
> case '\\':
> +#else
> + case '^':
> +#endif /* _WIN{32,64} */
Hmm. Why can't we use backslash as the escape character on Windows?
> in_escape = 1;
> break;
> case '"':
> Index: output.cpp
> ===================================================================
> --- output.cpp (revision 430088)
> +++ output.cpp (working copy)
> @@ -233,8 +233,12 @@
> {
> struct stat file_info;
> const size_t root_len = strlen (in_root);
> - char* const ref_name = (char*)RW_MALLOC (root_len
> - + strlen (target_name) + 19);
> +#if !defined (_WIN32) && !defined (_WIN64)
> + const size_t cmp_len = strlen (target_name);
> +#else
> + const size_t cmp_len = strlen (target_name) - 4; /* Remove trailing .exe */
Same thing here: something like
const size_t cmp_len =
strlen (target_name) - strlen (exe_suffix);
where exe_suffix is a global constant defined to the platform
specific suffix for executable files.
> +#endif /* _WIN{32,64} */
> + char* const ref_name = (char*)RW_MALLOC (root_len + cmp_len + 19);
> FILE* reference;
>
> assert (0 != in_root);
> @@ -244,8 +248,13 @@
>
> /* Try in_root/manual/out/target_name.out */
> memcpy (ref_name, in_root, root_len+1);
> +#if !defined (_WIN32) && !defined (_WIN64)
> strcat (ref_name, "/manual/out/");
> strcat (ref_name, target_name);
> +#else
> + strcat (ref_name, "\\manual\\out\\");
> + strncat (ref_name, target_name, cmp_len);
This should be abstracted out as well. Windows uses the backslash
character, UNIX forward slash, and z/OS the dot as the directory
separator. We need to make it easy to support z/OS (I'm not sure
how extensions like .out are handled...)
If we do a lot of path manipulation in the program we can add
something like rw_path_append(char* path, const char* dir). If
this is the only place where we do path manipulation, I'd go
simply with strcat (strcat (ref_name, path_sep), cmp_len),
and define the global constant path_sep to "/" on UNIX and
to "\\" on Windoze (and "." on z/OS). You might want to check
with Scott Zhong on the z/OS file name specifics.
> +#endif /* _WIN{32,64} */
> strcat (ref_name, ".out");
>
> if (0 > stat (ref_name, &file_info)) {
[...]
> Index: runall.cpp
> ===================================================================
> --- runall.cpp (revision 430088)
> +++ runall.cpp (working copy)
[...]
> @@ -211,6 +223,7 @@
> const size_t path_len = strlen (target);
> char* tmp_name;
>
> +#if 0
Did you really mean to disable this block? (If yes, please add
a comment explaining why.)
[...]
> +#else
> + /* Or the target\target.obj file on windows systems*/
We should discuss with Anton if we need to have this layout on
Windows instead of the UNIX layout (where all the files are in
the same directory). It would be nice to be consistent.
Martin