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

python constructor remembers default instance (slice2py)

When I try to generate python objects for the following ice definition:
struct Point {
  int x;
  int y;

struct Cursor {
  Point point;

and I would create 2 cursor instances:
c1 = Cursor()
c2 = Cursor()

One Point instance will be shared over both object. So:
c1.point.x = 3
will cause
print c2.point.x
to print 3.

Now I know this is normal python behavior, but I doubt if it is desirable. It had me baffled for a while.

Also generating code for Java and C++ will cause an empty constructor to initialize everything to null. At least than it is clear you need to initialize your own instance because you get a NPE if you try to access c1.point.x.


  • mes
    mes California
    Hi Vincent,

    Thanks for reporting this. The current behavior is not the intended behavior. The intent was for the Cursor constructor to create a new instance of Point. We'll fix this bug.

    Best regards,
  • ok thanks! looking forward to the next release then :)