On Mon, Jun 13, 2011 at 9:39 PM, Babak Khataee <email@example.com>
I've come across what might be an unusual problem involving py++ generated boost python code that I was hoping someone might be able to help me with.
We're using py++ to create python bindings for two libraries, one third party (libA) and the other in house (libB - which has a dependency on libA). The two libraries both define a class called 'Box2f' which is being exposed in both bindings. Before importing the bindings into python we set the dlopen flags to be 'RTLD_GLOBAL | RTLD_NOW' to avoid cross module problems. Due to the dependency between the two libA needs to be imported first. Doing so defines and calls the registration function for the Box2f class, now when libB is imported it calls the same Box2f registration function rather its own one.
Are you sure?
This means that libAbinding.Box2f is the same as libBbinding.Box2f :(
It seems that the binding code for both libraries defines a 'register_Box2f_class' function and that renaming this in either library binding code fixes the problem. However, I was wondering if there is a way change the name of the function that gets generated through py++ ? I've had a peek around the code and got the impression that by creating a custom 'multiple_files_t' class I could control this behaviour, but I wasn't sure whether this would be a good approach or not ?
An alternative would be to just change the name of the classes in the binding so they're not the same, but if possible we'd rather avoid introducing differences between the binding and library code.
I think your analysis has a mistake. 'RTLD_GLOBAL | RTLD_NOW' causes Boost.Python registry (the component, which keeps the registered classes, functions, conversions and etc) to be defined only once and shared between all extension modules. In my opinion, what happens is that you are trying to register class with the same name and Boost.Python skips the second definition. (You should get the warning, during your extension import).
I think, what you can do is to change the classes aliased, import them into Python and then to provide a new alias, which is the original name,
mb = module_builder_t(...)
mb.class_('Box2f').alias = "LibBBox2f"
where __init__.py content is something like:
import * from libbbinding
Box2f = LibBox2f
Hopefully that makes sense, any advice/help with this would be greatly appreciated.
Thank you very much.