bugGNU Octave - Bugs: bug #42549, return code of mkoctfile

 
 

bug #42549: return code of mkoctfile

Submitter:  Andreas Weber <andy1978>
Submitted:  Fri 13 Jun 2014 09:24:16 AM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 13 Jun 2014 03:36:50 PM UTC, comment #1: 

Good work here.  I pushed your patch to the development branch (http://hg.savannah.gnu.org/hgweb/octave/rev/5b7b18d603ae).  The only thing I did was add more detail to the commit message.  Octave developers use a 1-line summary of the patch at the top and then a per file/per function description of what was done.  You can take a look at what I added at the link above.

Marking as fixed, closing report.

Rik <rik5>
Group administrator
Fri 13 Jun 2014 09:24:16 AM UTC, original submission:  

See also this thead: http://octave.1599824.n4.nabble.com/mkoctfile-exits-with-0-if-gcc-failed-td4664462.html and http://octave.1599824.n4.nabble.com/RE-return-code-of-mkoctfile-td4664466.html

mkoctfile returns 0 if the called subprocess returns != 0.

~/src/octave-src$ LC_ALL=C mkoctfile nonexistentfile.cpp
g++: error: nonexistentfile.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
g++: error: nonexistentfile.o: No such file or directory
~/src/octave-src$ echo $?
0


This is because system returns the exit status of the called process in the upper 8bits. According to "man wait" WIFEXITED and WEXITSTSTUS should be used for the bit shifting and masking stuff.

I propose the following patch (hg changeset attached):

diff -r 0ede4dbb37f1 src/mkoctfile.in.cc
--- a/src/mkoctfile.in.cc       Sun Mar 30 14:18:43 2014 -0700
+++ b/src/mkoctfile.in.cc       Wed Jun 04 14:42:58 2014 +0200
@@ -344,7 +344,10 @@
 {
   if (debug)
     std::cout << cmd << std::endl;
-  return system (cmd.c_str ());
+  int result = system (cmd.c_str ());
+  if (WIFEXITED (result))
+    result = WEXITSTATUS (result);
+  return result;
 }

If I use the makros WIFEXITED and WEXITSTATUS I get these warnings when compiling mkoctfile on debian wheezy 64bit with gcc 4.7.2:

mkoctfile.cc: In function ‘int run_command(const string&)’:
mkoctfile.cc:348:7: warning: use of old-style cast [-Wold-style-cast]
mkoctfile.cc:349:14: warning: use of old-style cast [-Wold-style-cast]


The old style cast is defined in /usr/include/stdlib.h:55

#ifdef __USE_BSD
...
#define __WAIT_INT(status)        (*(int *) &(status))


Perhaps we should use the octave wrappers like in toplev.cc:

if (octave_wait::ifexited (cmd_status))
  cmd_status = octave_wait::exitstatus (cmd_status);
else
  cmd_status = 127;


There are also some other definitions of these makros which wouldn't trigger teh old-style warning:

$ grep -R "define WEXITSTATUS"
liboctave/system/syswait.h:#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
configure:# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
gnulib-hg/lib/sys_wait.in.h:#  define WEXITSTATUS(x) (((x) >> 8) & 0xff)

$ grep -R "define WIFEXITED"
liboctave/system/syswait.h:#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
configure:# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
gnulib-hg/lib/sys_wait.in.h:#  define WIFEXITED(x) (WTERMSIG (x) == 0)
gnulib-hg/lib/sys_wait.in.h:# define WIFEXITED(x) ((x) != 3)


I'll attach a patch using WIFEXITED and WEXITSTATUS (ignoring the old-style cast warning)

-- Andy

Andreas Weber <andy1978>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by andy1978 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-06-13 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2014-06-13 andy1978 Attached File- Added fix_mkoctfile_return_value_#42549.patch, #31541

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code