Thread: [pygccxml-development] FT - name uniqueness
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2006-10-09 21:23:36
|
Hi. I would like to propose solution for function name uniqueness problems. Problem description: void do_smth( int& ); void do_smth( int&, int& ); If user will specify output_t transformer for both functions the generate code will not compile, because Py++ will generate 2 functions with the same signature. In order to solve this problem, we have to mangle into function name next data: 1. full name ( namespaces, class names ) 2. return type information 3. arguments type information 4. template arguments type information Fortunately every function in pygccxml already has property that contains all this information: mangled . I think we can reuse it for this purpose. Actually we will have to apply base64( http://docs.python.org/lib/module-base64.html ) encoding in order to get valid C++ identifier. Comments? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Matthias B. <ba...@ir...> - 2006-10-10 08:47:37
|
Roman Yakovenko wrote: > Hi. I would like to propose solution for function name uniqueness problems. > > Problem description: > > void do_smth( int& ); > void do_smth( int&, int& ); > > If user will specify output_t transformer for both functions the > generate code will > not compile, because Py++ will generate 2 functions with the same signature. > > In order to solve this problem, we have to mangle into function name next data: > 1. full name ( namespaces, class names ) > 2. return type information > 3. arguments type information > 4. template arguments type information Assuming that the name has been mangled, how do you invoke those two functions from Python? - Matthias - |
From: Roman Y. <rom...@gm...> - 2006-10-10 09:14:21
|
On 10/10/06, Matthias Baas <ba...@ir...> wrote: > Roman Yakovenko wrote: > > Hi. I would like to propose solution for function name uniqueness problems. > > > > Problem description: > > > > void do_smth( int& ); > > void do_smth( int&, int& ); > > > > If user will specify output_t transformer for both functions the > > generate code will > > not compile, because Py++ will generate 2 functions with the same signature. > > > > In order to solve this problem, we have to mangle into function name next data: > > 1. full name ( namespaces, class names ) > > 2. return type information > > 3. arguments type information > > 4. template arguments type information > > Assuming that the name has been mangled, how do you invoke those two > functions from Python? I don't change the "alias" of the function, only its wrapper name. Python will see the original function name. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Matthias B. <ba...@ir...> - 2006-10-10 11:15:23
|
Roman Yakovenko wrote: > On 10/10/06, Matthias Baas <ba...@ir...> wrote: >> Roman Yakovenko wrote: >> > Hi. I would like to propose solution for function name uniqueness >> problems. >> > >> > Problem description: >> > >> > void do_smth( int& ); >> > void do_smth( int&, int& ); >> > >> > If user will specify output_t transformer for both functions the >> > generate code will >> > not compile, because Py++ will generate 2 functions with the same >> signature. >> > >> > In order to solve this problem, we have to mangle into function name >> next data: >> > 1. full name ( namespaces, class names ) >> > 2. return type information >> > 3. arguments type information >> > 4. template arguments type information >> >> Assuming that the name has been mangled, how do you invoke those two >> functions from Python? > > I don't change the "alias" of the function, only its wrapper name. > Python will see the original function name. Which of the above functions will be called when I do the following in Python: result = do_smth() And how can I invoke the other function? - Matthias - |
From: Roman Y. <rom...@gm...> - 2006-10-10 11:31:14
|
On 10/10/06, Matthias Baas <ba...@ir...> wrote: > Roman Yakovenko wrote: > > On 10/10/06, Matthias Baas <ba...@ir...> wrote: > >> Roman Yakovenko wrote: > >> > Hi. I would like to propose solution for function name uniqueness > >> problems. > >> > > >> > Problem description: > >> > > >> > void do_smth( int& ); > >> > void do_smth( int&, int& ); > >> > > >> > If user will specify output_t transformer for both functions the > >> > generate code will > >> > not compile, because Py++ will generate 2 functions with the same > >> signature. > >> > > >> > In order to solve this problem, we have to mangle into function name > >> next data: > >> > 1. full name ( namespaces, class names ) > >> > 2. return type information > >> > 3. arguments type information > >> > 4. template arguments type information > >> > >> Assuming that the name has been mangled, how do you invoke those two > >> functions from Python? > > > > I don't change the "alias" of the function, only its wrapper name. > > Python will see the original function name. > > Which of the above functions will be called when I do the following in > Python: > > result = do_smth() > > And how can I invoke the other function? User will provide an aliase for the functions. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Matthias B. <ba...@ir...> - 2006-10-11 16:43:30
|
Roman Yakovenko wrote: >> >> > Hi. I would like to propose solution for function name uniqueness >> >> problems. >> >> > >> >> > Problem description: >> >> > >> >> > void do_smth( int& ); >> >> > void do_smth( int&, int& ); >> >> > >> >> > If user will specify output_t transformer for both functions the >> >> > generate code will >> >> > not compile, because Py++ will generate 2 functions with the same >> >> signature. >> >> > >> >> > In order to solve this problem, we have to mangle into function name >> >> next data: >> >> > 1. full name ( namespaces, class names ) >> >> > 2. return type information >> >> > 3. arguments type information >> >> > 4. template arguments type information >> >> >> >> Assuming that the name has been mangled, how do you invoke those two >> >> functions from Python? >> > >> > I don't change the "alias" of the function, only its wrapper name. >> > Python will see the original function name. >> >> Which of the above functions will be called when I do the following in >> Python: >> >> result = do_smth() >> >> And how can I invoke the other function? > > User will provide an aliase for the functions. Right. And as long as the alias is used for the wrapper names (which is currently the case) the above problem doesn't exist. The question may then rather be: who should report the error, Py++ or the compiler? I think it's desirable that Py++ notices this situation and can issue an error, but I don't think it's a good idea to mangle the name so that the code compiles but produces functions that could not be called because they are shadowed by other functions. In my opinion the current behavior that I will get a compile error is not that bad because it guarantees that such situations won't pass unnoticed. A mere Py++ warning would do nothing for me as I still get hundreds of warnings that I just can't go through right now, so I won't notice this warning. - Matthias - |
From: Roman Y. <rom...@gm...> - 2006-10-11 21:21:44
|
On 10/11/06, Matthias Baas <ba...@ir...> wrote: > Right. And as long as the alias is used for the wrapper names (which is > currently the case) the above problem doesn't exist. You are wrong. Consider next case: struct window{ void get_size( int&, int& ); }; struct image{ void get_size( int&, int& ); }; What you propose will force user always specify a function alias. While in my proposition, user will have to do this only in case he has overloaded functions in the same scope. > The question may then rather be: who should report the error, Py++ or > the compiler? I think it's desirable that Py++ notices this situation > and can issue an error, but I don't think it's a good idea to mangle the > name so that the code compiles but produces functions that could not be > called because they are shadowed by other functions. Generated code should work. And it is possible to achieve this. In case we have problems like this, it could be nice to compare function signatures and to decide what alias to give for the functions. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Matthias B. <ba...@ir...> - 2006-10-12 09:40:16
|
Roman Yakovenko wrote: > On 10/11/06, Matthias Baas <ba...@ir...> wrote: >> Right. And as long as the alias is used for the wrapper names (which is >> currently the case) the above problem doesn't exist. > > You are wrong. Consider next case: > > struct window{ > void get_size( int&, int& ); > }; > > struct image{ > void get_size( int&, int& ); > }; > > What you propose will force user always specify a function alias. 1. I was not proposing anything at all, I was just describing the current situation which I think is not that bad (I'd just like to avoid that a "fix" will automatically produce code that compiles but that makes one function inaccessible. For me, this would be worse than the current situation). 2. Your initial mail was dealing with functions that are inside the same scope. The above code should be no problem at all as the class name is incorporated into the wrapper name as well when the wrappers are free functions. If you have an example where this is not the case, then this might be a bug. >> The question may then rather be: who should report the error, Py++ or >> the compiler? I think it's desirable that Py++ notices this situation >> and can issue an error, but I don't think it's a good idea to mangle the >> name so that the code compiles but produces functions that could not be >> called because they are shadowed by other functions. > > Generated code should work. And it is possible to achieve this. Without that the user assigns an alias? How will you do that? If you use the same name to register two different functions that have the same signature then one of those functions is not accessible in Python. How should Boost.Python distinguish between the two? - Matthias - |
From: Roman Y. <rom...@gm...> - 2006-10-12 09:51:00
|
On 10/12/06, Matthias Baas <ba...@ir...> wrote: > 2. Your initial mail was dealing with functions that are inside the same > scope. The above code should be no problem at all as the class name is > incorporated into the wrapper name as well when the wrappers are free > functions. If you have an example where this is not the case, then this > might be a bug. I remember that I post the example for free functions, when Py++ generates to functions with the same signature. May be you already fixed it. I will check. > >> The question may then rather be: who should report the error, Py++ or > >> the compiler? I think it's desirable that Py++ notices this situation > >> and can issue an error, but I don't think it's a good idea to mangle the > >> name so that the code compiles but produces functions that could not be > >> called because they are shadowed by other functions. > > > > Generated code should work. And it is possible to achieve this. > > Without that the user assigns an alias? Yes, Py++ will do it for him. > How will you do that? get_value1 get_value2 ... > If you use the same name to register two different functions that have > the same signature then one of those functions is not accessible in > Python. How should Boost.Python distinguish between the two? Py++ should not generate code like this, unfortunately FT classes does not provide "function signature" functionality. I think this should be fixed. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Matthias B. <ba...@ir...> - 2006-10-13 07:13:29
|
Roman Yakovenko wrote: >> Without that the user assigns an alias? > > Yes, Py++ will do it for him. > >> How will you do that? > > get_value1 > get_value2 > ... And how will the user know about this? I certainly wouldn't expect the methods to show up under a different name. If you're going to implement this, then please also provide a way to disable this feature. (Personally, I think this should actually be disabled by default and only be enabled when the user requests it. Then Py++ can at least assume that the user knows what he's doing. I suppose it would also be desirable to be able to customize the rules for generating the names as I doubt that numbering the functions is hardly ever what the user wants to get) - Matthias - |