[pypy-commit] pypy default: Test and fix

arigo noreply at buildbot.pypy.org
Mon Aug 13 00:15:13 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r56717:9366237d4f47
Date: 2012-08-12 23:57 +0200
http://bitbucket.org/pypy/pypy/changeset/9366237d4f47/

Log:	Test and fix

diff --git a/pypy/module/_cffi_backend/ctypeenum.py b/pypy/module/_cffi_backend/ctypeenum.py
--- a/pypy/module/_cffi_backend/ctypeenum.py
+++ b/pypy/module/_cffi_backend/ctypeenum.py
@@ -24,7 +24,7 @@
                                         name, len(name), align)
         self.enumerators2values = {}   # str -> int
         self.enumvalues2erators = {}   # int -> str
-        for i in range(len(enumerators)):
+        for i in range(len(enumerators)-1, -1, -1):
             self.enumerators2values[enumerators[i]] = enumvalues[i]
             self.enumvalues2erators[enumvalues[i]] = enumerators[i]
 
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -1065,6 +1065,12 @@
     assert repr(cast(BEnum, '#-20')) == "<cdata 'enum foo' 'ab'>"
     assert repr(cast(BEnum, '#-21')) == "<cdata 'enum foo' '#-21'>"
 
+def test_enum_with_non_injective_mapping():
+    BEnum = new_enum_type("foo", ('ab', 'cd'), (7, 7))
+    e = cast(BEnum, 7)
+    assert repr(e) == "<cdata 'enum foo' 'ab'>"
+    assert string(e) == 'ab'
+
 def test_enum_in_struct():
     BEnum = new_enum_type("foo", ('def', 'c', 'ab'), (0, 1, -20))
     BStruct = new_struct_type("bar")


More information about the pypy-commit mailing list