Commits

Armin Rigo  committed 92bdeb9

Test and fix.

  • Participants
  • Parent commits 909b497

Comments (0)

Files changed (2)

File c/_cffi_backend.c

 {
     if (ct->ct_flags & CT_IS_ENUM) {
         PyObject *res = PyTuple_GetItem(ct->ct_stuff, 1);
-        Py_XINCREF(res);
+        if (res) res = PyDict_Copy(res);
         return res;
     }
     return nosuchattr("elements");
     BEnum = new_enum_type("foo", ('def', 'c', 'ab'), (0, 1, -20))
     assert BEnum.kind == "enum"
     assert BEnum.elements == {-20: 'ab', 0: 'def', 1: 'c'}
+    # 'elements' is not the real dict, but merely a copy
+    BEnum.elements[2] = '??'
+    assert BEnum.elements == {-20: 'ab', 0: 'def', 1: 'c'}
 
 def test_cast_to_enum():
     BEnum = new_enum_type("foo", ('def', 'c', 'ab'), (0, 1, -20))