[C++-sig] importing embedded dynamic lib

Vio vmilitaru at sympatico.ca
Thu Jun 10 02:17:45 CEST 2004


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.

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.
The memory buffer having the exact contents of file "mysharedlib.so", 
thus avoiding
a disk access. While the result here is not very sexy, this exercise 
becomes interesting
when the app receives "mysharedlib.so" over the network.
Once received over network, easy solution is to write "mysharedlib.so" 
to local disk,
then either do something like:

PyRun_SimpleString("import mysharedlib")
or
PyImport_ImportModule("mysharedlib")

I simply want to skip that. In still other words, I guess I'm looking
for something like

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.

Anyway, my gut guess is that I must find what calls python uses to import
shared libs, and somehow use that and substitute that file pointer to my 
buffer pointer.
Just a wild guess.

If someone has some ideas on this, I'd appreciate it.
Vio






More information about the Cplusplus-sig mailing list