Archived

This forum has been archived. Please start a new discussion on GitHub.

Mishap in slice compilers

Hi

Ice 3.3 (slice2html), Ice 3.4.1 (slice2java, slice2py, slice2cs), any compiler, Mac OS X/FreeBSD/Linux, MCPP V.2.7.2 (2008/11)

Consider the following slice:
#ifndef MY_MODULE_ICE
#define MY_MODULE_ICE

module MyModule
{
  struct foo
  {
    string bar; // foobar
  };
};

#endif

This compiles fine using slice2cpp, slice2rb, and slice2php, but fails under slice2py (also Ice.loadSlice), slice2java, slice2cs, and slice2html giving the following error:
[dev@bsd /tmp]$ slice2py test2.ice
/tmp/test2.ice:9: struct `foo' must have at least one member
[dev@bsd /tmp]$ 

The Ice manual states:
4.5.1 Comments
Slice definitions permit both the C and the C++ style of writing comments:

/*
* C-style comment.
*/

// C++-style comment extending to the end of this line.

so I assume this is misbehavior in the parser of those slice compilers.

All compilers that fail actually set "keepComments" to true in their call to Slice::Preprocessor:: preprocess(bool). This leads to the call to mcpp set the "-C" flag, which in turn keeps comments in the output.

I've checked the preprocessor output of slice2py and realized, that the preprocessor is moving the comment to the wrong position:
[dev@bsd /tmp]$ slice2py -E test2.ice
#line 1 "/tmp/test2.ice"



module MyModule
{
  struct foo
  {
// foobar    string bar;
  };
};

Yikes! Calling mcpp on the command line directly yields the same results:
[dev@bsd /tmp]$ mcpp -C test2.ice
#line 1 "/tmp/test2.ice"



module MyModule
{
  struct foo
  {
// foobar    string bar;
  };
};

I'm not certain if this really intended by mcpp or a bug at that end (it happens in mcpp 2.7.2, on both MacOS and FreeBSD). Running mcpp in OLD mode (-@old) resolves the issue, but I', not certain if this lead to other problems.
[dev@bsd /tmp]$ mcpp -@old -C test2.ice
#line 1 "/private/tmp/test.ice"



module MyModule
{
  struct foo
  {
    string bar; // foobar
  };
};

I just realized, that the comment features were introduced in Ice 3.4.0, that's why we didn't see that issue earlier (the same problem exists when calling slice2html on Ice 3.3):
The Slice compilers for Java, C#, and Python now preserve Slice comments in the generated code.

So I would suggest one of the following solutions:
  1. Contact the authors of mcpp, if you assume this is an mcpp bug
  2. Add 'args.push_back("-@old");' at line 153 of cpp/Slice/Preprocessor.cpp (if @old doesn't 't break other things)
  3. Call Slice::Preprocessor:: preprocess passing "false" instead of true (probably not want you really want)
  4. Change all slice compilers to call preprocess with keep comments set to true (so this way at least they behave identically)
  5. Make same line C++ style comments illegal (yikes!)

Cheers
Michael

Comments

  • Additional information

    It seems that this *might* depend on the gcc version used. I can reproduce this easily on Mac OS X using Ice-3.3, but using a fresh binary installation of Ice-3.4.1 does not show this issue on Mac OS X. Neither does it on Debian.

    Is it possible that you're using a specially modified version of mcpp in your binary package that differs from the one coming out of macports / FreeBSD ports?!
  • bernard
    bernard Jupiter, FL
    Hi Michael,

    Yes, we patched a few bugs in mcpp. You can get the patch (and build instructions) in our third-party source distribution: http://www.zeroc.com/download.html#src

    Best regards,
    Bernard
  • Enlightenment?!

    I just realized, that Ice requires special patches applied to mcpp when compiled from source. I will try applying those patches and see if it solves the issues.
  • Should've waited for your reply :). I will try to install a patched version. Have you every tried to get in touch with the author of mcpp and get those patches incorporated into mcpp? Overall on a system with a shared libmcpp that would make a lot of sense.

    cheers
    Michael
  • Works now, instructions for FreeBSD ports

    Hi,

    I reinstalled mcpp using the patch, now it works ok. For FreeBSD aficionados the easiest way to accomplish this is to download the attached patch and do:

    gunzip patch-mcpp-ice.gz
    sudo mkdir -p /usr/ports/devel/mcpp/files
    sudo cp patch-mcpp-ice /usr/ports/devel/mcpp/files
    sudo portupgrade -f devel/mcpp

    (this patch is the same as found in http://zeroc.com/download/Ice/3.4/ThirdParty-Sources-3.4.1.tar.gz)

    cheers
    Michael
  • mcpp patch now port of FreeBSD ports

    Just wanted to give a status update on this. As of today the mcpp patch developerd by ZeroC is part of the FreeBSD ports tree. It has been approved by Kiyoshi Matsui, the maintainer and developer of mcpp.

    To upgrade mcpp run:

    sudo portsnap fetch update
    sudo portupgrade devel/mcpp

    the new port version number is 2.7.2_1
  • bernard
    bernard Jupiter, FL
    Hi Michael,

    Thank you for this update.

    I hope Kiyoshi Matsui will also publish soon a new version of mcpp (2.7.3?) with these fixes.

    Best regards,
    Bernard
  • Hi Bernard,

    unfortunately Kiyoshi has more severe issues to worry about right now (see below for his answer to my original request), I suspect it relates to recent events in Japan. He was kind enough to reply to my request (and later on my PR Query PR Database. He gave his consent to your patch and AFAIK would agree to commit that to the mcpp project. As mcpp is on SourceForge (mcpp.sourceforge.net), maybe you can get involved in creating a new release?!

    cheers
    Michael

    Kiyoshi wrote:
    "Hello,

    I'm very sorry, but I have no time for mcpp now. I think the Zeroc
    patch is correct, and has no undesirable side effect. So, if someone
    make an mcpp package applying the patch, and commit it to FreeBSD or any
    other system, I will agree with it.

    --
    Kiyoshi Matsui, the maintainer of mcpp"