From: Josh C. <jc...@nc...> - 2008-02-15 04:34:05
|
On Fri, 15 Feb 2008, Nitro wrote: > Am 14.02.2008, 22:31 Uhr, schrieb William S Fulton <ws...@fu...>: > >> For the record I tried calling load_dynamic many times over for the same >> shared object, but specifying a different init function each time. Only the >> first init function gets called. So the solution works but only allows for >> one init function per shared object/dll. > > What a pity. It sounded like this was the solution you could use. I searched > the python code a bit wondering why this occurs. I wouldn't have expected it > to happen. Some results are below. imp_load_dynamic calls > _PyImport_LoadDynamicModule which calls _PyImport_FindExtension . It seems > like python does some caching of the modules and I suspect this is where it > might go wrong. I could be enitrely off, too. Imo the behaviour is wrong and > you could try bugging the python mailing list/newsgroup (comp.lang.python) > with this. I've lost track of the grand scheme here, and don't know what good can come from this, but here are some suggestions if you're trying to call multiple init functions. 1. Make one of your init functions call the other(s). You can make the SWIG-generated init function for module foo call init_bar by putting %init { void init_bar(void); init_bar(); } in the interface for foo. Alternatively, you might provide your own init function that calls all the SWIG-generated ones. 2. This is SWIG, so wrap the extra init funtions. Putting %inline %{ void init_bar(void); %} in the interface for module foo should allow you to call init_bar once you've import'ed foo. 3. Perhaps ctypes can help. Josh |