Cross-module name resolution with boost python not working?

Here is my problem:

I have two C ++ modules, A and B, which are built as dynamically linked libraries. A offers basic math functions and custom exception types. B is a higher level module that uses A.

B :: someFunction () calls a function from A and tries to catch its own exception A: MyExceptionFromA to convert it to a custom type B: MyExceptionFromB (since users of module B do not need to know about the implementation of detail A).

Everything works fine as long as I stay in the C ++ domain. However, if I expose B :: someFunction () in python via boost python, the exception no longer gets into the C ++ module.

I can catch the std :: runtime_error from which A: MyExceptionFromA is raised and call typeid (e) .name () to get the correct malformed name, so I know the right exception has been thrown. Therefore, I suspect that the problem is resolving this garbled character to the correct type of exception.

I found this link explaining that "python uses the [island] model to open extension modules so that authors of extension modules do not need to know which characters other extension modules can use." I suspect this is part of the problem / solution, but I don't know enough about character resolution to figure out how to solve my problem.

Any ideas?

+4
source share
1 answer

I found a job around my problem. Based on this and the link text , I realized that adding

import sys, dl sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL) 

solves the problem before I turn it on, forcing python to open libraries in near global mode. But I still hope for an alternative solution, if any. As mentioned in the first link, I suspect that this could have unforeseen consequences (I already know that name collision can be a problem, and I suspect that performance may also be affected, but are there any other side effects?)

+2
source

All Articles