Author: Armin Rigo <ar...@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") _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit