[C++-sig] importing embedded dynamic lib

Rene Rivera grafik.list at redshift-software.com
Thu Jun 10 05:51:57 CEST 2004


Vio wrote:
> Perhaps I didn't explain myself correctly. My question would come down to:
> *what API call*
> does the python interpreter use when I type at the python prompt:
> 
>  >>> import mysharedlib
> 
> where "mysharedlib" is file "mysharedlib.so" somewhere on the PYTHONPATH.

Like I said before it uses dlopen and related OS functions, see:

http://www.die.net/doc/linux/include/dlfcn.h
http://www.die.net/doc/linux/man/man3/dlopen.3.html
http://www.die.net/doc/linux/man/man3/dlsym.3.html
http://www.die.net/doc/linux/man/man3/dlclose.3.html

Or go to your Linux shell and type "man dlopen".

> What I wish is to use *that* call, but change arguments as to substitute
> to the [my guess] file pointer for a memory buffer pointer.

You can not. Unless you write a different *dynamic linker loader* 
(ld.so), see:

http://www.die.net/doc/linux/man/man8/ld.so.8.html

[snip]
> PyImport_ExecCodeModule(char *name, PyObject *co)
> 
> only I'd have to construct a PyObject out of my buffer, since that's what
> PyImport_ExecCodeModule() wants as 2nd argument. But API docs say this 2nd
> argument should be python bytecode data, so I don't know if it won't 
> choke on
> compiled ELF binaries instead, hence I'm not too sure about this 
> particular hack.

It will not work. Python doesn't load ELF, it only loads Python code. 
It's the *operating system* which is loading the ELF.

[snip]
> Just a wild guess.

Very wild ;-)

And like my sig below says... Don't assume.. that things work they way 
you want them to work.


-- 
-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. - http://redshift-software.com
-- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq




More information about the Cplusplus-sig mailing list