[pypy-commit] cffi default: We need to take all **kwds and stick them into the hash too.
arigo
noreply at buildbot.pypy.org
Fri Nov 30 19:43:58 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1081:bec0477dcb83
Date: 2012-11-30 10:43 -0800
http://bitbucket.org/cffi/cffi/changeset/bec0477dcb83/
Log: We need to take all **kwds and stick them into the hash too.
diff --git a/cffi/ffiplatform.py b/cffi/ffiplatform.py
--- a/cffi/ffiplatform.py
+++ b/cffi/ffiplatform.py
@@ -76,3 +76,35 @@
return os.path.join(*names)
except OSError:
pass
+
+# ____________________________________________________________
+
+try:
+ int_or_long = (int, long)
+except NameError:
+ int_or_long = int # Python 3
+
+def _flatten(x, f):
+ if isinstance(x, str):
+ f.write('%ds%s' % (len(x), x))
+ elif isinstance(x, dict):
+ keys = sorted(x.keys())
+ f.write('%dd' % len(keys))
+ for key in keys:
+ _flatten(key, f)
+ _flatten(x[key], f)
+ elif isinstance(x, (list, tuple)):
+ f.write('%dl' % len(x))
+ for value in x:
+ _flatten(value, f)
+ elif isinstance(x, int_or_long):
+ f.write('%di' % (x,))
+ else:
+ raise TypeError(
+ "the keywords to verify() contains unsupported object %r" % (x,))
+
+def flatten(x):
+ import cStringIO
+ f = cStringIO.StringIO()
+ _flatten(x, f)
+ return f.getvalue()
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -9,12 +9,14 @@
tag='', force_generic_engine=False, **kwds):
self.ffi = ffi
self.preamble = preamble
+ flattened_kwds = ffiplatform.flatten(kwds)
vengine_class = _locate_engine_class(ffi, force_generic_engine)
self._vengine = vengine_class(self)
self._vengine.patch_extension_kwds(kwds)
self.kwds = kwds
#
- key = '\x00'.join(['1', sys.version[:3], __version__, preamble] +
+ key = '\x00'.join([sys.version[:3], __version__, preamble,
+ flattened_kwds] +
ffi._cdefsources)
if sys.version_info >= (3,):
key = key.encode('utf-8')
diff --git a/testing/test_platform.py b/testing/test_platform.py
--- a/testing/test_platform.py
+++ b/testing/test_platform.py
@@ -15,3 +15,11 @@
assert maybe_relative_path(p) == 'baz.py'
foobaz = os.path.join('foo', 'baz.py')
assert maybe_relative_path(os.path.abspath(foobaz)) == foobaz
+
+def test_flatten():
+ assert flatten("foo") == "3sfoo"
+ assert flatten(-10000000000000000000000000000) == \
+ "-10000000000000000000000000000i"
+ assert flatten([4, 5]) == "2l4i5i"
+ assert flatten({4: 5}) == "1d4i5i"
+ assert flatten({"foo": ("bar", "baaz")}) == "1d3sfoo2l3sbar4sbaaz"
More information about the pypy-commit
mailing list