API mode lib object

28 views
Skip to first unread message

Alex Theiakos

unread,
Sep 25, 2015, 9:14:10 AM9/25/15
to python-cffi
Hi there,

I recently switched to the new 1.x version of cffi for a project of mine. Along with the change I also decided to switch to the new API methods instead of the ABI.
With the ABI it used to be possible to name the library object that the dlopen returns, for example

libtest = dlopen("test")

With the API methods you get a magic object 'lib' once you ran the ffi.compile() method and import the extension.
My question is, is there a way to control the name of this 'lib' object? Is there an argument on the 'set_source' or 'compile' method that I'm missing maybe?
If not whats the preferred method to load 2 different libraries simultaneously? Use the full python namespace?

Regards,
Alex

Armin Rigo

unread,
Sep 25, 2015, 10:52:40 AM9/25/15
to pytho...@googlegroups.com
Hi Alex,

On Fri, Sep 25, 2015 at 3:14 PM, Alex Theiakos <athi...@gmail.com> wrote:
> My question is, is there a way to control the name of this 'lib' object?

How about:

from _myproject_cffi import ffi as myffi, lib as mylib

Or:

import _myproject_cffi
# always use _myproject_cffi.lib


A bientôt,

Armin.

Alex Theiakos

unread,
Sep 25, 2015, 11:46:55 AM9/25/15
to python-cffi, ar...@tunes.org
Hi Armin,

Something like that was my alternative, use python's namespace methods.
Do you thing a new argument in the set_source method to control this would make sense or is it too much of a hassle?

Thanks for the support and your excellent work on the package!

Regards,
Alex

Armin Rigo

unread,
Oct 2, 2015, 8:21:17 AM10/2/15
to pytho...@googlegroups.com
Hi Alex,

On Fri, Sep 25, 2015 at 5:46 PM, Alex Theiakos <athi...@gmail.com> wrote:
> Something like that was my alternative, use python's namespace methods.
> Do you thing a new argument in the set_source method to control this would
> make sense or is it too much of a hassle?

It doesn't make much sense to me to add support for that. It would
just be taking something that already exists in Python, and is very
natural (although admittedly not necessary obvious to Python
beginners), and replacing it with special support that needs to be
documented and tested.


Armin
Reply all
Reply to author
Forward
0 new messages