On Fri, Jun 5, 2015 at 10:45 AM, Armin Rigo <
ar...@tunes.org> wrote:
> Hi Anatoly,
>
> On 4 June 2015 at 20:37, anatoly techtonik <
tech...@gmail.com> wrote:
>> Is it possible to go without ctypes import? =/
>> That's.. important.
>
> Copy-paste the logic from ctypes/util.py...
>
> Sorry, I don't have anything better to suggest.
Patch cffi.api.dlopen
diff -r f9bbb11363fc cffi/api.py
--- a/cffi/api.py Fri Nov 21 20:45:12 2014 +0100
+++ b/cffi/api.py Fri Jun 05 16:17:07 2015 +0300
@@ -114,6 +114,10 @@
library we only look for the actual (untyped) symbols.
"""
assert isinstance(name, basestring) or name is None
+ if sys.platform == "win32" and name is None:
+ # port Unix behavior - load C stdlib
+ import ctypes.util
+ name = ctypes.util.find_library("c")
with self._lock:
lib, function_cache = _make_ffi_library(self, name, flags)
self._function_caches.append(function_cache)
No?
> The point of CFFI's
> out-of-line mode is that it only needs to import one C extension
> module (in ABI mode) or two (in API mode) but not the whole Python
> logic from the cffi package.
What is the difference in the logic. Just the loader rewritten in C?
It also feel awkward to split the function definition from a library
name. A step back from future. It would be nice if definitions were
linked to the libraries they are supposed to come from. All this C
library lookup stuff for every platform is a huge mess. If CFFI could
set some standard for library names and placement, at least for
the stuff that can be shipped together with Python packages, and
provided a manual way to override that for those who need the
flexibility - that would provide a value for those of us who are lost
in building cross-platform extensions for Python.
That means that definitions will came as:
"libc": {"""
int printf( .... );
"""}
and then ffi will try to find and load that `libc` automatically. There
could be service like PyPI to resolve ambiguity with C package
names, turning names into identifiers, like "import libc". But that
may not be required, because it looks like these symbols from
external libraries are isolated in module namespace, and the
only thing that is relevant is where from CFFI finds and loads the
library, and if symbols match.
> If you really need to get access
> Microsoft's version of the standard C library in ABI mode, but you
> don't want to import the whole of ctypes either, then copy the
> functions _get_build_version() and find_msvcrt().
Again, it looks like the best place for that code is the generated
.py module, but it doesn't load the lib and don't know the lib name
at all. It looks awkward that I can not query this generated module
about the properties of the library that I need to load for it. Like
checking name, version, comments etc.
> As usual, I'd also recommend looking at the API mode, which doesn't
> have all these problems but at the cost of building a C extension for
> which you need a compiler --- but just like a regular project with a C
> extension you can redistribute binary wheels that contain the
> precompiled stuff, and so on.
I am evaluating the possibility to replace ctypes with CFFI, so that
people could checkout and run things right away from repository
without additional steps for compilation and installation.
--
anatoly t.