Archived

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

Impact of include on on structs in modules(Python)

(Linux/i386 (FC3), Ice-2.1.0, Python 2.4)

I have a few struct definitions in my file struct.ice:
module Foo {
  struct MyStruct {
    ...
  };
};

I keep all my “types” (or structures) in the same file, all defined at this top level module level. I then import them into each place that needs them like this:
#include <struct.ice>

module Foo {
  interface Bar {
    MyStruct getStruct();
  };
};

You would think this works, and at least from my reading of the manual, it should, as it is possible to open and close a module and add new things into it. Unfortunately, this continually gave me an error:
sys:1: RuntimeWarning: invalid return value for operation `getStruct'
TestApplication.py: warning: dispatch exception: 
    Operation.cpp:870: Ice::MarshalException:
protocol error: error during marshaling or unmarshaling

Somewhat useful, I guess, but unfortuantely it didn’t seem to help me figure it out. When I finally moved the struct definition inside the other file, everything worked. Perhaps it was my running of the slice compiler, slice2py:

$ slice2py -I. --all --output-dir ../lib/ Foo.ice

Any thoughts? I'd like to keep these sort of common definitions in a separate file.

Comments

  • matthew
    matthew NL, Canada
    Hi,

    I just created an example that I've attached to this post that uses a similar setup. I ran, manually:

    slice2py -I. --output-dir generated Hello.ice
    slice2py -I. --output-dir generated DemoBase.ice

    then:

    PYTHONPATH=$PYTHONPATH:generated python Server.py

    and in another window:

    PYTHONPATH=$PYTHONPATH:generated python Client.py

    And everything worked as expected.

    If you don't want to use slice2py as above then you can uncomment the

    #Ice.loadSlice('--all -I. Hello.ice')
    import Demo

    At the top of Server.py and Client.py.

    I also tried cleaning out the generated directory and running:

    slice2py --all -I. --output-dir generated Hello.ice

    and everything also worked as expected. Note that in this case I did not run slice2py on BOTH .ice files. In general if you are using static code generation using --all is not recommended.

    If this example doesn't sort things out for you then please create a self-contained example that demonstrates the problem and we'll look into it for you!

    Best Regards, Matthew
  • Fixed
    matthew wrote:
    In general if you are using static code generation using --all is not recommended.

    Based on this, I re-ran everything using both multiple runs of slice2py and with a *.ice glob, and it worked great. It seems the problem is related to using the --all bit on the compiler. The help for slice2py says:
    --all Generate code for Slice definitions in included files.

    It would probably be good to make a comment in both the documentation and the command line help that this is for dynamic generation, not static.

    Thanks for the assistance! You guys are great.