FAQ
I have a basic dynamic lib "noddy.so" which I want to
1- embed inside my executable
2- import by embedded python interpreter using an API call.

I have two questions:

1- what would be the recommended technique to embed a binary file inside
an executable?
My guess would be to add the binary "noddy.so" to the linking command,
but then
how do I get access to that chunk of code in my source file? My goal
would be to achieve something like

int* noddy_so = <binary here> ... but then how do I include the
binary code, or make the source code aware of it?

Using "#include" doesn't feel right, as this is a binary file, not
ASCII. And loading the file at run-time isn't right either, I need to
load it at compile time. And is "int*" the appropriate data type for
binary data?

2- Let's imagine that I managed to load "noddy.so" into my source code
somehow, and now have a pointer to it.
Any hints as to the correct python API call to import a dynamic lib
from a memory buffer? Could someone
tell me for example if the following makes sense for my purpose?

------------------------------
char *modulename="noddy", *filename="no_real_file";
PyObject *tmp;

/*Here try to translate the binary lib into a PyObject*/
tmp = Py_CompileString(noddy_so, filename, Py_file_input);
if (tmp == NULL)
error("Can't compile module [tmp]");

/*Import the "noddy" module*/
pmod = PyImport_ExecCodeModule(modulename, tmp);
if (pmod == NULL)
error("Can't load module [pmod]");
------------------------------

Regards,
Vio

Search Discussions

  • Miki Tebeka at Jun 10, 2004 at 7:20 am
    Hello Vio,
    I have a basic dynamic lib "noddy.so" which I want to
    1- embed inside my executable
    Why? What is the reason you can have multiple files?
    2- import by embedded python interpreter using an API call.

    1- what would be the recommended technique to embed a binary file inside
    an executable?
    Have a look at what Python Installer does (or NSIS installer).
    IMO the OS will need a "real" file so what you'll have to do is extract
    it at runtime and then load it.
    2- Let's imagine that I managed to load "noddy.so" into my source code
    somehow, and now have a pointer to it.
    Again. I'd extract it to a temporary file and load it. This way you can
    use the regular `import'.

    HTH.
    --
    -------------------------------------------------------------------------
    Miki Tebeka <miki.tebeka at zoran.com>
    The only difference between children and adults is the price of the toys.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 9, '04 at 12:23p
activeJun 10, '04 at 7:20a
posts2
users2
websitepython.org

2 users in discussion

Miki Tebeka: 1 post Vio: 1 post

People

Translate

site design / logo © 2022 Grokbase