bugGNU Octave - Bugs: bug #38746, Including mex.h does not work with...

 
 

bug #38746: Including mex.h does not work with G++ 4.8

Submitted by:  Sébastien Villemot <svillemot>
Submitted on:  Mon Apr 15 15:45:37 2013  
 
Category: LibrariesSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Other
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: 3.6.4Operating System: GNU/Linux

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Thu May 30 18:15:06 2013, comment #7:

I checked in your changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/122d3f62e179

John W. Eaton <jwe>
Project Administrator
Sun May 26 19:47:39 2013, comment #6:

Here's a patch implementing the original suggestion by Sébastien, which is to include mexproto.h outside the extern "C" block in mex.h. That way cstdlib will continue to be included in C++ code.

(file #28181)

Clemens Buchacher <drizzd>
Wed May 22 09:54:55 2013, comment #5:

Some additional notes for replicating the problem on Debian sid (unstable).

You need to install package g++-4.8. Then the example given by Clemens has to be compiled with:

I get a compilation failure with Octave 3.6.4 (did not try with devel branch). If I do not set CXX=g++-4.8, then it uses GCC 4.7 (current default on Debian sid), and the program compiles.

Sébastien Villemot <svillemot>
Tue May 21 21:36:40 2013, comment #4:

Below is a simple testcase with revision 16692:c19cc8c158b3 (this Saturday).

I get the same output with this:

I am attaching mex_empty.ii and mex_empty.s from that command. I am also attaching /usr/include/c++/4.8.0/cstdlib.

GCC Sources:
_snapshot=4.8-20130502
source=(ftp://gcc.gnu.org/pub/gcc/snapshots/${_snapshot}/gcc-${_snapshot}.tar.bz2)

On my system GCC is built without patches, with the following flags:

CPPFLAGS="-D_FORTIFY_SOURCE=2"
CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4"
CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4"
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro"
# using -pipe causes spurious test-suite failures
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48565
CFLAGS=${CFLAGS/-pipe/}
CXXFLAGS=${CXXFLAGS/-pipe/}

${srcdir}/${_basedir}/configure --prefix=/usr \
--libdir=/usr/lib --libexecdir=/usr/lib \
--mandir=/usr/share/man --infodir=/usr/share/info \
--with-bugurl=https://bugs.archlinux.org/ \
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ \
--enable-shared --enable-threads=posix \
--with-system-zlib --enable-__cxa_atexit \
--disable-libunwind-exceptions --enable-clocale=gnu \
--disable-libstdcxx-pch \
--enable-gnu-unique-object --enable-linker-build-id \
--enable-cloog-backend=isl --disable-cloog-version-check \
--enable-lto --enable-gold --enable-ld=default \
--enable-plugin --with-plugin-ld=ld.gold \
--with-linker-hash-style=gnu --disable-install-libiberty \
--disable-multilib --disable-libssp --disable-werror \
--enable-checking=release
make

(file #28132, file #28133, file #28134)

Clemens Buchacher <drizzd>
Mon May 20 21:37:13 2013, comment #3:

Also, can someone please post a precise recipe for reproducing the problem? I'm not seeing any problem compling a mex file with GCC 4.8 on my system using the current development sources. I'd like to understand exactly what the problem is before applying a patch.

John W. Eaton <jwe>
Project Administrator
Mon May 20 21:33:54 2013, comment #2:

I would prefer a fix that ensures that we include cstdlib in C++ code because cstdlib is supposed to avoid macro definitions that stdlib.h may provide.

John W. Eaton <jwe>
Project Administrator
Sat May 4 16:32:01 2013, comment #1:

The patch below fixes the issue for me. Instead of disallowing mexproto.h to be included from extern "C" context, I think it is more appropriate instead not to include C++ header files such as cstdlib in a header file which declares only C functions. I am not sure what the motivation was for doing so, but for the record, there are two more files with similar constructs of the form #ifdef __cpluslus #include <cheader> extern "C" { #else <header.h> #include #endif:

libinterp/interp-core/cutils.h
liboctave/cruft/misc/quit.h

I did not touch those to keep the change minimal.

---
diff -r a1f613e5066d libinterp/interp-core/mexproto.h
--- a/libinterp/interp-core/mexproto.h Sat May 04 09:37:28 2013 +0200
+++ b/libinterp/interp-core/mexproto.h Sat May 04 16:37:00 2013 +0200
@@ -49,11 +49,10 @@
#define MEXPROTO_H

#if defined (__cplusplus)
-#include <cstdlib>
extern "C" {
-#else
+#endif
+
#include <stdlib.h>
-#endif

/* The definition of OCTINTERP_API is normally provided by Octave's
config.h file. This is provided for the case of mex.h included by

Clemens Buchacher <drizzd>
Mon Apr 15 15:45:37 2013, original submission:

This is Debian bug #705485 (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=705485)

When including mex.h from a C++ source file, and compiling with G++ 4.8, the compilation crashes.

The root of the problem is that mex.h includes mexproto.h within an extern "C" block. In turn, mexproto.h includes cstdlib.

Apparently, including cstdlib within an extern "C" block was working with G++ 4.7, but this is no longer the case.

The fix is to include mexproto.h outside of the extern "C" block.

Sébastien Villemot <svillemot>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #28181:  gcc-v2.patch added by drizzd (829B - text/x-patch)
file #28132:  mex_empty.s added by drizzd (23B - application/octet-stream)
file #28133:  cstdlib added by drizzd (6kB - application/octet-stream)
file #28134:  mex_empty.ii added by drizzd (37kB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by jordigh (Updated the item)
  • -unavailable- added by drizzd (Posted a comment)
  • -unavailable- added by svillemot (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu May 30 18:15:06 2013jweStatusPatch Submitted=>Fixed
      Open/ClosedOpen=>Closed
    Sun May 26 19:47:39 2013drizzdAttached File-=>Added gcc-v2.patch, #28181
    Tue May 21 21:36:40 2013drizzdAttached File-=>Added mex_empty.s, #28132
      Attached File-=>Added cstdlib, #28133
      Attached File-=>Added mex_empty.ii, #28134
    Mon May 20 21:16:53 2013jordighStatusNone=>Patch Submitted

    Back to the top


    Powered by Savane 3.1-cleanup