A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-February/124430.html below:

[Python-Dev] cffi in stdlib

[Python-Dev] cffi in stdlibPaul Moore p.f.moore at gmail.com
Thu Feb 28 09:27:25 CET 2013
On 27 February 2013 23:18, Armin Rigo <arigo at tunes.org> wrote:
> from cffi import FFI
> ffi = FFI()
> ffi.cdef("""
>     int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
> """)
> lib = ffi.dlopen("USER32.DLL")
> lib.MessageBox(ffi.NULL, "Hello, world!", "Title", 0)

Yeah, that's loads better than 0.5. Presumably ffi.NULL isn't needed
and I can use 0? (After all, 0 and NULL are equivalent in C, so that's
not a correctness issue). The auto-conversion of strings is a huge
improvement.

> That's a slightly unfair example, because in this case it happens to
> work with ctypes without specifying the argtypes and the restype.  I
> would argue that this feature of ctypes is not a good thing: it's
> mostly the same as saying "you only need to declare argtypes and
> restype if you get nonsense results or segfaults".

That's a bit unfair. I'd say "you only need to declare argtypes if
you're dealing with things more complex than integers, strings and
null pointers". Which means you're fine for a huge proportion of the
Windows API.

On the other hand, going to the API level and being able to use all
the Windows constants without having to look them up (their values
aren't documented, so googling doesn't help :-() is a huge plus.

Paul.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4