From: SourceForge.net <no...@so...> - 2009-04-19 14:33:41
|
Bugs item #1875074, was opened at 2008-01-18 17:05 Message generated for change (Comment added) made by koro666 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1875074&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: csharp Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Koro (koro666) Assigned to: William Fulton (wsfulton) Summary: [csharp] getCPtr should use object.ReferenceEquals Initial Comment: The internal getCPtr function uses operator== to compare the "obj" parameters instead of using object.ReferenceEquals. This has bad side effects if the class has defined operator== (with %typemap(cscode)) that calls another wrapped function in the class (leading to an infinite loop) As an attachment, a patch to correct the problem (which I hope I created correctly). ---------------------------------------------------------------------- Comment By: Koro (koro666) Date: 2009-04-19 10:33 Message: This was from a while ago, at a job I don't even work at anymore :) Basically I was trying to work around the fact that the csharp module doesn't wrap C++ operators. So what I did basically was: 1- %rename all of C++ operators in a class with "proper names" (aka operator== becomes OperatorEqual) so they could be wrapped as regular functions. 2- Make said functions private in the C# wrapper class. 3- Use %typemap(cscode) to add code to the C# class implementing a proper operator== that just calls the private function from 1. Now obviously, OperatorEqual will call getCPtr, which uses == (aka the C# class's operator==) to check if obj is null. Since I defined it to call OperatorEqual, which internaly calls getCPtr... bam, infinite recursion. I don't think it matters much if Object.ReferenceEquals or (object)obj==null is used to compare if obj is null, as long as it makes sure to not call the operator== function if it's defined. ---------------------------------------------------------------------- Comment By: William Fulton (wsfulton) Date: 2009-04-10 19:28 Message: Using (object)obj == null could also be used instead. In the MSDN docs http://msdn.microsoft.com/en-us/library/ms173147(VS.80).aspx on overloading operator==, it suggests the operator== should be using the cast to object. Perhaps your operator== isn't following the guidelines? Can you please provide a testcase showing the problem? Thanks. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1875074&group_id=1645 |