Thread: [pygccxml-development] py++ generating invalid default args code
Brought to you by:
mbaas,
roman_yakovenko
From: Allen B. <al...@vr...> - 2008-01-14 23:02:20
|
I am wrapping a method that looks something like this: class MyClass { public: void init(const unsigned value=0, const ClassB valueb=ClassB(-10.0, 11.0), const float other_val=2.0); }; When py++ wraps this it creates code like this: { //::MyClass::init typedef void ( ::MyClass::*init_function_type )( ::unsigned const,::ClassB const,::float const ) ; MyClass_exposer.def( "init" , init_function_type( &::MyClass::init ) , ( bp::arg("value")=(unsigned char const)(0) , bp::arg("valueb")=::ClassB( (&-1.0e+1), (&1.1e+1) , bp::arg("other_val")=2.0e+0 ) ); } As you can see the "&-1.0e+1" style values are invalid code and the compiler fails to build the code. Is this a know issue and is there a simple work around or way to prevent py++ from generating code that won't compile? Thanks, Allen PS. Sorry that I could not include the "real" sample, the code for it is internal use only. |
From: Roman Y. <rom...@gm...> - 2008-01-15 06:39:10
|
On Jan 15, 2008 1:02 AM, Allen Bierbaum <al...@vr...> wrote: > I am wrapping a method that looks something like this: > > class MyClass > { > public: > void init(const unsigned value=0, > const ClassB valueb=ClassB(-10.0, 11.0), > const float other_val=2.0); > }; > > When py++ wraps this it creates code like this: > > { //::MyClass::init > > typedef void ( ::MyClass::*init_function_type )( ::unsigned > const,::ClassB const,::float const ) ; > > MyClass_exposer.def( "init" > , init_function_type( &::MyClass::init ) > , ( bp::arg("value")=(unsigned char const)(0) > , bp::arg("valueb")=::ClassB( (&-1.0e+1), (&1.1e+1) > , bp::arg("other_val")=2.0e+0 ) ); > } > > As you can see the "&-1.0e+1" style values are invalid code and the > compiler fails to build the code. Is this a know issue and is there a > simple work around or way to prevent py++ from generating code that > won't compile? Yes, this is a known issue - http://language-binding.net/pygccxml/design.html#patchers You have few ways to fix the problem: http://language-binding.net/pyplusplus/documentation/functions/default_args.html or mb = module_builder_t(...) mb.mem_fun( '::MyClass::init' ).arguments[1].default_value = 'ClassB(-10.0, 11.0)' Choose the one you like HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2008-01-15 14:14:51
|
Is there a way to detect this problem is happening and output an error with a link to the documentation? The way it works now where it generates code that doesn't compile seems a bit problematic to me. I don't think a new user would be able to decipher what is going on and determine what they need to fix. -Allen Roman Yakovenko wrote: > On Jan 15, 2008 1:02 AM, Allen Bierbaum <al...@vr...> wrote: >> I am wrapping a method that looks something like this: >> >> class MyClass >> { >> public: >> void init(const unsigned value=0, >> const ClassB valueb=ClassB(-10.0, 11.0), >> const float other_val=2.0); >> }; >> >> When py++ wraps this it creates code like this: >> >> { //::MyClass::init >> >> typedef void ( ::MyClass::*init_function_type )( ::unsigned >> const,::ClassB const,::float const ) ; >> >> MyClass_exposer.def( "init" >> , init_function_type( &::MyClass::init ) >> , ( bp::arg("value")=(unsigned char const)(0) >> , bp::arg("valueb")=::ClassB( (&-1.0e+1), (&1.1e+1) >> , bp::arg("other_val")=2.0e+0 ) ); >> } >> >> As you can see the "&-1.0e+1" style values are invalid code and the >> compiler fails to build the code. Is this a know issue and is there a >> simple work around or way to prevent py++ from generating code that >> won't compile? > > Yes, this is a known issue - > http://language-binding.net/pygccxml/design.html#patchers > > You have few ways to fix the problem: > http://language-binding.net/pyplusplus/documentation/functions/default_args.html > or > mb = module_builder_t(...) > mb.mem_fun( '::MyClass::init' ).arguments[1].default_value = > 'ClassB(-10.0, 11.0)' > > Choose the one you like > > HTH > |
From: Roman Y. <rom...@gm...> - 2008-01-15 14:35:25
|
On Jan 15, 2008 4:14 PM, Allen Bierbaum <al...@vr...> wrote: > Is there a way to detect this problem is happening and output an error > with a link to the documentation? The way it works now where it > generates code that doesn't compile seems a bit problematic to me. I > don't think a new user would be able to decipher what is going on and > determine what they need to fix. If I would now to detect such use case I would treat them in Py++. For free and non virtual member functions you can use next functionality http://language-binding.net/pyplusplus/documentation/functions/default_args.html What user you mean by "a new user" - a bindings developer or final user, who will run the script and compile generated code? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |