slice2sl 0.3.0 - code generation for dispatch__

kwaclawkwaclaw Oshawa, CanadaMember Karl WaclawekOrganization: Personal
slice2sl generates code for the dispatch__ operation like this:
public override Ice.DispatchStatus dispatch__(IceInternal.Incoming inS__, Ice.Current current__)
{
    int pos = _System.Array.BinarySearch(all__, current__.operation);
    . . .
}
The binary search shown above can fail to find the operation name, as no proper string comparison is performed, and then one gets an Ice.OperationNotExistException when one should not.

Replacing the code above with
int pos = _System.Array.BinarySearch(all__, 0, all__.Length,
            current__.operation, IceUtil.StringUtil.OrdinalStringComparer);
works for me.

One could also replace the operations and types with their generic equivalents, i.e. BinarySearch<string> and IComparer<string>.

Karl

Comments

  • matthewmatthew ✭✭✭ NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Karl, can you detail what exactly isn't working?
  • kwaclawkwaclaw Oshawa, CanadaMember Karl WaclawekOrganization: Personal
    matthew wrote: »
    Karl, can you detail what exactly isn't working?


    Sure,

    My little demo app threw an Ice.OperationNotExistException when I was sure that both server and client (in this case it is a call-back) used the same slice definitions. So I stepped into the debugger, and noticed that BinarySearch returned a negative number, though I could see that the item it searched for (an operation name) was actually contained in the array.

    So, checking the docs for string.IComparable (used by BinarySearch) it states that this performs a culture sensitive comparison - I don't think this is desirable. Whether the binary search fails improperly or not will depend on the contents of the array and the locale used. It may oftent work properly, as it did for the other operations in my app. I then changed the generated code to perform an ordinal string comparison (as shown before), and the problem went away.

    Does that explain it?
  • matthewmatthew ✭✭✭ NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Thanks for reporting this bug Karl. You can observe the bug with a slice interface such as the following:
    interface Operations
    {
        void aaa();
        void AAB();
        void aac();
        void aad();
        void aae();
    };
    

    Try calling AAB and you'll get an ObjectNotExistException. Ice for .NET does not have this issue.
Sign In or Register to comment.