Results 1 to 2 of 2

Thread: IcePy: Check types in generated compare methods

  1. #1
    cebix is offline Registered User
    Name: Christian Bauer
    Organization: AREVA NP
    Project: Diagnostics frontend for industrial I&C
    Join Date
    Jun 2007
    Location
    Erlangen, Germany
    Posts
    10

    IcePy: Check types in generated compare methods

    (Using Ice 3.3.1 on Linux)

    Consider this Slice definition:
    Code:
    module Demo {
        struct Value {
            float v;
        };
    };
    Now observe this Python session:
    Code:
    >>> from Demo import *
    >>> l = ['a', 5, Value(2.0)]
    >>> 'a' in l
    True
    >>> 5 in l
    True
    >>> Value(2.0) in l
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "Demo_ice.py", line 36, in __cmp__
        if self.v < other.v:
    AttributeError: 'str' object has no attribute 'v'
    This is because the Value.__cmp__() method generated by slice2py tries to access the 'v' member of the right-hand-side object even though it may not have one:
    Code:
            def __cmp__(self, other):
                if other == None:
                    return 1
                if self.v < other.v:
                    return -1
                elif self.v > other.v:
                    return 1
                return 0
    The code should check the type of 'other' before accessing 'Value'-specific members:
    Code:
            def __cmp__(self, other):
                if other == None:
                    return 1
                if not isinstance(other, _M_Demo.Value):
                    return NotImplemented
                if self.v < other.v:
                    return -1
                elif self.v > other.v:
                    return 1
                return 0
    With the comparison fixed like this, the example works as expected:
    Code:
    >>> 'a' in l
    True
    >>> 5 in l
    True
    >>> Value(2.0) in l
    True
    >>> Value(2.5) in l
    False

  2. #2
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    Thanks for the report. We'll consider this for the next release.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 03-11-2011, 07:28 AM
  2. Callback prx and time out check
    By mathgl in forum Help Center
    Replies: 1
    Last Post: 05-17-2010, 03:15 AM
  3. Replies: 1
    Last Post: 03-12-2007, 12:07 PM
  4. C# code generated for comparison methods
    By kwaclaw in forum Comments
    Replies: 3
    Last Post: 10-11-2005, 01:54 PM
  5. Replies: 5
    Last Post: 05-29-2004, 09:18 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
  •