Re: [pygccxml-development] Two patches proposal
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2009-12-23 13:13:56
|
On Wed, Dec 23, 2009 at 1:07 PM, Berserker <ber...@ho...> wrote: > Hi, I'd like to discuss about two issues Hello > 1) properties generation > > I have some classes like this one: > > class Foo > { > Bar getBar() const; > void setBar(const Bar &bar); > }; > > getBar returns a temporary object because the return value is created by a > conversion > from an internal stored string (setBar saves the value in the same way) . > In this case name_based_recognizer_t creates a "readonly" property "Bar" > instead of a read/write one, > so I'm overriding the method in this way: > > def check_type_compatibility(self, fget, fset): > if decl_wrappers.name_based_recognizer_t.check_type_compatibility(self, > fget, fset): > return True > > t1 = fget.return_type > t2 = fset.arguments[0].type > > if declarations.is_reference(t2): > t2 = declarations.remove_cv( declarations.remove_reference( t2 ) ) > if declarations.is_same( t1, t2 ): > return True > > return False > > What about this change? Is it reasonable to be "merged" in the svn? The short answer is no :-(. The main reason for it: such code does not meat user expectations. Let me explain: foo = Foo() foo.Bar.x = 2 assert foo.Bar.x == 2 The following is explanation how I thought "add_properties" functionality should be used in such case. class custom_name_based_recognizer_t( name_based_recognizer_t ): def __init__( ... ): ... def check_type_compatibility(self, fget, fset): <your code > cls = mb.class_( ... ) cls.add_properties( recognizer=custom_name_based_recognizer_t() ) Could it be an acceptable solution? > 2) Implicit conversions: > > class Foo > { > public: > Foo(int v, bool flag = true); // convertible from int > Foo(double v1, double v2); // not convertible from double because v2 > hasn't default value > }; > > I looked at constructor_t.does_define_implicit_conversion implementation and > I think that > the following two lines are "incomplete": > > if 1 != len( self.arguments ): > return False > > Isn't supposed to be: > > if 1 != len( self.arguments ) and (arguments > 1 haven't default value): > return False > > Using the above patch Foo should be implicit convertible from int right? I am not sure. According to the MSDN ( http://msdn2.microsoft.com/en-us/library/h1y7x448.aspx ) "...C++ constructors that have just one parameter automatically perform implicit type conversion. ...". In your case the constructor has 2 arguments. I tested the following code with gcc 4.4.1 struct Foo{ Foo( int i, bool b=false ){} }; void dosmth( Foo ){ } int main( int argc, const char* argv[] ){ dosmth( 11 ); }; and it compiles fine. I don't know C++ at the level of standard. Do you know what the standard says? Does the code compile fines with MSVC compiler? > How can I write it? It is not a problem to write it: if 1 != len( self.required_args ): return False > Any hope to apply the code to the svn? The first issue - I believe you have a solution, the second one - I prefer to know the answers. If they are positive - I will apply the patch almost immediately. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |