[Insight-developers] Re: Are preimport() and postimport() really useful in itkbase.py ?

Brad King brad.king at kitware.com
Sun Jan 15 11:00:25 EST 2006


Gaetan Lehmann wrote:
> I don't really understand the preimport() and postimport() function in 
> itkbase.py. I seems that we can load the modules without them without any 
> problem.
> Are they really useful ?

On what platform are you succeeding without them?  Windows will work 
fine but posix platforms require them.  The ITK wrapper code must be 
loaded with RTLD_GLOBAL set in the dl flags.  By default python loads 
modules without this flag to keep them isolated from one another.  Since 
the wrapper modules share code (such as the virtual tables of the higher 
classes), their symbols must be integrated at runtime.

Although the modules appear to load successfully they may not run 
properly.  If an object is created in one module and passed through 
python to another then a dynamic_cast down the hierarchy may fail 
depending on the compiler's implementation of RTTI.  In GCC 3.x and 
above it will almost certainly fail.  That is the reason preimport and 
postimport were created in the first place.

The functions also allow the libraries to be loaded without setting 
LD_LIBRARY_PATH to point at their location.

-Brad


More information about the Insight-developers mailing list