Results 1 to 3 of 3

Thread: python constructor remembers default instance (slice2py)

  1. #1
    DaVinci79 is offline Registered User
    Name: Vincent vanBeveren
    Organization: FOM Rijnhuizen
    Project: Remote access research data Magnum PSI
    Join Date
    Oct 2008
    Posts
    9

    python constructor remembers default instance (slice2py)

    When I try to generate python objects for the following ice definition:

    Code:
    struct Point {
      int x;
      int y;
    }
    
    struct Cursor {
      Point point;
    }
    and I would create 2 cursor instances:

    Code:
    c1 = Cursor()
    c2 = Cursor()
    One Point instance will be shared over both object. So:

    Code:
    c1.point.x = 3
    will cause
    Code:
    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.

  2. #2
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    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

  3. #3
    DaVinci79 is offline Registered User
    Name: Vincent vanBeveren
    Organization: FOM Rijnhuizen
    Project: Remote access research data Magnum PSI
    Join Date
    Oct 2008
    Posts
    9
    ok thanks! looking forward to the next release then

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 07-16-2007, 02:17 AM
  2. Python: #include/import problem with slice2py
    By hiasl in forum Bug Reports
    Replies: 1
    Last Post: 02-21-2006, 09:59 AM
  3. Identity Constructor
    By acbell in forum Comments
    Replies: 1
    Last Post: 08-30-2005, 01:34 PM
  4. Passing parameters to constructor
    By jacopo in forum Help Center
    Replies: 2
    Last Post: 05-12-2005, 12:47 PM
  5. Constructor and Default-Parameter
    By Mr.Freeze in forum Help Center
    Replies: 1
    Last Post: 08-13-2003, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •