summaryrefslogtreecommitdiff
path: root/testing/embedding
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2016-01-08 11:37:08 +0100
committerArmin Rigo <arigo@tunes.org>2016-01-08 11:37:08 +0100
commit8f7e76571f24fe5837120e7e04ea97dfd2b87fea (patch)
treee9f43dfde23da0481aee4ee3fbfb92ac7284fe9e /testing/embedding
parent67a018017d788b03619b38631439e31514837d6c (diff)
downloadcffi-8f7e76571f24fe5837120e7e04ea97dfd2b87fea.tar.gz
py3 compat
Diffstat (limited to 'testing/embedding')
-rw-r--r--testing/embedding/add1.py1
-rw-r--r--testing/embedding/add2.py1
-rw-r--r--testing/embedding/add3.py1
-rw-r--r--testing/embedding/add_recursive.py9
-rw-r--r--testing/embedding/perf.py2
-rw-r--r--testing/embedding/test_basic.py3
-rw-r--r--testing/embedding/tlocal.py11
7 files changed, 20 insertions, 8 deletions
diff --git a/testing/embedding/add1.py b/testing/embedding/add1.py
index 37a1b3e..28526e5 100644
--- a/testing/embedding/add1.py
+++ b/testing/embedding/add1.py
@@ -22,6 +22,7 @@ ffi.embedding_init_code(r"""
@ffi.def_extern()
def add1(x, y):
sys.stdout.write("adding %d and %d\n" % (x, y))
+ sys.stdout.flush()
return x + y
""")
diff --git a/testing/embedding/add2.py b/testing/embedding/add2.py
index de359ec..b6febef 100644
--- a/testing/embedding/add2.py
+++ b/testing/embedding/add2.py
@@ -18,6 +18,7 @@ ffi.embedding_init_code(r"""
@ffi.def_extern()
def add2(x, y, z):
sys.stdout.write("adding %d and %d and %d\n" % (x, y, z))
+ sys.stdout.flush()
return x + y + z
""")
diff --git a/testing/embedding/add3.py b/testing/embedding/add3.py
index 045fd58..4b950f5 100644
--- a/testing/embedding/add3.py
+++ b/testing/embedding/add3.py
@@ -13,6 +13,7 @@ ffi.embedding_init_code(r"""
@ffi.def_extern()
def add3(x, y, z, t):
sys.stdout.write("adding %d, %d, %d, %d\n" % (x, y, z, t))
+ sys.stdout.flush()
return x + y + z + t
""")
diff --git a/testing/embedding/add_recursive.py b/testing/embedding/add_recursive.py
index 1dd0bfd..cd23a4e 100644
--- a/testing/embedding/add_recursive.py
+++ b/testing/embedding/add_recursive.py
@@ -9,15 +9,18 @@ ffi.cdef("""
ffi.embedding_init_code(r"""
from _add_recursive_cffi import ffi, lib
- print "preparing REC"
+ import sys
+ print("preparing REC")
+ sys.stdout.flush()
@ffi.def_extern()
def add_rec(x, y):
- print "adding %d and %d" % (x, y)
+ print("adding %d and %d" % (x, y))
+ sys.stdout.flush()
return x + y
x = lib.my_callback(400)
- print '<<< %d >>>' % (x,)
+ print('<<< %d >>>' % (x,))
""")
ffi.set_source("_add_recursive_cffi", """
diff --git a/testing/embedding/perf.py b/testing/embedding/perf.py
index 8da7ecf..e72fc02 100644
--- a/testing/embedding/perf.py
+++ b/testing/embedding/perf.py
@@ -18,4 +18,4 @@ ffi.set_source("_perf_cffi", """
""")
fn = ffi.compile(verbose=True)
-print 'FILENAME:', fn
+print('FILENAME: %s' % (fn,))
diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
index b77484e..0da1258 100644
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -97,7 +97,8 @@ class EmbeddingTests:
env['LD_LIBRARY_PATH'] = libpath
print('running %r in %r' % (name, path))
popen = subprocess.Popen([name], cwd=path, env=env,
- stdout=subprocess.PIPE)
+ stdout=subprocess.PIPE,
+ universal_newlines=True)
result = popen.stdout.read()
err = popen.wait()
if err:
diff --git a/testing/embedding/tlocal.py b/testing/embedding/tlocal.py
index 781fac3..3a5f70c 100644
--- a/testing/embedding/tlocal.py
+++ b/testing/embedding/tlocal.py
@@ -8,16 +8,21 @@ ffi.cdef("""
ffi.embedding_init_code(r"""
from _tlocal_cffi import ffi
- import thread, itertools
+ import itertools
+ try:
+ import thread
+ g_seen = itertools.count().next
+ except ImportError:
+ import _thread as thread # py3
+ g_seen = itertools.count().__next__
tloc = thread._local()
- g_seen = itertools.count()
@ffi.def_extern()
def add1(x, y):
try:
num = tloc.num
except AttributeError:
- num = tloc.num = g_seen.next() * 1000
+ num = tloc.num = g_seen() * 1000
return x + y + num
""")