Commits

Armin Rigo  committed 6739201

Ported cffi/012670e62732

  • Participants
  • Parent commits ed989c5

Comments (0)

Files changed (3)

File pypy/module/_cffi_backend/ctypeenum.py

                 space.setitem(w_dct, space.wrap(enumvalue),
                                      space.wrap(enumerator))
             return w_dct
+        if attrchar == 'R':     # relements
+            space = self.space
+            w_dct = space.newdict()
+            for enumerator, enumvalue in self.enumerators2values.iteritems():
+                space.setitem(w_dct, space.wrap(enumerator),
+                                     space.wrap(enumvalue))
+            return w_dct
         return W_CTypePrimitiveSigned._fget(self, attrchar)
 
     def string(self, cdataobj, maxlen):

File pypy/module/_cffi_backend/ctypeobj.py

         if attrchar == 'c':     # cname
             return space.wrap(self.name)
         raise operationerrfmt(space.w_AttributeError,
-                              "cdata '%s' has no such attribute",
+                              "ctype '%s' has no such attribute",
                               self.name)
 
     def fget_kind(self, space):     return self._fget('k')
     def fget_ellipsis(self, space): return self._fget('E')
     def fget_abi(self, space):      return self._fget('A')
     def fget_elements(self, space): return self._fget('e')
+    def fget_relements(self, space):return self._fget('R')
 
 
 W_CType.typedef = TypeDef(
     ellipsis = GetSetProperty(W_CType.fget_ellipsis, doc="function has '...'"),
     abi = GetSetProperty(W_CType.fget_abi, doc="function ABI"),
     elements = GetSetProperty(W_CType.fget_elements, doc="enum elements"),
+    relements = GetSetProperty(W_CType.fget_relements,
+                               doc="enum elements, reversed"),
     __dir__ = interp2app(W_CType.dir),
     )
 W_CType.typedef.acceptable_as_base_class = False

File pypy/module/_cffi_backend/test/_backend_test_c.py

     # 'elements' is not the real dict, but merely a copy
     BEnum.elements[2] = '??'
     assert BEnum.elements == {-20: 'ab', 0: 'def', 1: 'c'}
+    #
+    BEnum = new_enum_type("bar", ('ab', 'cd'), (5, 5))
+    assert BEnum.elements == {5: 'ab'}
+    assert BEnum.relements == {'ab': 5, 'cd': 5}
 
 def test_cast_to_enum():
     BEnum = new_enum_type("foo", ('def', 'c', 'ab'), (0, 1, -20))