Using ctypes inside a C application embedding the CPython runtime

"[email protected]" <[email protected]> Tue, 7 Jun 2016 16:06:28 -0600
Newsgroups gmane.comp.python.ctypes
Message-ID <CAJhOshs2=UCLyG3O8OAisz9xUm_8Gf8HcoF-nBiCRAPzgN6kNg@mail.gmail.com>
Hi,

We have a python server application that will load a shared library (using
ctypes) and make its functions available to a client application on another
host.

Now we're been asked to embedded that application into a larger C
application that also loads the same library (the goal is to let the C
application turn on and off the server as needed). We used the CPython
runtime to embed the python application inside the C application
successfully, using the documentation available here[0].

The problem is that right now we make sure that our python application is
using the same library (in memory) as the C application by passing None as
the name parameter to the CDLL constructor, which means it ultimately calls
dlopen() with Null as it's filename parameter, having the following effect:

If *filename* is NULL, then the returned handle is for the main
       program.  When given to *dlsym*(), this handle causes a search for a
       symbol in the main program, followed by all shared objects loaded at
       program startup, and then all shared objects loaded by *dlopen*() with
       the flag *RTLD_GLOBAL*.

As documented on dlopen's manpage[1], and this is working right now. What
we're worried about is that passing None to the CDLL constructor is not
documented anywhere (at least that I could find), so we're not sure if we
can rely on this functionality (if so, the documentation should probably be
updated and I can help with that if needed) or if there's an alternate
recommended and documented way of achieving the same result.

Thank you very much for your time.


Regards,

[0] https://docs.python.org/3.5/extending/embedding.html
[1] http://man7.org/linux/man-pages/man3/dlopen.3.html

-- 
Jeffrey Esquivel S.

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users