CFFI and PyPy

CFFI

PyPy

CFFI

CFFI

CFFI demo

$ man getpwuid

SYNOPSIS
       #include <sys/types.h>
       #include <pwd.h>

       struct passwd *getpwnam(const char *name);

CFFI demo

.
.
.
The passwd structure is defined in <pwd.h> as follows:

    struct passwd {
        char   *pw_name;       /* username */
        char   *pw_passwd;     /* user password */
        uid_t   pw_uid;        /* user ID */
.
.
.

CFFI demo

from cffi import FFI
ffi = cffi.FFI()

ffi.cdef("""
    typedef int... uid_t;
    struct passwd {
        uid_t pw_uid;
        ...;
    };
    struct passwd *getpwnam(const char *name);
""")

CFFI demo

ffi.set_source("_pwuid_cffi", """
    #include <sys/types.h>
    #include <pwd.h>
""")

ffi.compile()

------- ^^ put that in pwuid_build.py

CFFI demo

python pwuid_build.py

creates _pwuid_cffi.so

CFFI demo

from _pwuid_cffi import lib

print lib.getpwnam("arigo").pw_uid

CFFI demo

from _pwuid_cffi import ffi, lib

CFFI

PyPy

PyPy

PyPy

$ pypy

Python 2.7.10 (5f8302b8bf9f, Nov 18 2015, 10:46:46)
[PyPy 4.0.1 with GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> 2+3
5
>>>>

PyPy

PyPy

PyPy: Garbage Collection

PyPy: C extensions

PyPy: C extensions

PyPy: C extensions

PyPy: C extensions

PyPy: C extensions

PyPy: ad

CPython C API: the problem

CPython C API

CPython C API

CPython C API

CFFI

CFFI and PyPy

CFFI: performance

CFFI: summary

CFFI

CFFI

CFFI: latest news

CFFI

http://cffi.readthedocs.org/