Home Bug Reports

python constructor remembers default instance (slice2py)

DaVinci79DaVinci79 Member Vincent vanBeverenOrganization: FOM RijnhuizenProject: Remote access research data Magnum PSI
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.

Comments

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    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,
    Mark
  • DaVinci79DaVinci79 Member Vincent vanBeverenOrganization: FOM RijnhuizenProject: Remote access research data Magnum PSI
    ok thanks! looking forward to the next release then :)
Sign In or Register to comment.