# HG changeset patch # User John W. Eaton # Date 1345738688 14400 # Node ID a83b7b2f95eef833de412f3155241d8a64e1e127 # Parent 61822c866ba1a01d5dd3ee62dd0c81389b729282 avoid C-style cast warnings from GCC for wait-related macros * lo-utils.h (octave_wait): New class. * lo-cutils.h, lo-cutils.c (octave_wifexited, octave_wexitstatus, octave_wifsignaled, octave_wtermsig, octave_wcoredump, octave_wifstopped, octave_wstopsig, octave_wifcontinued): New functions. * toplev.cc, pager.cc, syscalls.cc: Use octave_wait functions instead of WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED macros. diff -r 61822c866ba1 -r a83b7b2f95ee libinterp/corefcn/syscalls.cc --- a/libinterp/corefcn/syscalls.cc Thu Aug 23 12:13:59 2012 -0400 +++ b/libinterp/corefcn/syscalls.cc Thu Aug 23 12:18:08 2012 -0400 @@ -1376,21 +1376,17 @@ @seealso{waitpid, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = false; -#if defined (WIFEXITED) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WIFEXITED (status); + retval = octave_wait::ifexited (status); else error ("WIFEXITED: STATUS must be an integer"); } -#else - warning ("WIFEXITED always returns false in this version of Octave"); -#endif return retval; } @@ -1404,21 +1400,17 @@ @seealso{waitpid, WIFEXITED, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = 0; -#if defined (WEXITSTATUS) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WEXITSTATUS (status); + retval = octave_wait::exitstatus (status); else error ("WEXITSTATUS: STATUS must be an integer"); } -#else - warning ("WEXITSTATUS always returns false in this version of Octave"); -#endif return retval; } @@ -1431,21 +1423,17 @@ @seealso{waitpid, WIFEXITED, WEXITSTATUS, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = false; -#if defined (WIFSIGNALED) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WIFSIGNALED (status); + retval = octave_wait::ifsignaled (status); else error ("WIFSIGNALED: STATUS must be an integer"); } -#else - warning ("WIFSIGNALED always returns false in this version of Octave"); -#endif return retval; } @@ -1459,21 +1447,17 @@ @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WCOREDUMP, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = 0; -#if defined (WTERMSIG) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WTERMSIG (status); + retval = octave_wait::termsig (status); else error ("WTERMSIG: STATUS must be an integer"); } -#else - warning ("WTERMSIG always returns false in this version of Octave"); -#endif return retval; } @@ -1489,21 +1473,17 @@ @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, WIFCONTINUED}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = false; -#if defined (WCOREDUMP) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WCOREDUMP (status); + retval = octave_wait::coredump (status); else error ("WCOREDUMP: STATUS must be an integer"); } -#else - warning ("WCOREDUMP always returns false in this version of Octave"); -#endif return retval; } @@ -1518,21 +1498,17 @@ @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WSTOPSIG, WIFCONTINUED}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = false; -#if defined (WIFSTOPPED) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WIFSTOPPED (status); + retval = octave_wait::ifstopped (status); else error ("WIFSTOPPED: STATUS must be an integer"); } -#else - warning ("WIFSTOPPED always returns false in this version of Octave"); -#endif return retval; } @@ -1546,21 +1522,17 @@ @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WIFCONTINUED}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = 0; -#if defined (WSTOPSIG) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WSTOPSIG (status); + retval = octave_wait::stopsig (status); else error ("WSTOPSIG: STATUS must be an integer"); } -#else - warning ("WSTOPSIG always returns false in this version of Octave"); -#endif return retval; } @@ -1573,21 +1545,17 @@ @seealso{waitpid, WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WCOREDUMP, WIFSTOPPED, WSTOPSIG}\n\ @end deftypefn") { - octave_value retval = 0.0; + octave_value retval = false; -#if defined (WIFCONTINUED) if (args.length () == 1) { int status = args(0).int_value (); if (! error_state) - retval = WIFCONTINUED (status); + retval = octave_wait::ifcontinued (status); else error ("WIFCONTINUED: STATUS must be an integer"); } -#else - warning ("WIFCONTINUED always returns false in this version of Octave"); -#endif return retval; } diff -r 61822c866ba1 -r a83b7b2f95ee libinterp/interpfcn/pager.cc --- a/libinterp/interpfcn/pager.cc Thu Aug 23 12:13:59 2012 -0400 +++ b/libinterp/interpfcn/pager.cc Thu Aug 23 12:18:08 2012 -0400 @@ -108,7 +108,7 @@ if (pid > 0) { - if (WIFEXITED (status) || WIFSIGNALLED (status)) + if (octave_wait::ifexited (status) || octave_wait::ifsignaled (status)) { // Avoid warning() since that will put us back in the pager, // which would be bad news. diff -r 61822c866ba1 -r a83b7b2f95ee libinterp/interpfcn/toplev.cc --- a/libinterp/interpfcn/toplev.cc Thu Aug 23 12:13:59 2012 -0400 +++ b/libinterp/interpfcn/toplev.cc Thu Aug 23 12:18:08 2012 -0400 @@ -808,8 +808,8 @@ int cmd_status = cmd->close (); - if (WIFEXITED (cmd_status)) - cmd_status = WEXITSTATUS (cmd_status); + if (octave_wait::ifexited (cmd_status)) + cmd_status = octave_wait::exitstatus (cmd_status); else cmd_status = 127; @@ -988,8 +988,8 @@ // status of the command. Otherwise, return 127 as a // failure code. - if (WIFEXITED (status)) - status = WEXITSTATUS (status); + if (octave_wait::ifexited (status)) + status = octave_wait::exitstatus (status); retval(0) = status; } diff -r 61822c866ba1 -r a83b7b2f95ee liboctave/lo-cutils.c --- a/liboctave/lo-cutils.c Thu Aug 23 12:13:59 2012 -0400 +++ b/liboctave/lo-cutils.c Thu Aug 23 12:18:08 2012 -0400 @@ -76,3 +76,115 @@ { return WAITPID (pid, status, options); } + +OCTAVE_API int octave_wifexited (int status) +{ + int retval = 0; + +#if defined (WIFEXITED) + retval = WIFEXITED (status); +#else + (*liboctave_warning_handler) + ("WIFEXITED always returns false in this version of Octave"); +#endif + + return retval; +} + +OCTAVE_API int octave_wexitstatus (int status) +{ + int retval = 0; + +#if defined (WEXITSTATUS) + retval = WEXITSTATUS (status); +#else + (*liboctave_warning_handler) + ("WEXITSTATUS always returns 0 in this version of Octave"); +#endif + + return retval; +} + +OCTAVE_API int octave_wifsignaled (int status) +{ + int retval = 0; + +#if defined (WIFSIGNALED) + retval = WIFSIGNALED (status); +#else + (*liboctave_warning_handler) + ("WIFSIGNALED always returns false in this version of Octave"); +#endif + + return retval; +} + +OCTAVE_API int octave_wtermsig (int status) +{ + int retval = 0; + +#if defined (WTERMSIG) + retval = WTERMSIG (status); +#else + (*liboctave_warning_handler) + ("WTERMSIG always returns 0 in this version of Octave"); +#endif + + return retval; +} + +OCTAVE_API int octave_wcoredump (int status) +{ + int retval = 0; + +#if defined (WCOREDUMP) + retval = WCOREDUMP (status); +#else + (*liboctave_warning_handler) + ("WCOREDUMP always returns false in this version of Octave"); +#endif + + return retval; +} + +OCTAVE_API int octave_wifstopped (int status) +{ + int retval = 0; + +#if defined (WIFSTOPPED) + retval = WIFSTOPPED (status); +#else + (*liboctave_warning_handler) + ("WIFSTOPPED always returns false in this version of Octave"); +#endif + + return retval; +} + +OCTAVE_API int octave_wstopsig (int status) +{ + int retval = 0; + +#if defined (WSTOPSIG) + retval = WSTOPSIG (status); +#else + (*liboctave_warning_handler) + ("WSTOPSIG always returns 0 in this version of Octave"); +#endif + + return retval; +} + +OCTAVE_API int octave_wifcontinued (int status) +{ + int retval = 0; + +#if defined (WIFCONTINUED) + retval = WIFCONTINUED (status); +#else + (*liboctave_warning_handler) + ("WIFCONTINUED always returns false in this version of Octave"); +#endif + + return retval; +} diff -r 61822c866ba1 -r a83b7b2f95ee liboctave/lo-cutils.h --- a/liboctave/lo-cutils.h Thu Aug 23 12:13:59 2012 -0400 +++ b/liboctave/lo-cutils.h Thu Aug 23 12:18:08 2012 -0400 @@ -50,6 +50,15 @@ OCTAVE_API pid_t octave_waitpid (pid_t pid, int *status, int options); +OCTAVE_API int octave_wifexited (int status); +OCTAVE_API int octave_wexitstatus (int status); +OCTAVE_API int octave_wifsignaled (int status); +OCTAVE_API int octave_wtermsig (int status); +OCTAVE_API int octave_wcoredump (int status); +OCTAVE_API int octave_wifstopped (int status); +OCTAVE_API int octave_wstopsig (int status); +OCTAVE_API int octave_wifcontinued (int status); + #ifdef __cplusplus } #endif diff -r 61822c866ba1 -r a83b7b2f95ee liboctave/lo-utils.h --- a/liboctave/lo-utils.h Thu Aug 23 12:13:59 2012 -0400 +++ b/liboctave/lo-utils.h Thu Aug 23 12:18:08 2012 -0400 @@ -135,4 +135,52 @@ extern OCTAVE_API void octave_write_float_complex (std::ostream& os, const FloatComplex& cval); +// Maybe this is overkill, but it allos + +class +octave_wait +{ +public: + + static bool ifexited (int status) + { + return octave_wifexited (status); + } + + static int exitstatus (int status) + { + return octave_wexitstatus (status); + } + + static bool ifsignaled (int status) + { + return octave_wifsignaled (status); + } + + static int termsig (int status) + { + return octave_wtermsig (status); + } + + static bool coredump (int status) + { + return octave_wcoredump (status); + } + + static bool ifstopped (int status) + { + return octave_wifstopped (status); + } + + static int stopsig (int status) + { + return octave_wstopsig (status); + } + + static bool ifcontinued (int status) + { + return octave_wifcontinued (status); + } +}; + #endif