• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import cffi
2
3ffi = cffi.FFI()
4
5ffi.embedding_api("""
6    int add1(int, int);
7""")
8
9ffi.embedding_init_code(r"""
10    from _tlocal_cffi import ffi
11    import itertools
12    try:
13        import thread
14        g_seen = itertools.count().next
15    except ImportError:
16        import _thread as thread      # py3
17        g_seen = itertools.count().__next__
18    tloc = thread._local()
19
20    @ffi.def_extern()
21    def add1(x, y):
22        try:
23            num = tloc.num
24        except AttributeError:
25            num = tloc.num = g_seen() * 1000
26        return x + y + num
27""")
28
29ffi.set_source("_tlocal_cffi", """
30""")
31
32fn = ffi.compile(verbose=True)
33print('FILENAME: %s' % (fn,))
34