[pypy-commit] cffi static-callback-embedding: py3 compat
arigo
pypy.commits at gmail.com
Fri Jan 8 05:37:20 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: static-callback-embedding
Changeset: r2554:31afbf41f7b5
Date: 2016-01-08 11:37 +0100
http://bitbucket.org/cffi/cffi/changeset/31afbf41f7b5/
Log: py3 compat
diff --git a/testing/embedding/add1.py b/testing/embedding/add1.py
--- a/testing/embedding/add1.py
+++ b/testing/embedding/add1.py
@@ -22,6 +22,7 @@
@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
--- a/testing/embedding/add2.py
+++ b/testing/embedding/add2.py
@@ -18,6 +18,7 @@
@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
--- a/testing/embedding/add3.py
+++ b/testing/embedding/add3.py
@@ -13,6 +13,7 @@
@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
--- a/testing/embedding/add_recursive.py
+++ b/testing/embedding/add_recursive.py
@@ -9,15 +9,18 @@
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
--- a/testing/embedding/perf.py
+++ b/testing/embedding/perf.py
@@ -18,4 +18,4 @@
""")
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
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -97,7 +97,8 @@
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
--- a/testing/embedding/tlocal.py
+++ b/testing/embedding/tlocal.py
@@ -8,16 +8,21 @@
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
""")
More information about the pypy-commit
mailing list