Finding the library filename or address via old CFFI?

28 views
Skip to first unread message

Matthew Brett

unread,
May 28, 2016, 10:29:25 PM5/28/16
to python-cffi
Hi,

Is there any way to find the filename of the compiled library that a given FFI instance is using?

I'm asking, because I'm trying to implement run-time symbol loading against the Python tkinter implementation - see https://github.com/python-pillow/Pillow/pull/1932

I can do this moderately easily on CPython, because I can find the compiled `.so` module that links against Tcl and Tk libraries, do a C `dlopen` on that `.so` module, and there are all the Tcl and Tk symbols I need.

It's not too hard to do the same thing in PyPy 5.1.1, because the `.so` name is available under "_tkinter.tklib_cffi.__file__" (5.1.1 is running cffi 1.6.0).

But - I can't work out a way to do this for PyPy3 2.4.0 (the current release).  This is running cffi 0.8.6.

I realize that version is very old - but I'm asking because, at the moment, this is a blocker for what is otherwise a very useful way to make sure that binaries find the correct versions of the libraries that Python depends on.

Thanks much in advance,

Matthew


Armin Rigo

unread,
May 29, 2016, 9:11:57 AM5/29/16
to pytho...@googlegroups.com
Hi Matthew,

On 29 May 2016 at 04:29, Matthew Brett <matthe...@gmail.com> wrote:
> But - I can't work out a way to do this for PyPy3 2.4.0 (the current
> release). This is running cffi 0.8.6.

CFFI being 0.8.6 means it is using the old "ffi.verify()" way. This
should return an old-style "lib" object which has a few hidden
attributes (see "class FFILibrary" in cffi/vengine_gen.py for pypy;
they are different on cpython, which is in cffi/vengine_cpy.py).
Notably, try to look at "lib._cffi_generic_module".

Note that the PyPy project should make very soon an alpha release
supporting Python 3.3. This should finally end the period where PyPy
users of Python 3 are stuck with a very old PyPy.


A bientôt,

Armin.

Matthew Brett

unread,
May 30, 2016, 1:33:50 PM5/30/16
to python-cffi, ar...@tunes.org
Thanks for the help - that is useful.

Can I ask related question?  Can we depend on the compiled module name being in "tklib_cffi.__file__" (I mean "<libname>_cffi.__file__") in the long-ish term?  Or is this API likely to change in the near future.

A+,

Matthew

Armin Rigo

unread,
May 31, 2016, 4:24:20 AM5/31/16
to pytho...@googlegroups.com
Hi Matthew,

On 30 May 2016 at 19:33, Matthew Brett <matthe...@gmail.com> wrote:
> Can I ask related question? Can we depend on the compiled module name being
> in "tklib_cffi.__file__" (I mean "<libname>_cffi.__file__") in the long-ish
> term? Or is this API likely to change in the near future.

"tklib_cffi" is a regular C extension module, so it has a __file__
attribute, if that's the question. We have no reason to hack in order
to hide this standard attribute.

Note: PyPy3.3 v5.2 has been released!


Armin
Reply all
Reply to author
Forward
0 new messages